Compare commits

...

3 Commits

Author SHA1 Message Date
MasterofJOKers 68b1142cd7 Add a filter for watched issues 2022-10-25 22:37:32 +02:00
MasterofJOKers 6596be6c1e Let the user query issues without default project
When the user sets --project to an empty string, we will not add the
default project from the config anymore.
2022-10-25 22:30:39 +02:00
MasterofJOKers 6c1667046b Change meaning of --jql in issues command
--jql can now provide filtering in addition to the other command line
arguments instead of replacing the whole query. This still allows the
same behavior as before by specifying none of the other options.
2022-10-25 22:26:57 +02:00
1 changed files with 45 additions and 40 deletions

View File

@ -96,23 +96,24 @@ def version(client):
@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('--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('--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):
if not project and config.has_section('filters') and config.get('filters', 'default_project'):
def issues(config, client, project, components, status, labels, texts, flagged, watching, order, asc, jql):
if project is None and config.has_section('filters') and config.get('filters', 'default_project'):
project = config['filters']['default_project']
project_jql = f"project = {project}"
# TODO add filtering by created since
# TODO add filtering by updated
# TODO support pagination I guess? i.e. a limit
if not jql:
filters = []
if jql:
filters.append(jql)
if texts:
texts_jql = ' AND '.join([f'text ~ "{text}"' for text in texts])
filters.append(f"( {texts_jql} )")
@ -143,7 +144,15 @@ def issues(config, client, project, components, status, labels, texts, flagged,
flagged_jql = 'flagged IS EMPTY'
filters.append(flagged_jql)
if watching is not None:
if watching:
watching_jql = 'watcher = currentUser()'
else:
watching_jql = 'watcher != currentUser()'
filters.append(watching_jql)
if project:
project_jql = f"project = {project}"
filters.append(project_jql)
jql = ' AND '.join(filters)
@ -151,10 +160,6 @@ def issues(config, client, project, components, status, labels, texts, flagged,
if order:
jql += f" ORDER BY {order} {'ASC' if asc else 'DESC'}"
else:
if project:
jql = f"project = {project} AND {jql}"
print(f"Searching with query: {jql}")
issues = client.search_issues(jql)
for issue in issues: