98 lines
3.5 KiB
Python
98 lines
3.5 KiB
Python
# find all subtasks of a story and keep description in sync
|
|
# zisco 2022-05-03 07:25
|
|
|
|
from tkinter.tix import INTEGER
|
|
from tokenize import Number
|
|
from types import ClassMethodDescriptorType
|
|
from jira import JIRA, Issue, Comment, exceptions
|
|
import re
|
|
import csv
|
|
import xlsxwriter
|
|
import logging
|
|
import pymsteams
|
|
import asyncio
|
|
import os
|
|
|
|
|
|
def update_subtask(issue, parent):
|
|
issue_dict = {
|
|
'project': {'id': 12501},
|
|
'summary': "[{}] {}".format(type, escaped),
|
|
'description': issue.fields.description,
|
|
'issuetype': {'name': issue_type},
|
|
'priority': {'name': issue.fields.priority.name},
|
|
'parent': {'key': parent},
|
|
'labels': issue.fields.labels,
|
|
#'customfield_10022' - Story Points
|
|
'timetracking': {'originalEstimate': "{}d".format(subtask_sp)},
|
|
'assignee': {'name': assignee}
|
|
}
|
|
new_issue = jira_server.create_issue(fields=issue_dict)
|
|
|
|
# consider components
|
|
existingComponents = []
|
|
for component in issue.fields.components:
|
|
existingComponents.append({"name" : component.name})
|
|
new_issue.update(fields={"components": existingComponents})
|
|
#new_issue.update(priority={"name": issue.fields.priority.name})
|
|
|
|
logging.info('Created Sub-Task {}'.format(new_issue))
|
|
|
|
# set https_proxy
|
|
os.environ['https_proxy'] = "http://uaproxy.wien.gv.at:3128"
|
|
|
|
logging.basicConfig(filename='sub_task_generator.log',
|
|
filemode='a',
|
|
format='%(asctime)s - %(levelname)s: %(message)s',
|
|
level=logging.INFO,
|
|
encoding='utf-8')
|
|
|
|
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})
|
|
|
|
# use filter or single issue
|
|
issues_Jql = jira_server.search_issues('filter=20262') #, expand='changelog')
|
|
#issues_Jql = jira_server.search_issues('key in (WRGWR-905)') #, 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('Keep sub-task description in sync with story description')
|
|
|
|
issue: Issue
|
|
parent_issue: Issue
|
|
chng=0
|
|
for issue in issues_Jql:
|
|
logging.info('Working on {}'.format(issue))
|
|
|
|
# get parent-issue
|
|
parent = issue.fields.parent
|
|
|
|
parent_issue = jira_server.issue(parent.key)
|
|
|
|
if parent_issue.fields.description != issue.fields.description:
|
|
issue.update(notify=False, description=parent_issue.fields.description)
|
|
logging.info('Updated sub-task description with story description')
|
|
|
|
chng += 1
|
|
# send info to teams as well
|
|
# TODO
|
|
|
|
# no changes detected
|
|
# You must create the connectorcard object with the Microsoft Webhook URL
|
|
if chng == 0:
|
|
loop = asyncio.get_event_loop()
|
|
|
|
# the async_connectorcard object is used instead of the normal one.
|
|
myTeamsMessage = pymsteams.async_connectorcard("https://atos365.webhook.office.com/webhookb2/f107169d-26b9-46ff-a973-b7aa1f37e552@33440fc6-b7c7-412c-bb73-0e70b0198d5a/IncomingWebhook/6cf64f8f6f1b40e198c1a981921afed1/181686a4-0d13-4990-a87a-e4814c1abc55")
|
|
|
|
myTeamsMessage.title("JIRA Sub-Task Syncer")
|
|
myTeamsMessage.text("No changes in description detected")
|
|
myTeamsMessage.color("#F9EC26")
|
|
|
|
myTeamsMessage.printme()
|
|
|
|
# to send the message, pass to the event loop
|
|
loop.run_until_complete(myTeamsMessage.send()) |