# -*- coding: utf-8 -*- """ Created on Thu Feb 4 16:43:30 2021 @author: CHEO001 """ #Creates a JIRA object for bulk operations # https://jira.readthedocs.io/en/master/examples.html#quickstart # https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/#creating-an-issue-examples # https://jira.readthedocs.io/examples.html#issues # https://atlassian-python-api.readthedocs.io/jira.html from jira import JIRA #pip install jira (required) from dotenv import load_dotenv import os load_dotenv() jiraServer = os.getenv('JIRASERVER') jiraUserID = os.getenv('JIRAUSERID') jiraAPIKey= os.getenv('JIRAAPIKEY') jira = JIRA( basic_auth=(jiraUserID, jiraAPIKey), options={ 'server': jiraServer } ) def resetTBD(issue): TBDdescription = 'h1. Description\n\nCreate a logic that matches\ \n\nh1. Requirements\n\n* Process must work\ \n\nh1. Acceptance Criterion\n\n* Ensure that the lookup process works\ \n\nh1. References\n\n* Confluence Documentation *TBD*' TBDcomment = 'Repurposed for future use' TBDsummary = '[TBD] Future use' TBDdict = {'description': TBDdescription, \ 'summary': TBDsummary, \ 'labels': [], \ 'components': [{}],\ 'assignee': None, \ 'customfield_10014': None} ticket = jira.issue(issue) ticket.update(fields=TBDdict) jira.add_comment(issue, TBDcomment) def addLabels(issue, labels): #use labels as a list [] ticket = jira.issue(issue) ticket.update(fields={'labels': labels}) def resetLabels(issue): ticket = jira.issue(issue) ticket.update(fields={'labels': []}) def addComponents(issue, components): #use components as a list [] cLst = [] for c in components: cLst.append({'name': c}) ticket = jira.issue(issue) ticket.update(fields={'components':[cLst]}) def resetComponents(issue): ticket = jira.issue(issue) ticket.update(fields={'components': [{}]}) def addComment(issue, comment): jira.add_comment(issue,comment) def jiraTransition(issue, transitionid, resolutionid): jira.transition_issue(issue, transition=transitionid, resolution={'id':resolutionid}) def getStatus(issue): status=jira.issue(issue).fields.status.name return status # creates a jira and returns the jira issue key def createJira(projectid,summary,description,issuetype,assignee): new_issue = jira.create_issue(project=projectid, summary=summary, description=description, issuetype={'name': issuetype}) new_issue.update(assignee={'name': assignee}) return new_issue.key def getIssue(key): issue=jira.issue(key) return issue ''' INT project ID - 323 jira ID self: 712020:ddb3bf46-f93a-44e9-bdfd-a1791f794516 rob: 5ca363ad23df2a41d8378ce2 [~accountid:ACCOUNT-ID-HERE] do a thing [~accountid:{{comment.author.accountId}}] [~accountid:{{issue.assignee.accountId}}] [~accountid:{{issue.reporter.accountId}}] ''' """ jira.transitions() 121 Blocked 141 In Progress 151 In Requirements 161 Ready for Dev 231 OnHold 251 To Do 261 Done 271 Backlog 91 To Fix 101 Ready for Review 111 Ready for QA 81 In QA =jira.resolutions() [, , , , , , , , , , ] """ #projects = jira.projects() #issue = jira.issue("DLPM-1142") """issue_list = [ { 'project': {'id': 123}, 'summary': 'First issue of many', 'description': 'Look into this one', 'issuetype': {'name': 'Bug'}, }, { 'project': {'key': 'FOO'}, 'summary': 'Second issue', 'description': 'Another one', 'issuetype': {'name': 'Bug'}, }, { 'project': {'name': 'Bar'}, 'summary': 'Last issue', 'description': 'Final issue of batch.', 'issuetype': {'name': 'Story'}, 'priority': {'id': '4'}, 'labels': ['LinkFire', 'Post-MVP', 'Snowflake'], 'components': [{'name': 'DB'}] 'customfield_10014': 'DLPM-1173', }] issues = jira.create_issues(field_list=issue_list) #NOTES priority 4 = low, 3 = medium... customfield_10014 = Epic Link """