From 5f63efebe1ad47f8142d7a780b3948b32ed60513 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Tue, 26 Oct 2021 11:42:44 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20let=20bot=20ignore=20issues=20with?= =?UTF-8?q?=20a=20no=5Fbot=5Ftag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - the tag can be specified in the config.yaml - the tag can be placed in the issue description or any of its journals (comments) --- example_config.yaml | 2 +- main.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/example_config.yaml b/example_config.yaml index 1edbed1..e28135a 100644 --- a/example_config.yaml +++ b/example_config.yaml @@ -5,7 +5,7 @@ redmine: version: ${REDMINE_VERSION} api_key: ${REDMINE_API_KEY} issue_closed_id: 5 # Id of the "closed" status - + no_bot_tag: "#nobot" # a tag that signals bot not to handle an issue actions: diff --git a/main.py b/main.py index a33a23b..12884bb 100644 --- a/main.py +++ b/main.py @@ -9,7 +9,6 @@ from jinja2 import Template def treat_issues(): - dir_path = os.path.dirname(os.path.realpath(__file__)) + '/' # Set up logging @@ -25,6 +24,7 @@ def treat_issues(): url = config['redmine']['url'] version = config['redmine']['version'] api_key = config['redmine']['api_key'] + no_bot_tag = config['redmine']['no_bot_tag'] actions = config['actions'] logging.getLogger().setLevel(config['logging']['level'].upper()) except Exception as e: @@ -49,6 +49,16 @@ def treat_issues(): for issue in redmine.issue \ .filter(updated_on=f"><{action['start_date']}|{end_date.isoformat()}") \ .filter(project__name__in=action['projects'], status__name__in=action['status'], closed_on=None): + + # Skip issue if a no_bot_tag is found in the issue description or any of its journals + def find_no_bot_tag_in_journals(journals): + for journal in journals: + if no_bot_tag in journal.notes: + return True + return False + if no_bot_tag in issue.description or find_no_bot_tag_in_journals(issue.journals): + continue + with open(f"{dir_path}templates/{action['template']}", newline='\r\n') as f: content = f.read() template = Template(content)