From 54202c14ef5ed5a10004a4ff68ffe9da479244b5 Mon Sep 17 00:00:00 2001 From: James McMullan Date: Tue, 10 Sep 2024 07:59:26 -0400 Subject: [PATCH] Code review changes --- .github/workflows/JirabotMerge.yml | 45 ++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/.github/workflows/JirabotMerge.yml b/.github/workflows/JirabotMerge.yml index 855bdb5a8..1aab53288 100644 --- a/.github/workflows/JirabotMerge.yml +++ b/.github/workflows/JirabotMerge.yml @@ -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 }} @@ -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: @@ -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 = [] @@ -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]: @@ -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 @@ -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) @@ -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)