Skip to content

Commit

Permalink
Code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmcmu committed Feb 6, 2024
1 parent 773c975 commit 8be3c0b
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions .github/workflows/Jirabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ jobs:
PULL_URL: ${{ github.event.pull_request.html_url }}
COMMENTS_URL: ${{ github.event.pull_request.comments_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
USER_DICT: ${{ vars.USER_DICT }}
GITHUB_JIRA_USER_MAP: ${{ vars.GITHUB_JIRA_USER_MAP }}
run: |
import os
import re
import json
from jira.client import JIRA
def updateIssue(jira, issue, user: str, pull_url: str) -> str:
def updateIssue(jira, issue, prAuthor: str, pull_url: str) -> str:
result = ''
statusName = str(issue.fields.status)
Expand Down Expand Up @@ -73,13 +73,13 @@ jobs:
elif issue.fields.customfield_10010 is not None and issue.fields.customfield_10010 != pull_url:
result += 'Additional PR: ' + pull_url + '\n'
if user:
if prAuthor:
if issue.fields.assignee is None:
jira.assign_issue(issue, user)
result += 'Assigning user: ' + user + '\n'
elif issue.fields.assignee is not None and issue.fields.assignee.name.lower() != user.lower():
result += 'Changing assignee from: ' + issue.fields.assignee.name + ' to: ' + user + '\n'
jira.assign_issue(issue, user)
jira.assign_issue(issue, prAuthor)
result += 'Assigning user: ' + prAuthor + '\n'
elif issue.fields.assignee is not None and issue.fields.assignee.name.lower() != prAuthor.lower():
result += 'Changing assignee from: ' + issue.fields.assignee.name + ' to: ' + prAuthor + '\n'
jira.assign_issue(issue, prAuthor)
return result
Expand All @@ -88,34 +88,46 @@ jobs:
jira_url = os.environ['JIRA_URL']
pr = os.environ['PULL_REQUEST_NUMBER']
title = os.environ['PULL_REQUEST_TITLE']
user = os.environ['PULL_REQUEST_AUTHOR_NAME']
prAuthor = os.environ['PULL_REQUEST_AUTHOR_NAME']
pull_url = os.environ['PULL_URL']
github_token = os.environ['GITHUB_TOKEN']
comments_url = os.environ['COMMENTS_URL']
print("%s %s %s" % (title, user, comments_url))
print("%s %s %s" % (title, prAuthor, comments_url))
result = ''
issuem = re.search("(HPCC4J|JAPI)-[0-9]+", title)
if issuem:
nameCorrectionPattern = re.compile("hpcc4j", re.IGNORECASE)
issue_name = nameCorrectionPattern.sub("JAPI",issuem.group())
userDict = json.loads(os.environ['USER_DICT'])
userDict = json.loads(os.environ['GITHUB_JIRA_USER_MAP'])
if not isinstance(userDict, dict):
userDict = {}
if user in userDict:
user = userDict.get(user, user)
if prAuthor in userDict:
prAuthor = userDict.get(prAuthor)
print('Mapped Github user to Jira user: ' + prAuthor)
options = {
'server': jira_url
}
jira = JIRA(options=options, basic_auth=(jirabot_user, jirabot_pass))
# Check if prAuthor exists in Jira
try:
jiraUser = jira.user(prAuthor)
if jiraUser is None:
prAuthor = None
print('Error: Unable to find Jira user: ' + prAuthor + ' continuing without assigning')
except Exception as error:
prAuthor = None
print('Error: Unable to find Jira user: ' + prAuthor + ' with error: ' + str(error) + ' continuing without assigning')
issue = jira.issue(issue_name)
result = 'Jirabot Action Result:\n'
result += updateIssue(jira, issue, user, pull_url)
result += updateIssue(jira, issue, prAuthor, pull_url)
jira.add_comment(issue, result)
else:
print('Unable to find Jira issue name in title')
Expand Down

0 comments on commit 8be3c0b

Please sign in to comment.