From 8f00082431c09cbf90f04655577fe7ccfc68634b Mon Sep 17 00:00:00 2001 From: Zimmerberger Markus Date: Mon, 23 Oct 2023 15:28:26 +0200 Subject: [PATCH] Planning Excel export support --- JIRA_EffortbyComments.py | 36 +++++++++++++++++++--- JIRA_EffortbySubTasks.py | 66 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 JIRA_EffortbySubTasks.py diff --git a/JIRA_EffortbyComments.py b/JIRA_EffortbyComments.py index 072d53d..de28613 100644 --- a/JIRA_EffortbyComments.py +++ b/JIRA_EffortbyComments.py @@ -1,6 +1,7 @@ # find comments with estimations out of pre-planning # zisco 2021-09-30 19:50 +# TODO: Excel export from types import ClassMethodDescriptorType from jira import JIRA, Issue, Comment, exceptions import re @@ -18,6 +19,21 @@ host = "https://jira.wien.gv.at/" pat = "OTAyMTM3MjY0MjE0Ovz6bu0ti1TlEdSegmmiWiJ2wGeD" sprint = 9 +row = 0; col = 0 +workbook = xlsxwriter.Workbook(f'efforts sprint {sprint} (from comment).xlsx') +worksheet = workbook.add_worksheet('efforts') + +cell_format = workbook.add_format() +cell_format.set_bold() + +worksheet.write(row, col, 'Story' , cell_format) +worksheet.write(row, col + 1, 'Sub-Task' , cell_format) +worksheet.write(row, col + 2, 'Summary' , cell_format) +worksheet.write(row, col + 3, 'timeoriginalestimate', cell_format) +worksheet.write(row, col + 4, 'SP' , cell_format) +worksheet.write(row, col + 5, 'PT' , cell_format) +row += 1 + headers = JIRA.DEFAULT_OPTIONS["headers"].copy() headers["Authorization"] = f"Bearer {pat}" jira_server = JIRA(server=host, options={"headers": headers}) @@ -60,22 +76,32 @@ for issue in issues_Jql: if (comment_line_parts[1][-2:] != 'NN') and (comment_line_parts[1][-1:] != '-'): # NN means NotNecessary comment_line_sub_parts = comment_line_parts[1].split(' (') if len(comment_line_sub_parts)>1: - if comment_line_sub_parts[0].isnumeric(): + if comment_line_sub_parts[0].strip().isnumeric(): subtask_ph = float(comment_line_sub_parts[0]) * 0.5 estimation_remark = comment_line_sub_parts[1] else: subtask_ph = 0 else: - if comment_line_sub_parts[1].isnumeric(): - subtask_ph = float(comment_line_parts[1]) * 0.5 + if comment_line_sub_parts[0].strip().isnumeric(): + subtask_ph = float(comment_line_sub_parts[0]) * 0.5 estimation_remark = "" else: subtask_ph = 0 - #logging.info(f"Effort {comment_line_sub_parts[0]}") + + worksheet.write(row, col, issue.key) + worksheet.write(row, col + 1, 'na') + worksheet.write(row, col + 2, comment_line_parts[0]) + worksheet.write(row, col + 3, 'na') + worksheet.write(row, col + 4, subtask_ph) + worksheet.write(row, col + 5, f'=E{row + 1}/0.5') + row += 1 sp_sum += subtask_ph / 0.5 try: if sp != sp_sum: logging.info(f"Estimated story-points changed to Sum(Sub-Tasks story-points): {sp_sum}") except exceptions.JIRAError: - logging.error("Issue {} has no (visible) Story Points-attribute".format(issue.key)) \ No newline at end of file + logging.error("Issue {} has no (visible) Story Points-attribute".format(issue.key)) + +worksheet.autofit() +workbook.close() \ No newline at end of file diff --git a/JIRA_EffortbySubTasks.py b/JIRA_EffortbySubTasks.py new file mode 100644 index 0000000..9853913 --- /dev/null +++ b/JIRA_EffortbySubTasks.py @@ -0,0 +1,66 @@ +# find comments with estimations out of pre-planning +# zisco 2021-09-30 19:50 + +from types import ClassMethodDescriptorType +from jira import JIRA, Issue, Comment, exceptions +import re +import csv +import xlsxwriter +import logging + +logging.basicConfig(filename='sprint efforts.log', + filemode='a', + format='%(asctime)s - %(levelname)s: %(message)s', + level=logging.INFO, + encoding='utf-8') + +host = "https://jira.wien.gv.at/" +pat = "OTAyMTM3MjY0MjE0Ovz6bu0ti1TlEdSegmmiWiJ2wGeD" +sprint = 9 + +row = 0; col = 0 +workbook = xlsxwriter.Workbook(f'efforts sprint {sprint}.xlsx') +worksheet = workbook.add_worksheet('efforts') + +cell_format = workbook.add_format() +cell_format.set_bold() + +worksheet.write(row, col, 'Story' , cell_format) +worksheet.write(row, col + 1, 'Sub-Task' , cell_format) +worksheet.write(row, col + 2, 'Summary' , cell_format) +worksheet.write(row, col + 3, 'timeoriginalestimate', cell_format) +worksheet.write(row, col + 4, 'SP' , cell_format) +worksheet.write(row, col + 5, 'PT' , cell_format) +row += 1 + +headers = JIRA.DEFAULT_OPTIONS["headers"].copy() +headers["Authorization"] = f"Bearer {pat}" +jira_server = JIRA(server=host, options={"headers": headers}) + +# use filter or single issue +issues_Jql = jira_server.search_issues('filter=24707') #, expand='changelog') +#issues_Jql = jira_server.search_issues('key in (wrgwr-856, dkarb-367)', expand='changelog') +#issues_Jql = jira_server.search_issues('key in (DKARB-140)') #, expand='changelog') +#issues_Jql = jira_server.search_issues('labels in (Refinement11012022) AND type not in (Bug) AND status not in (Done) and ("Story Points" is EMPTY or "Story Points" = 0)') #, expand='changelog') + +logging.info('Sum effort stored in issue-comments of pre-planning sprint {}'.format(sprint)) +xsp = lambda s: s or 0 + +issue: Issue +for issue in issues_Jql: + single_issue = jira_server.issue(issue.key) + logging.info(f'OriginalTimeEstimate: {single_issue.fields.timeoriginalestimate}') + + for subtask in issue.fields.subtasks: + ssubtask = jira_server.issue(subtask.key) # this is essential to access 'timeoriginalestimate' + + worksheet.write(row, col, issue.key) + worksheet.write(row, col + 1, ssubtask.key) + worksheet.write(row, col + 2, ssubtask.fields.summary) + worksheet.write(row, col + 3, ssubtask.fields.timeoriginalestimate) + worksheet.write(row, col + 4, f'=D{row + 1}/28800') + worksheet.write(row, col + 5, f'=E{row + 1}/0.5') + row += 1 + +worksheet.autofit() +workbook.close() \ No newline at end of file