Skip to content

Commit

Permalink
HPCC4J-593 Update JirabotMerge for Jira Cloud
Browse files Browse the repository at this point in the history
- Updated jirabot merge script to use Atlassian python library
- Updated project name in JirabotMerge and Jirabot

Signed-off-by: James McMullan [email protected]
  • Loading branch information
jpmcmu committed Apr 8, 2024
1 parent eea845e commit 5d14862
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Jirabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ jobs:
issuem = re.search("(HPCC4J|JAPI)-[0-9]+", title)
if issuem:
nameCorrectionPattern = re.compile("hpcc4j", re.IGNORECASE)
issue_name = nameCorrectionPattern.sub("JAPI",issuem.group())
issue_name = nameCorrectionPattern.sub("HPCC4J",issuem.group())
userDict = json.loads(os.environ['GHUB_JIRA_USER_MAP'])
if not isinstance(userDict, dict):
Expand Down
38 changes: 21 additions & 17 deletions .github/workflows/JirabotMerge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
import subprocess
import time
import sys
from jira.client import JIRA
from atlassian.jira import Jira
def extractVersion(versionStr):
parts = versionStr.split('.')
Expand Down Expand Up @@ -131,13 +131,13 @@ jobs:
for fixVersion in fixVersions:
alreadyHasFixVersion = False
versions = jira.project_versions('JAPI')
versions = jira.get_project_versions('HPCC4J')
for v in versions:
if v.name == fixVersion:
alreadyHasFixVersion = True
if not alreadyHasFixVersion:
jira.create_version(name=fixVersion, project='JAPI', description=fixVersion)
jira.add_version(fixVersion, HPCC4J', fixVersion)
return fixVersions
Expand All @@ -146,18 +146,21 @@ jobs:
versionsToAdd = []
issueName = issue['key']
issueFields = issue['fields']
for addedVersion in fixVersions:
alreadyHasFixVersion = False
for v in issue.fields.fixVersions:
for v in issueFields['fixVersions']:
if v.name == addedVersion:
alreadyHasFixVersion = True
break
if not alreadyHasFixVersion:
versionsToAdd.append(addedVersion)
versions = jira.project_versions('JAPI')
versions = jira.get_project_versions('HPCC4J')
updatedVersionList = []
for v in issue.fields.fixVersions:
for v in issueFields['fixVersions']:
updatedVersionList.append({'id' : v.id})
for fixVersionName in versionsToAdd:
Expand All @@ -174,14 +177,14 @@ jobs:
result += "Error: Unable to find fix version: " + fixVersionName + "\n"
if len(versionsToAdd) > 0:
issue.update(fields={'fixVersions': updatedVersionList})
jira.update_issue_field(issueName, {'fixVersions': updatedVersionList})
else:
result += "Fix versions already added.\n"
statusName = str(issue.fields.status)
statusName = str(issueFields['status']['name'])
if statusName != 'Resolved':
transition = 'Resolve Issue'
jira.transition_issue(issue, transition)
transition = 'Accept Pull Request'
jira.issue_transition(issue_name, transition)
result += "Workflow Transition: 'Resolve issue'\n"
return result
Expand All @@ -203,23 +206,24 @@ jobs:
issuem = re.search("(HPCC4J|JAPI)-[0-9]+", title)
if issuem:
nameCorrectionPattern = re.compile("hpcc4j", re.IGNORECASE)
issue_name = nameCorrectionPattern.sub("JAPI",issuem.group())
issue_name = nameCorrectionPattern.sub("HPCC4J",issuem.group())
options = {
'server': jira_url
}
jira = JIRA(options=options, basic_auth=(jirabot_user, jirabot_pass))
issue = jira.issue(issue_name)
if issue is None:
print('Unable to find issue with name: ' + issue_name)
sys.exit(1)
jira = Jira(url=jira_url, username=jirabot_user, password=jirabot_pass, cloud=True)
if not jira.issue_exists(issue_name):
sys.exit('Error: Unable to find Jira issue: ' + issue_name)
else:
issue = jira.issue(issue_name)
result = 'Jirabot Action Result:\n'
fixVersions = generateFixVersionList(jira, branch_name)
result += resolveIssue(jira, issue, fixVersions)
jira.add_comment(issue, result)
jira.issue_add_comment(issue_name, result)
else:
print('Unable to find Jira issue name in title')
Expand Down

0 comments on commit 5d14862

Please sign in to comment.