✨ find issue status ids by their names
This commit is contained in:
parent
695da96cbe
commit
aa4e51fcb1
2 changed files with 27 additions and 14 deletions
|
@ -5,7 +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
|
issue_closed_status: "Done" # 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:
|
||||||
|
@ -27,7 +27,7 @@ actions:
|
||||||
- "IT Tickets"
|
- "IT Tickets"
|
||||||
status:
|
status:
|
||||||
- "In revision"
|
- "In revision"
|
||||||
change_status_to: 4
|
change_status_to: "Waiting for feedback"
|
||||||
template: "nudge_ticket"
|
template: "nudge_ticket"
|
||||||
|
|
||||||
|
|
||||||
|
|
37
main.py
37
main.py
|
@ -10,6 +10,17 @@ from jinja2 import Template
|
||||||
from exceptions import IssueStatusNotFoundException
|
from exceptions import IssueStatusNotFoundException
|
||||||
|
|
||||||
|
|
||||||
|
def get_issue_status_id(status_name: str, redmine: Redmine):
|
||||||
|
all_status = redmine.issue_status.all()
|
||||||
|
statuses = all_status.filter(name=status_name)
|
||||||
|
if len(statuses) < 1:
|
||||||
|
raise IssueStatusNotFoundException(status_name)
|
||||||
|
elif len(statuses) > 1:
|
||||||
|
logging.warning(f'Expected one issue status with the name {status_name} but found '
|
||||||
|
f'{len(statuses)}')
|
||||||
|
return statuses[0].id
|
||||||
|
|
||||||
|
|
||||||
def treat_issues():
|
def treat_issues():
|
||||||
dir_path = os.path.dirname(os.path.realpath(__file__)) + '/'
|
dir_path = os.path.dirname(os.path.realpath(__file__)) + '/'
|
||||||
|
|
||||||
|
@ -43,18 +54,11 @@ def treat_issues():
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Get status id for closed issues
|
# Get status id for closed issues
|
||||||
|
issue_closed_status_id = None
|
||||||
try:
|
try:
|
||||||
all_status = redmine.issue_status.all()
|
issue_closed_status_id = get_issue_status_id(issue_closed_status, redmine)
|
||||||
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:
|
except IssueStatusNotFoundException as e:
|
||||||
logging.error(e, exc_info=True)
|
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():
|
||||||
|
@ -62,6 +66,15 @@ def treat_issues():
|
||||||
# Calculate end_date
|
# Calculate end_date
|
||||||
end_date = date.today() - timedelta(days=+int(action['time_range']))
|
end_date = date.today() - timedelta(days=+int(action['time_range']))
|
||||||
|
|
||||||
|
# Get change_status_id
|
||||||
|
change_status_id = None
|
||||||
|
if action.get('change_status_to'):
|
||||||
|
try:
|
||||||
|
change_status_id = get_issue_status_id(action['change_status_to'], redmine)
|
||||||
|
except IssueStatusNotFoundException as e:
|
||||||
|
logging.error(e, exc_info=True)
|
||||||
|
continue
|
||||||
|
|
||||||
# Loop through affected issues
|
# Loop through affected issues
|
||||||
try:
|
try:
|
||||||
for issue in redmine.issue \
|
for issue in redmine.issue \
|
||||||
|
@ -95,11 +108,11 @@ def treat_issues():
|
||||||
)
|
)
|
||||||
|
|
||||||
# Update issue
|
# Update issue
|
||||||
if action.get('close_ticket') is True:
|
if action.get('close_ticket') is True and issue_closed_status_id is not None:
|
||||||
redmine.issue.update(issue.id, notes=notes, status_id=issue_closed_status_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 change_status_id is not None:
|
||||||
redmine.issue.update(issue.id, notes=notes, status_id=action['change_status_to'])
|
redmine.issue.update(issue.id, notes=notes, status_id=change_status_id)
|
||||||
logging.info(f"Ticket ID: {issue.id}, changed ticket status")
|
logging.info(f"Ticket ID: {issue.id}, changed ticket status")
|
||||||
else:
|
else:
|
||||||
redmine.issue.update(issue.id, notes=notes)
|
redmine.issue.update(issue.id, notes=notes)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue