# recalculate historical estimations # zisco 2021-10-05 15:54 import logging from types import ClassMethodDescriptorType from jira import JIRA, Issue, Comment, exceptions import re import csv import xlsxwriter logging.basicConfig(filename='jahe.log', filemode='a', format='%(asctime)s - %(message)s', level=logging.INFO) host = "https://jira.wien.gv.at/" pat = "OTAyMTM3MjY0MjE0Ovz6bu0ti1TlEdSegmmiWiJ2wGeD" headers = JIRA.DEFAULT_OPTIONS["headers"].copy() headers["Authorization"] = f"Bearer {pat}" jira_server = JIRA(server=host, options={"headers": headers}) logging.info("Connection to JIRA established") # issues_Jql = jira_server.search_issues('cf[10022] is not EMPTY AND labels not in (Refinement23092021, hotfix0921) AND status not in (Done) and key not in (wrgwr-929)', expand='changelog') issues_Jql = jira_server.search_issues('key in (wrgwr-856, wrgwr-854, wrgwr-853)', expand='changelog') xsp = lambda s: s or 0 sp_sum = 0 issue: Issue for issue in issues_Jql: logging.info("Working on {}".format(issue.key)) sp = 0 if hasattr(issue.fields, 'customfield_10022'): sp = xsp(issue.fields.customfield_10022) sp_sum += sp # log old values print(sp, sp/8) originalEstimate = issue.fields.timeoriginalestimate logging.info("Estimation-system change: Old Story Points {} -> new Story Points {}".format(sp, sp/8)) # probably already adapted? Search for activity 'updated the Story Points' doChange = True for history in issue.changelog.histories: if doChange==False: break if (history.author.key=='JIRAUSER17211'): for item in history.items: if (item.field=='Story Points'): doChange = False break if doChange: # update story-points try: issue.update(fields={'customfield_10022': sp/8}) comment = jira_server.add_comment(issue, "Estimation-system change: Old Story Points {} -> new Story Points {}".format(sp, sp/8)) except exceptions.JIRAError: logging.error("Issue {} has no (visible) Story Points-attribute".format(issue.key)) finally: print('Done {}'.format(issue.key))