add template variables for 'days_since_last_update' and 'assigned_to'

This commit is contained in:
Marc Michalsky 2021-11-04 17:14:00 +01:00
parent 5f63efebe1
commit c93fc9f959
4 changed files with 18 additions and 5 deletions

View file

@ -4,7 +4,7 @@ redmine:
url: ${REDMINE_URL}
version: ${REDMINE_VERSION}
api_key: ${REDMINE_API_KEY}
issue_closed_id: 5 # Id of the "closed" status
time_zone: "Europe/Berlin"
no_bot_tag: "#nobot" # a tag that signals bot not to handle an issue
actions:

10
main.py
View file

@ -1,7 +1,8 @@
#!/usr/bin/env python3
import sys
import os
from datetime import date, timedelta
from datetime import date, datetime, timedelta
import pytz
import logging
from redminelib import Redmine
from envyaml import EnvYAML
@ -24,6 +25,7 @@ def treat_issues():
url = config['redmine']['url']
version = config['redmine']['version']
api_key = config['redmine']['api_key']
time_zone = pytz.timezone(config['redmine']['time_zone'])
no_bot_tag = config['redmine']['no_bot_tag']
actions = config['actions']
logging.getLogger().setLevel(config['logging']['level'].upper())
@ -62,7 +64,11 @@ def treat_issues():
with open(f"{dir_path}templates/{action['template']}", newline='\r\n') as f:
content = f.read()
template = Template(content)
notes = template.render(author=issue.author.name, time_range=action['time_range'], url=issue.url)
notes = template.render(
issue=issue,
time_range=action['time_range'],
days_since_last_update=(datetime.now(time_zone) - issue.updated_on.replace(tzinfo=time_zone)).days
)
# Update issue
if action.get('close_ticket') is True:

View file

@ -8,3 +8,4 @@ python-redmine==2.3.0
PyYAML==5.4.1
requests==2.25.1
urllib3==1.26.5
pytz~=2021.3

View file

@ -1,6 +1,12 @@
Hello {{ author }},
{% if issue.assigned_to is defined %}
Hello {{ issue.assigned_to }},
this ticket wasn't updated for at least {{ time_range }}. We therefore assume that the problem has been solved in the meantime. If the issue persists, please reopen the ticket and give us a brief update on the situation.
this ticket is assigned to you but wasn't updated for at least {{ days_since_last_update }}. We therefore assume that the problem has been solved in the meantime. If the issue persists, please reopen the ticket and give us a brief update on the situation.
{% else %}
Hello {{ issue.author }},
this ticket wasn't updated for at least {{ days_since_last_update }}. We therefore assume that the problem has been solved in the meantime. If the issue persists, please reopen the ticket and give us a brief update on the situation.
{% endif %}
Here is the ticket: {{ url }}
Yours sincerely