Skip to content

Instantly share code, notes, and snippets.

@sagarjhaa
Created March 6, 2020 00:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sagarjhaa/5b7e624bf43abe78f0f6963cb1ebb359 to your computer and use it in GitHub Desktop.
Save sagarjhaa/5b7e624bf43abe78f0f6963cb1ebb359 to your computer and use it in GitHub Desktop.
python script to list all your redmines for a year
import requests
from datetime import datetime
from collections import defaultdict
def get_redmines(username,password,redmineurl,projectname):
response = None
url = """https://{}:{}@{}/projects/{}/issues.json?utf8=✓s
'&limit=1000
'&set_filter=1
'&sort=assigned_to,id:desc
'&f[]=fixed_version_id
'&f[]=assigned_to_id&op[assigned_to_id]==&v[assigned_to_id][]=me&f[]=
'&c[]=project&c[]=tracker&c[]=status&c[]=priority&c[]=subject&c[]=assigned_to&c[]=fixed_version&c[]=category&c[]=updated_on&group_by=&t[]="""
url = url.format(username,password,redmineurl,projectname)
response = requests.get(url).json()
return response
def display_issues(month,issues):
print(month)
for index,issue in enumerate(issues,1):
start_date = datetime.strptime(issue['created_on'].split('T')[0],'%Y-%m-%d').date()
if 'closed_on' in issue:
close_date = datetime.strptime(issue['closed_on'].split('T')[0],'%Y-%m-%d').date()
else:
close_date = 'OPEN'
print("{:3} | {:10} | {:10} | {} | {:30} | {}".format(index,str(start_date),str(close_date),issue['id'],issue['category']['name'],issue['subject']))
print('-----'*30)
def populate_data(year,response):
group_by_month = defaultdict(list)
if response and 'issues' in response:
for index,issue in enumerate(response['issues'],1):
group_by_month[issue['fixed_version']['name']].append(issue)
else:
print('Error - {}'.format(response['errors']))
for month in range(1,13):
month = 'R'+str(year)+'.'+str(month)
if month in group_by_month:
display_issues(month, group_by_month[month])
# Change the username, password, redmine-url and the project-name.
response = get_redmines('username','password','redmine-url','project-name')
populate_data(year=20,response=response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment