Skip to content

Commit

Permalink
Code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmcmu committed Sep 10, 2024
1 parent cd4b362 commit 54202c1
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions .github/workflows/JirabotMerge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
PULL_REQUEST_TITLE : ${{ github.event.pull_request.title }}
PULL_REQUEST_AUTHOR_NAME : ${{ github.event.pull_request.user.login }}
PULL_URL: ${{ github.event.pull_request.html_url }}
PROJECT_CONFIG: ${{ vars.PROJECT_CONFIG}}
COMMENTS_URL: ${{ github.event.pull_request.comments_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH_NAME: ${{ github.ref_name }}
Expand Down Expand Up @@ -95,8 +96,15 @@ jobs:
major, minor, point = map(int, version)
return f"{major}.{minor}.{point}"
def createReleaseTagPattern(major = None, minor = None, point = None):
releaseTagPattern = 'hpcc4j_'
def createReleaseTagPattern(projectConfig, major = None, minor = None, point = None):
releaseTagPrefix = projectConfig.get('tagPrefix')
releaseTagPostfix = projectConfig.get('tagPostfix')
if releaseTagPrefix is None or releaseTagPostfix is None:
print('Error: PROJECT_CONFIG is missing required fields: tagPrefix and/or tagPostfix')
sys.exit(1)
releaseTagPattern = releaseTagPrefix
if major is not None:
releaseTagPattern += str(major) + '\.'
else:
Expand All @@ -112,16 +120,16 @@ jobs:
else:
releaseTagPattern += '[0-9]+(-[0-9]+)?'
releaseTagPattern += '-release$'
releaseTagPattern += releaseTagPostfix + '$'
return releaseTagPattern
def getLatestSemVer(major = None, minor = None, point = None):
cmd = "git tag --list --sort=-v:refname | grep -E '" + createReleaseTagPattern(major, minor, point) + "' | head -n 1"
def getLatestSemVer(projectConfig, major = None, minor = None, point = None):
cmd = "git tag --list --sort=-v:refname | grep -E '" + createReleaseTagPattern(projectConfig, major, minor, point) + "' | head -n 1"
return getTagVersionForCmd(cmd)
def generateFixVersionList(jira, projectName, branchName):
latestVersion = getLatestSemVer()
def generateFixVersionList(jira, projectConfig, projectName, branchName):
latestVersion = getLatestSemVer(projectConfig)
# If we are merging into master we assume it is going into the next minor release
fixVersions = []
Expand All @@ -134,12 +142,12 @@ jobs:
branchVersion = extractVersion(branchVersionMatch.group(1))
# Get latest release in branch
latestBranchVer = getLatestSemVer(branchVersion[0], branchVersion[1])
latestBranchVer = getLatestSemVer(projectConfig, branchVersion[0], branchVersion[1])
curMajor = branchVersion[0]
latestMajor = latestVersion[0]
while curMajor <= latestMajor:
latestVersionInMajor = getLatestSemVer(curMajor)
latestVersionInMajor = getLatestSemVer(projectConfig, curMajor)
curMinor = 0
if curMajor == branchVersion[0]:
Expand All @@ -148,7 +156,7 @@ jobs:
latestMinor = latestVersionInMajor[1]
while curMinor <= latestMinor:
latestPointInMinor = getLatestSemVer(curMajor, curMinor)
latestPointInMinor = getLatestSemVer(projectConfig, curMajor, curMinor)
fixVersions.append(buildVersionString([latestPointInMinor[0], latestPointInMinor[1], latestPointInMinor[2] + 2]))
curMinor += 2
curMajor += 1
Expand Down Expand Up @@ -236,7 +244,20 @@ jobs:
github_token = os.environ['GITHUB_TOKEN']
branch_name = os.environ['BRANCH_NAME']
comments_url = os.environ['COMMENTS_URL']
project_name = 'HPCC4J'
projectConfig = json.loads(os.environ['PROJECT_CONFIG'])
if not isinstance(projectConfig, dict):
print('Error: PROJECT_CONFIG is not a valid JSON object, aborting.')
sys.exit(1)
if 'tagPrefix' not in projectConfig or 'tagPostfix' not in projectConfig:
print('Error: PROJECT_CONFIG is missing required fields: tagPrefix and/or tagPostfix')
sys.exit(1)
project_name = projectConfig.get('projectName')
if project_name is None:
print('Error: PROJECT_CONFIG is missing required field: projectName')
sys.exit(1)
result = ''
issuem = re.search("(" + project_name + ")-[0-9]+", title, re.IGNORECASE)
Expand All @@ -252,7 +273,7 @@ jobs:
result = 'Jirabot Action Result:\n'
fixVersions = generateFixVersionList(jira, project_name, branch_name)
fixVersions = generateFixVersionList(jira, projectConfig, project_name, branch_name)
result += resolveIssue(jira, project_name, issue, fixVersions)
jira.issue_add_comment(issue_name, result)
Expand Down

0 comments on commit 54202c1

Please sign in to comment.