MasterofJOKers 2 years ago
parent 14a9af7e51
commit 6594f515f3

@ -90,20 +90,23 @@ def version(client):
@main.command()
@click.option('--project', help='Project to filter for. Default: take from config [filters]/default_project')
@click.option('--component', 'components', help='Filter for issues with *any* of the given components')
@click.option('--status', multiple=True, help='Filter for issues with *any* of the given statuses')
@click.option('--label', 'labels', multiple=True, help='Filter for issues with all the given labels')
@click.option('--text', 'texts', multiple=True, help='Filter for issues containing all the given strings')
@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.')
@pass_client
@pass_config
def issues(config, client, project, status, labels, texts, order, asc, jql):
filters_config = config.get('filters')
def issues(config, client, project, components, status, labels, texts, flagged, order, asc, jql):
filters_config = config['filters']
if not project and filters_config and 'default_project' in filters_config:
project = filters_config['default_project']
project_jql = f"project = {project}"
# TODO add filtering by created since
# TODO add filtering by updated
@ -114,6 +117,12 @@ def issues(config, client, project, status, labels, texts, order, asc, jql):
if texts:
texts_jql = ' AND '.join([f'text ~ "{text}"' for text in texts])
filters.append(f"( {texts_jql} )")
if components:
component_list = ', '.join([f'"{c}"' for c in components])
components_jql = f"component in ({component_list})"
filters.append(components_jql)
if status:
status_list = ', '.join([f'"{s}"' for s in status])
status_jql = f"status IN ({status_list})"
@ -123,13 +132,24 @@ def issues(config, client, project, status, labels, texts, order, asc, jql):
labels_jql = ' AND '.join([f'labels = "{label}"' for label in labels])
filters.append(f"( {labels_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 project:
filters.append(project_jql)
jql = ' AND '.join(filters)
if order:
jql += f" ORDER BY {order} {'ASC' if asc else 'DESC'}"
if project:
jql = f"project = {project} AND {jql}"
else:
if project:
jql = f"project = {project} AND {jql}"
print(f"Searching with query: {jql}")
issues = client.search_issues(jql)

Loading…
Cancel
Save