This is an automated email from the ASF dual-hosted git repository.

chengpan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-celeborn.git


The following commit(s) were added to refs/heads/main by this push:
     new ad890e938 [CELEBORN-903][INFRA] Fix list index out of range for JIRA 
resolution in merge_pr
ad890e938 is described below

commit ad890e93818de518d4b34b01b7b75e7b7e326c21
Author: Kent Yao <[email protected]>
AuthorDate: Wed Aug 23 18:49:55 2023 +0800

    [CELEBORN-903][INFRA] Fix list index out of range for JIRA resolution in 
merge_pr
    
    ### What changes were proposed in this pull request?
    
    This PR fixes list index out-of-range error for the merge_pr script
    
    The error occurs when the branch we merge into does not have a jira project 
version.
    
    see also 
https://github.com/apache/spark/commit/cb16591f9b7a7a62d4c1797249569b07f6bf2de7
    
    ### Why are the changes needed?
    
    Bugfix
    
    ### Does this PR introduce _any_ user-facing change?
    
    no
    
    ### How was this patch tested?
    
    verification tbd by maintainer, you can checkout this PR and use this 
updated one the merge and test
    
    Closes #1827 from yaooqinn/CELEBORN-903.
    
    Authored-by: Kent Yao <[email protected]>
    Signed-off-by: Cheng Pan <[email protected]>
---
 dev/merge_pr.py | 45 +++++++++++++++++++++++++++++----------------
 1 file changed, 29 insertions(+), 16 deletions(-)

diff --git a/dev/merge_pr.py b/dev/merge_pr.py
index e5b09e136..f1ba4c6f7 100755
--- a/dev/merge_pr.py
+++ b/dev/merge_pr.py
@@ -237,15 +237,6 @@ def cherry_pick(pr_num, merge_hash, default_branch):
     return pick_ref
 
 
-def fix_version_from_branch(branch, versions):
-    # Note: Assumes this is a sorted (newest->oldest) list of un-released 
versions
-    if branch == "main":
-        return versions[0]
-    else:
-        branch_ver = branch.replace("branch-", "")
-        return list(filter(lambda x: x.name.startswith(branch_ver), 
versions))[-1]
-
-
 def resolve_jira_issue(merge_branches, comment, default_jira_id=""):
     asf_jira = jira.client.JIRA(
         {"server": JIRA_API_BASE}, basic_auth=(ASF_USERNAME, ASF_PASSWORD)
@@ -280,14 +271,36 @@ def resolve_jira_issue(merge_branches, comment, 
default_jira_id=""):
     )
 
     versions = asf_jira.project_versions("CELEBORN")
-    versions = sorted(versions, key=lambda x: x.name, reverse=True)
-    versions = list(filter(lambda x: x.raw["released"] is False, versions))
-    # Consider only x.y.z versions
-    versions = list(filter(lambda x: re.match(r"\d+\.\d+\.\d+", x.name), 
versions))
+    # 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
+                )
 
-    default_fix_versions = list(
-        map(lambda x: fix_version_from_branch(x, versions).name, 
merge_branches)
-    )
     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

Reply via email to