in dev/merge_pr.py [0:0]
def resolve_jira_issue(merge_branches, comment, default_jira_id=""):
jira_id = input("Enter a JIRA id [%s]: " % default_jira_id)
if jira_id == "":
jira_id = default_jira_id
try:
issue = asf_jira.issue(jira_id)
except Exception as e:
fail("ASF JIRA could not find %s\n%s" % (jira_id, e))
cur_status = issue.fields.status.name
cur_summary = issue.fields.summary
cur_assignee = issue.fields.assignee
if cur_assignee is None:
cur_assignee = choose_jira_assignee(issue)
# Check again, we might not have chosen an assignee
if cur_assignee is None:
cur_assignee = "NOT ASSIGNED!!!"
else:
cur_assignee = cur_assignee.displayName
if cur_status == "Resolved" or cur_status == "Closed":
fail("JIRA issue %s already has status '%s'" % (jira_id, cur_status))
print("=== JIRA %s ===" % jira_id)
print(
"summary\t\t%s\nassignee\t%s\nstatus\t\t%s\nurl\t\t%s/%s\n"
% (cur_summary, cur_assignee, cur_status, JIRA_BASE, jira_id)
)
versions = asf_jira.project_versions("CELEBORN")
# Consider only x.y.z, unreleased, unarchived versions
versions = [
x
for x in versions
if not x.raw["released"] and not x.raw["archived"] and re.match(r"\d+\.\d+\.\d+", x.name)
]
default_fix_versions = []
for b in merge_branches:
if b == "main":
default_fix_versions.append(versions[0].name)
else:
found = False
found_versions = []
for v in versions:
if v.name.startswith(b.replace("branch-", "")):
found_versions.append(v.name)
found = True
if found:
# There might be several unreleased versions for specific branches
# For example, assuming
# versions = ['4.0.0', '3.5.1', '3.5.0', '3.4.2', '3.3.4', '3.3.3']
# we've found two candidates for branch-3.5, we pick the last/smallest one
default_fix_versions.append(found_versions[-1])
else:
print(
"Target version for %s is not found on JIRA, it may be archived or "
"not created. Skipping it." % b
)
for v in default_fix_versions:
# Handles the case where we have forked a release branch but not yet made the release.
# In this case, if the PR is committed to the main branch and the release branch, we
# only consider the release branch to be the fix version. E.g. it is not valid to have
# both 1.1.0 and 1.0.0 as fix versions.
(major, minor, patch) = v.split(".")
if patch == "0":
previous = "%s.%s.%s" % (major, int(minor) - 1, 0)
if previous in default_fix_versions:
default_fix_versions = list(filter(lambda x: x != v, default_fix_versions))
default_fix_versions = ",".join(default_fix_versions)
available_versions = set(list(map(lambda v: v.name, versions)))
while True:
try:
fix_versions = input(
"Enter comma-separated fix version(s) [%s]: " % default_fix_versions
)
if fix_versions == "":
fix_versions = default_fix_versions
fix_versions = fix_versions.replace(" ", "").split(",")
if set(fix_versions).issubset(available_versions):
break
else:
print(
"Specified version(s) [%s] not found in the available versions, try "
"again (or leave blank and fix manually)." % (", ".join(fix_versions))
)
except KeyboardInterrupt:
raise
except BaseException:
traceback.print_exc()
print("Error setting fix version(s), try again (or leave blank and fix manually)")
def get_version_json(version_str):
return list(filter(lambda v: v.name == version_str, versions))[0].raw
jira_fix_versions = list(map(lambda v: get_version_json(v), fix_versions))
resolve = list(filter(lambda a: a["name"] == "Resolve Issue", asf_jira.transitions(jira_id)))[0]
resolution = list(filter(lambda r: r.raw["name"] == "Fixed", asf_jira.resolutions()))[0]
asf_jira.transition_issue(
jira_id,
resolve["id"],
fixVersions=jira_fix_versions,
comment=comment,
resolution={"id": resolution.raw["id"]},
)
print("Successfully resolved %s with fixVersions=%s!" % (jira_id, fix_versions))