Compare commits
3 Commits
0ce3932e9c
...
68b1142cd7
Author | SHA1 | Date |
---|---|---|
MasterofJOKers | 68b1142cd7 | |
MasterofJOKers | 6596be6c1e | |
MasterofJOKers | 6c1667046b |
|
@ -96,64 +96,69 @@ def version(client):
|
||||||
@click.option('--label', 'labels', multiple=True, help='Filter for issues with all the given labels')
|
@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('--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('--flagged/--not-flagged', is_flag=True, default=None, help='Filter issues being flagged or not flagged')
|
||||||
|
@click.option('--watching/--not-watching', is_flag=True, default=None, help='Filter issues I watch or do not watch')
|
||||||
@click.option('--order', help='Sort by this field')
|
@click.option('--order', help='Sort by this field')
|
||||||
@click.option('--asc/--desc', 'asc', help='Sort ascending/descending. Default: descending')
|
@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. '
|
@click.option('--jql', help='Provide your own JQL query string to include in the search via AND.')
|
||||||
'Setting this ignores all other query options except --project.')
|
|
||||||
@pass_client
|
@pass_client
|
||||||
@pass_config
|
@pass_config
|
||||||
def issues(config, client, project, components, status, labels, texts, flagged, order, asc, jql):
|
def issues(config, client, project, components, status, labels, texts, flagged, watching, order, asc, jql):
|
||||||
if not project and config.has_section('filters') and config.get('filters', 'default_project'):
|
if project is None and config.has_section('filters') and config.get('filters', 'default_project'):
|
||||||
project = config['filters']['default_project']
|
project = config['filters']['default_project']
|
||||||
project_jql = f"project = {project}"
|
|
||||||
|
|
||||||
# TODO add filtering by created since
|
# TODO add filtering by created since
|
||||||
# TODO add filtering by updated
|
# TODO add filtering by updated
|
||||||
# TODO support pagination I guess? i.e. a limit
|
# TODO support pagination I guess? i.e. a limit
|
||||||
if not jql:
|
filters = []
|
||||||
filters = []
|
|
||||||
|
|
||||||
if texts:
|
if jql:
|
||||||
texts_jql = ' AND '.join([f'text ~ "{text}"' for text in texts])
|
filters.append(jql)
|
||||||
filters.append(f"( {texts_jql} )")
|
|
||||||
|
|
||||||
if components:
|
if texts:
|
||||||
component_list = ', '.join([f'"{c}"' for c in components])
|
texts_jql = ' AND '.join([f'text ~ "{text}"' for text in texts])
|
||||||
components_jql = f"component in ({component_list})"
|
filters.append(f"( {texts_jql} )")
|
||||||
filters.append(components_jql)
|
|
||||||
|
|
||||||
if status:
|
if components:
|
||||||
status_list = ', '.join([f'"{s}"' for s in status if not s.startswith('!')])
|
component_list = ', '.join([f'"{c}"' for c in components])
|
||||||
if status_list:
|
components_jql = f"component in ({component_list})"
|
||||||
status_jql = f"status IN ({status_list})"
|
filters.append(components_jql)
|
||||||
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 labels:
|
if status:
|
||||||
labels_jql = ' AND '.join([f'labels = "{label}"' for label in labels])
|
status_list = ', '.join([f'"{s}"' for s in status if not s.startswith('!')])
|
||||||
filters.append(f"( {labels_jql} )")
|
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 labels:
|
||||||
if flagged:
|
labels_jql = ' AND '.join([f'labels = "{label}"' for label in labels])
|
||||||
flagged_jql = 'flagged IS NOT EMPTY'
|
filters.append(f"( {labels_jql} )")
|
||||||
else:
|
|
||||||
flagged_jql = 'flagged IS EMPTY'
|
|
||||||
filters.append(flagged_jql)
|
|
||||||
|
|
||||||
if project:
|
if flagged is not None:
|
||||||
filters.append(project_jql)
|
if flagged:
|
||||||
|
flagged_jql = 'flagged IS NOT EMPTY'
|
||||||
|
else:
|
||||||
|
flagged_jql = 'flagged IS EMPTY'
|
||||||
|
filters.append(flagged_jql)
|
||||||
|
|
||||||
jql = ' AND '.join(filters)
|
if watching is not None:
|
||||||
|
if watching:
|
||||||
|
watching_jql = 'watcher = currentUser()'
|
||||||
|
else:
|
||||||
|
watching_jql = 'watcher != currentUser()'
|
||||||
|
filters.append(watching_jql)
|
||||||
|
|
||||||
if order:
|
if project:
|
||||||
jql += f" ORDER BY {order} {'ASC' if asc else 'DESC'}"
|
project_jql = f"project = {project}"
|
||||||
|
filters.append(project_jql)
|
||||||
|
|
||||||
else:
|
jql = ' AND '.join(filters)
|
||||||
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}")
|
print(f"Searching with query: {jql}")
|
||||||
issues = client.search_issues(jql)
|
issues = client.search_issues(jql)
|
||||||
|
|
Loading…
Reference in New Issue