diff --git a/jiracli/cli.py b/jiracli/cli.py index b346b5e..17c9ed3 100644 --- a/jiracli/cli.py +++ b/jiracli/cli.py @@ -98,8 +98,7 @@ def version(client): @click.option('--flagged/--not-flagged', is_flag=True, default=None, help='Filter issues being flagged or not flagged') @click.option('--order', help='Sort by this field') @click.option('--asc/--desc', 'asc', help='Sort ascending/descending. Default: descending') -@click.option('--jql', default='', help='Provide your own JQL query to search for issues. ' - 'Setting this ignores all other query options except --project.') +@click.option('--jql', help='Provide your own JQL query string to include in the search via AND.') @pass_client @pass_config def issues(config, client, project, components, status, labels, texts, flagged, order, asc, jql): @@ -110,50 +109,48 @@ def issues(config, client, project, components, status, labels, texts, flagged, # TODO add filtering by created since # TODO add filtering by updated # TODO support pagination I guess? i.e. a limit - if not jql: - filters = [] + filters = [] - if texts: - texts_jql = ' AND '.join([f'text ~ "{text}"' for text in texts]) - filters.append(f"( {texts_jql} )") + if jql: + filters.append(jql) - if components: - component_list = ', '.join([f'"{c}"' for c in components]) - components_jql = f"component in ({component_list})" - filters.append(components_jql) + if texts: + texts_jql = ' AND '.join([f'text ~ "{text}"' for text in texts]) + filters.append(f"( {texts_jql} )") - if status: - status_list = ', '.join([f'"{s}"' for s in status if not s.startswith('!')]) - if status_list: - status_jql = f"status IN ({status_list})" - filters.append(status_jql) - status_list = ', '.join([f'"{s[1:]}"' for s in status if s.startswith('!')]) - if status_list: - status_jql = f"status NOT IN ({status_list})" - filters.append(status_jql) + if components: + component_list = ', '.join([f'"{c}"' for c in components]) + components_jql = f"component in ({component_list})" + filters.append(components_jql) - if labels: - labels_jql = ' AND '.join([f'labels = "{label}"' for label in labels]) - filters.append(f"( {labels_jql} )") + if status: + status_list = ', '.join([f'"{s}"' for s in status if not s.startswith('!')]) + if status_list: + status_jql = f"status IN ({status_list})" + filters.append(status_jql) + status_list = ', '.join([f'"{s[1:]}"' for s in status if s.startswith('!')]) + if status_list: + status_jql = f"status NOT IN ({status_list})" + filters.append(status_jql) - if flagged is not None: - if flagged: - flagged_jql = 'flagged IS NOT EMPTY' - else: - flagged_jql = 'flagged IS EMPTY' - filters.append(flagged_jql) + if labels: + labels_jql = ' AND '.join([f'labels = "{label}"' for label in labels]) + filters.append(f"( {labels_jql} )") - if project: - filters.append(project_jql) + if flagged is not None: + if flagged: + flagged_jql = 'flagged IS NOT EMPTY' + else: + flagged_jql = 'flagged IS EMPTY' + filters.append(flagged_jql) - jql = ' AND '.join(filters) + if project: + filters.append(project_jql) - if order: - jql += f" ORDER BY {order} {'ASC' if asc else 'DESC'}" + jql = ' AND '.join(filters) - else: - if project: - jql = f"project = {project} AND {jql}" + if order: + jql += f" ORDER BY {order} {'ASC' if asc else 'DESC'}" print(f"Searching with query: {jql}") issues = client.search_issues(jql)