Created
May 24, 2016 15:07
-
-
Save smola/72db05b35a5738e605fd48f7a7fc5b76 to your computer and use it in GitHub Desktop.
jira_adjust_time_tracking.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf-8 | |
""" | |
Adjusts the time tracking for issues in a given JIRA project. | |
Requires 'jira' library: | |
$ pip install jira | |
JIRA credentials need to be stored in a file '.jira_auth.json'. | |
Its contents should be: | |
{ "username": "your-username", "password": "your-password" } | |
Usage: | |
$ python <this-script> <project-key> | |
""" | |
from jira import JIRA | |
import json | |
import sys | |
def connect_jira(): | |
options = { | |
'server': 'https://stratio.atlassian.net' | |
} | |
basic_auth = json.load(open('.jira_auth.json', 'r')) | |
return JIRA(options, basic_auth=(basic_auth['username'], basic_auth['password'])) | |
def get_story_points(issue): | |
""" | |
Get Story Points for an issue. | |
""" | |
return issue.fields.customfield_10004 | |
def update_timetracking(issue, original=None, remaining=None): | |
""" | |
Update original and remaining estimates. | |
""" | |
new_timetracking = {} | |
if 'timetracking' in issue.fields.__dict__: | |
new_timetracking['originalEstimate'] = issue.fields.timetracking.originalEstimate | |
new_timetracking['remainingEstimate'] = issue.fields.timetracking.remainingEstimate | |
if original is not None: | |
new_timetracking['originalEstimate'] = orginal | |
if remaining is not None: | |
new_timetracking['remainingEstimate'] = remaining | |
issue.update(fields={'timetracking': new_timetracking}) | |
if len(sys.argv) != 2: | |
print('Usage: %s <project-key>' % sys.argv[0]) | |
sys.exit(1) | |
jira = connect_jira() | |
project_name = sys.argv[1] | |
project = jira.project(project_name) | |
# | |
# For every issue with Story Points and no Original Estimate, | |
# set Original Estimate to Story Points (in workdays). | |
# | |
issues = jira.search_issues('project = %s AND "Story Points" is not empty and (originalEstimate is EMPTY or originalEstimate = 0m)' % project_name) | |
for issue in issues: | |
new_timetracking = {} | |
update_timetracking(original='%dd' % get_story_points(issue)) | |
# | |
# For every issue that is closed and has a Remaining Estimate not set to 0m. Set it to 0m. | |
# | |
issues = jira.search_issues('project = %s and resolution = Fixed and status = Done and remainingEstimate != 0m' % project_name) | |
for issue in issues: | |
update_timetracking(issue, original='%dd' % get_story_points(issue), remaining = '0m') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment