✨ find 'issue_closed_status_id' by its name
This commit is contained in:
parent
c93fc9f959
commit
bb461aefaf
3 changed files with 24 additions and 1 deletions
|
@ -5,6 +5,7 @@ redmine:
|
||||||
version: ${REDMINE_VERSION}
|
version: ${REDMINE_VERSION}
|
||||||
api_key: ${REDMINE_API_KEY}
|
api_key: ${REDMINE_API_KEY}
|
||||||
time_zone: "Europe/Berlin"
|
time_zone: "Europe/Berlin"
|
||||||
|
issue_closed_status: "Abgeschlossen" # Name of the "closed" status
|
||||||
no_bot_tag: "#nobot" # a tag that signals bot not to handle an issue
|
no_bot_tag: "#nobot" # a tag that signals bot not to handle an issue
|
||||||
|
|
||||||
actions:
|
actions:
|
||||||
|
|
6
exceptions.py
Normal file
6
exceptions.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
class IssueStatusNotFoundException(Exception):
|
||||||
|
def __init__(self, status_name: str):
|
||||||
|
self.status_name = status_name
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"No issue status with the name \"{self.status_name}\" could be found. Please check your config.yaml."
|
18
main.py
18
main.py
|
@ -7,6 +7,7 @@ import logging
|
||||||
from redminelib import Redmine
|
from redminelib import Redmine
|
||||||
from envyaml import EnvYAML
|
from envyaml import EnvYAML
|
||||||
from jinja2 import Template
|
from jinja2 import Template
|
||||||
|
from exceptions import IssueStatusNotFoundException
|
||||||
|
|
||||||
|
|
||||||
def treat_issues():
|
def treat_issues():
|
||||||
|
@ -26,6 +27,7 @@ def treat_issues():
|
||||||
version = config['redmine']['version']
|
version = config['redmine']['version']
|
||||||
api_key = config['redmine']['api_key']
|
api_key = config['redmine']['api_key']
|
||||||
time_zone = pytz.timezone(config['redmine']['time_zone'])
|
time_zone = pytz.timezone(config['redmine']['time_zone'])
|
||||||
|
issue_closed_status = config['redmine']['issue_closed_status']
|
||||||
no_bot_tag = config['redmine']['no_bot_tag']
|
no_bot_tag = config['redmine']['no_bot_tag']
|
||||||
actions = config['actions']
|
actions = config['actions']
|
||||||
logging.getLogger().setLevel(config['logging']['level'].upper())
|
logging.getLogger().setLevel(config['logging']['level'].upper())
|
||||||
|
@ -40,6 +42,20 @@ def treat_issues():
|
||||||
logging.error('Could not instantiate Redmine object', exc_info=True)
|
logging.error('Could not instantiate Redmine object', exc_info=True)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Get status id for closed issues
|
||||||
|
try:
|
||||||
|
all_status = redmine.issue_status.all()
|
||||||
|
issue_closed_statuses = all_status.filter(name=issue_closed_status)
|
||||||
|
if len(issue_closed_statuses) < 1:
|
||||||
|
raise IssueStatusNotFoundException(issue_closed_status)
|
||||||
|
elif len(issue_closed_statuses) > 1:
|
||||||
|
logging.warning(f'Expected one issue status with the name {issue_closed_status} but found '
|
||||||
|
f'{len(issue_closed_statuses)}')
|
||||||
|
issue_closed_status_id = issue_closed_statuses[0].id
|
||||||
|
except IssueStatusNotFoundException as e:
|
||||||
|
logging.error(e, exc_info=True)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
# Loop through all actions defined in config.yaml
|
# Loop through all actions defined in config.yaml
|
||||||
for action in actions.values():
|
for action in actions.values():
|
||||||
|
|
||||||
|
@ -72,7 +88,7 @@ def treat_issues():
|
||||||
|
|
||||||
# Update issue
|
# Update issue
|
||||||
if action.get('close_ticket') is True:
|
if action.get('close_ticket') is True:
|
||||||
redmine.issue.update(issue.id, notes=notes, status_id=config['redmine']['issue_closed_id'])
|
redmine.issue.update(issue.id, notes=notes, status_id=issue_closed_status_id)
|
||||||
logging.info(f"Ticket ID: {issue.id}, ticket closed")
|
logging.info(f"Ticket ID: {issue.id}, ticket closed")
|
||||||
elif action.get('change_status_to') is not None and isinstance(action.get('change_status_to'), int):
|
elif action.get('change_status_to') is not None and isinstance(action.get('change_status_to'), int):
|
||||||
redmine.issue.update(issue.id, notes=notes, status_id=action['change_status_to'])
|
redmine.issue.update(issue.id, notes=notes, status_id=action['change_status_to'])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue