Skip to content

Commit f0dd102

Browse files
committed
Added jira issue property map
1 parent 19467ed commit f0dd102

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

.github/workflows/Jirabot.yml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ jobs:
3838
COMMENTS_URL: ${{ github.event.pull_request.comments_url }}
3939
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4040
GHUB_JIRA_USER_MAP: ${{ vars.GHUB_JIRA_USER_MAP }}
41+
JIRA_ISSUE_PROPERTY_MAP: ${{ vars.JIRA_ISSUE_PROPERTY_MAP }}
4142
run: |
4243
import os
4344
import re
4445
import json
4546
from jira.client import JIRA
4647
47-
def updateIssue(jira, issue, prAuthor: str, pull_url: str) -> str:
48+
def updateIssue(jira, issue, prAuthor: str, propertyMap: dict, pull_url: str) -> str:
4849
result = ''
4950
5051
statusName = str(issue.fields.status)
@@ -67,10 +68,17 @@ jobs:
6768
transitions = jira.transitions(issue)
6869
result += 'Error: Transition: "' + transition + '" failed with: "' + str(error) + '" Valid transitions=' + str(transitions) + '\n'
6970
70-
if issue.fields.customfield_10010 is None:
71-
issue.update(fields={'customfield_10010': pull_url})
71+
prFieldName = propertyMap.get('pullRequestFieldName', 'customfield_10010')
72+
try:
73+
currentPR = getattr(issue.fields, prFieldName)
74+
except:
75+
currentPR = None
76+
print('Error: Unable to get current pull request with field name: ' + prFieldName)
77+
78+
if currentPR is None:
79+
issue.update(fields={prFieldName: pull_url})
7280
result += 'Updated PR\n'
73-
elif issue.fields.customfield_10010 is not None and issue.fields.customfield_10010 != pull_url:
81+
elif currentPR is not None and currentPR != pull_url:
7482
result += 'Additional PR: ' + pull_url + '\n'
7583
7684
if prAuthor:
@@ -127,7 +135,11 @@ jobs:
127135
issue = jira.issue(issue_name)
128136
result = 'Jirabot Action Result:\n'
129137
130-
result += updateIssue(jira, issue, prAuthor, pull_url)
138+
jiraIssuePropertyMap = json.loads(os.environ['JIRA_ISSUE_PROPERTY_MAP'])
139+
if not isinstance(jiraIssuePropertyMap, dict):
140+
jiraIssuePropertyMap = {}
141+
142+
result += updateIssue(jira, issue, prAuthor, jiraIssuePropertyMap, pull_url)
131143
jira.add_comment(issue, result)
132144
else:
133145
print('Unable to find Jira issue name in title')

0 commit comments

Comments
 (0)