Skip to content

Commit

Permalink
Code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmcmu committed Aug 29, 2023
1 parent ac1235c commit eb58834
Showing 1 changed file with 62 additions and 77 deletions.
139 changes: 62 additions & 77 deletions .github/workflows/JirabotMerge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
PULL_URL: ${{ github.event.pull_request.html_url }}
COMMENTS_URL: ${{ github.event.pull_request.comments_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH_NAME: ${{ github.ref_name }}

run: |
import os
Expand All @@ -39,69 +40,22 @@ jobs:
import time
from jira.client import JIRA
def compareVersions(verA, verB) -> int:
aParts = verA.split('.')
bParts = verB.split('.')
if len(aParts) != 3 or len(bParts) != 3:
print('Invalid version comparison: ' + verA + ' <=> ' + verB)
sys.exit(1)
if aParts[2].lower() == 'x':
aParts[2] = 10000
if bParts[2].lower() == 'x':
bParts[2] = 10000
aMajor, aMinor, aPoint = map(int, aParts)
bMajor, bMinor, bPoint = map(int, bParts)
if aMajor < bMajor:
return -1
elif aMajor > bMajor:
return 1
if aMinor < bMinor:
return -1
elif aMinor > bMinor:
return 1
if aPoint < bPoint:
return -1
elif aPoint > bPoint:
return 1
return 0
def findLatestMinorForMajor(majorVer, versions) -> str:
latestMinor = 0
latestPoint = 0
latestVer = None
for v in versions:
parts = v.name.split('.')
if len(parts) != 3:
continue
if int(parts[0]) != majorVer:
continue
if int(parts[1]) >= latestMinor and (parts[2].lower() == 'x' or int(parts[2]) > latestPoint):
latestVer = v.name
latestMinor = int(parts[1])
if parts[2].lower() != 'x':
latestPoint = int(parts[2])
return latestVer
def incrementPointVersion(version) -> str:
parts = version.split('.')
def extractVersion(versionStr):
parts = versionStr.split('.')
if len(parts) != 3:
print('Invalid version: ' + version)
sys.exit(1)
if parts[2].lower() == 'x':
parts[2] = '0'
major, minor, point = map(int, parts)
incPoint = point + 2
return f"{major}.{minor}.{incPoint}"
return [major, minor, point]
def generateFixVersionList(jira):
gitTagProcess = subprocess.Popen('git describe --tags `git rev-list --tags --max-count=1`', stdout=subprocess.PIPE, shell=True)
def getTagVersionForCmd(cmd):
versionPattern = re.compile(r".*([0-9]+\.[0-9]+\.[0-9]+).*")
# Get latest release version
gitTagProcess = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
(output, err) = gitTagProcess.communicate()
gitTagProcessStatus = gitTagProcess.wait()
Expand All @@ -110,36 +64,62 @@ jobs:
sys.exit(1)
latestGitTag = str(output)
tagVersionIsRelease = "-release" in latestGitTag
versionPattern = re.compile(r".*([0-9]+\.[0-9]+\.[0-9]+).*")
versionMatch = versionPattern.match(latestGitTag)
if versionMatch:
tagVersion = versionMatch.group(1)
return extractVersion(versionMatch.group(1))
else:
print('Unable to extract version from git tag.')
sys.exit(2)
fixVersion = tagVersion
if tagVersionIsRelease:
fixVersion = incrementPointVersion(fixVersion)
def buildVersionString(version):
major, minor, point = map(int, version)
return f"{major}.{minor}.{point}"
alreadyHasFixVersion = False
versions = jira.project_versions('JAPI')
for v in versions:
if v.name == fixVersion:
alreadyHasFixVersion = True
def generateFixVersionList(jira, branchName):
latestVersion = getTagVersionForCmd("git tag --list 'hpcc4j_*-release' --sort=-v:refname | head -n 1")
# If we are merging into master we assume it is going into the next minor release
fixVersions = []
if branchName == "master":
fixVersions = [buildVersionString([latestVersion[0], latestVersion[1] + 2, 0])]
else:
# Extract candidate branch major / minor version
candidateBranchPattern = re.compile(r"candidate-([0-9]+\.[0-9]+\.([0-9]+|x)).*")
branchVersionMatch = candidateBranchPattern.match(branchName)
branchVersion = extractVersion(branchVersionMatch.group(1))
if not alreadyHasFixVersion:
jira.create_version(name=fixVersion, project='JAPI', description=fixVersion)
# Get latest release in branch
findLatestBranchVer = "git tag --list 'hpcc4j_" + str(branchVersion[0]) + "." + str(branchVersion[1]) + "*-release' --sort=-v:refname | head -n 1"
latestBranchVer = getTagVersionForCmd(findLatestBranchVer)
parts = fixVersion.split('.')
majorVer = int(parts[0])
fixVersions = [fixVersion]
curMajor = branchVersion[0]
latestMajor = latestVersion[0]
while curMajor <= latestMajor:
latestVersionInMajor = getTagVersionForCmd("git tag --list 'hpcc4j_" + str(curMajor) + "*-release' --sort=-v:refname | head -n 1")
latestMinor = findLatestMinorForMajor(majorVer, versions)
if latestMinor != None and compareVersions(fixVersion, latestMinor) < 0:
fixVersions.append(latestMinor)
curMinor = 0
if curMajor == branchVersion[0]:
curMinor = branchVersion[1]
latestMinor = latestVersionInMajor[1]
while curMinor <= latestMinor:
latestPointInMinor = getTagVersionForCmd("git tag --list 'hpcc4j_" + str(curMajor) + "." + str(curMinor) + "*-release' --sort=-v:refname | head -n 1")
fixVersions.append(buildVersionString([latestPointInMinor[0], latestPointInMinor[1], latestPointInMinor[2] + 2]))
curMinor += 2
curMajor += 1
for fixVersion in fixVersions:
alreadyHasFixVersion = False
versions = jira.project_versions('JAPI')
for v in versions:
if v.name == fixVersion:
alreadyHasFixVersion = True
if not alreadyHasFixVersion:
jira.create_version(name=fixVersion, project='JAPI', description=fixVersion)
return fixVersions
Expand Down Expand Up @@ -196,6 +176,7 @@ jobs:
user = os.environ['PULL_REQUEST_AUTHOR_NAME']
pull_url = os.environ['PULL_URL']
github_token = os.environ['GITHUB_TOKEN']
branch_name = os.environ['BRANCH_NAME']
print("%s %s %s" % (title, user, comments_url))
result = ''
Expand All @@ -204,6 +185,10 @@ jobs:
nameCorrectionPattern = re.compile("hpcc4j", re.IGNORECASE)
issue_name = nameCorrectionPattern.sub("JAPI",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:
Expand All @@ -212,7 +197,7 @@ jobs:
result = 'Jirabot Action Result:\n'
fixVersions = generateFixVersionList(jira)
fixVersions = generateFixVersionList(jira, branch_name)
result += resolveIssue(jira, issue, fixVersions)
jira.add_comment(issue, result)
else:
Expand Down

0 comments on commit eb58834

Please sign in to comment.