Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPCC4J-620 Jirabot: Sanitize information coming from external sources #720

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions .github/workflows/Jirabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,17 @@ jobs:
import time
import sys
import json
import subprocess
from email.utils import parseaddr
from atlassian.jira import Jira

def sanitizeInput(input: str, inputType: str) -> str:
if inputType.lower() == 'email':
# Return the email address only, returns '' if not valid or found
return parseaddr(input)[1]
else:
return ''

def updateIssue(jira, issue, prAuthor : str, transitionMap: dict, propertyMap: dict, pull_url: str) -> str:
result = ''

Expand Down Expand Up @@ -89,8 +98,12 @@ jobs:
assigneeId = assignee['accountId']
assigneeEmail = assignee["emailAddress"]

assigneeEmail = sanitizeInput(assigneeEmail, 'email')

prAuthorId = prAuthor["accountId"]
prAuthorEmail = prAuthor["emailAddress"]
prAuthorEmail = sanitizeInput(prAuthorEmail, 'email')

if assigneeId is None or assigneeId == '':
jira.assign_issue(issueName, prAuthorId)
result += 'Assigning user: ' + prAuthorEmail + '\n'
Expand All @@ -110,7 +123,6 @@ jobs:
github_token = os.environ['GITHUB_TOKEN']
comments_url = os.environ['COMMENTS_URL']

print("%s %s %s" % (title, prAuthor, comments_url))
result = ''
issuem = re.search("(HPCC4J|JAPI)-[0-9]+", title)
if issuem:
Expand All @@ -132,7 +144,7 @@ jobs:
if userSearchResults and len(userSearchResults) > 0:
jiraUser = userSearchResults[0]
else:
print('Error: Unable to find Jira user: ' + prAuthor + ' continuing without assigning')
print('Error: Unable to map GitHub user to Jira user, continuing without assigning')

if not jira.issue_exists(issue_name):
sys.exit('Error: Unable to find Jira issue: ' + issue_name)
Expand All @@ -159,8 +171,7 @@ jobs:
# Escape the result for JSON
result = json.dumps(result)

curlCommand = 'curl -X POST %s -H "Content-Type: application/json" -H "Authorization: token %s" --data \'{ "body": %s }\'' % ( comments_url, github_token, result )
os.system(curlCommand)
subprocess.run(['curl', '-X', 'POST', comments_url, '-H', 'Content-Type: application/json', '-H', f'Authorization: token {github_token}', '--data', f'{{ "body": {result} }}'], check=True)
else:
print('Unable to find Jira issue name in title')

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/JirabotMerge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ jobs:
branch_name = os.environ['BRANCH_NAME']
comments_url = os.environ['COMMENTS_URL']

print("Attempting to close out Jira issue: %s %s %s" % (title, user, comments_url))
result = ''
issuem = re.search("(HPCC4J|JAPI)-[0-9]+", title)
if issuem:
Expand Down
Loading