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

yao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new da5aa706147c [SPARK-45779][INFRA] Add a check step for jira issue 
ticket to be resolved
da5aa706147c is described below

commit da5aa706147c6a462a8470f8fdf2c3cd17fede01
Author: Kent Yao <y...@apache.org>
AuthorDate: Sat Nov 4 01:10:30 2023 +0800

    [SPARK-45779][INFRA] Add a check step for jira issue ticket to be resolved
    
    ### What changes were proposed in this pull request?
    
    This PR moves the step for printing the summary of the Jira issue and adds 
a confirmation step for committers before assigning it to a user.
    
    Also, we show the final status of the Jira issue after resolution.
    
    ### Why are the changes needed?
    
    The JIRA ID mentioned in the PR title can sometimes be incorrect due to 
carelessness. Double-checking the ID is necessary to ensure that it is 
accurate. It is now too late for the committers to modify the ID once they have 
seen the ticket summary.
    
    ### Does this PR introduce _any_ user-facing change?
    
    no
    
    ### How was this patch tested?
    
    Tested with SPARK-45776.
    
    Note that the message below may seem noisy because I declined the merge 
script at first.
    
    ```
    Would you like to update an associated JIRA? (y/n): y
    Enter a JIRA id[SPARK-45776]:
    === JIRA SPARK-45776 ===
    summary         Remove the defensive null check added in SPARK-39553.
    assignee        None
    status          Open
    url             https://issues.apache.org/jira/browse/SPARK-45776
    
    Check if the JIRA information is as expected(y/n): n
    Enter the revised JIRA ID again or leave blank to skip[]: SPARK-45776
    === JIRA SPARK-45776 ===
    summary         Remove the defensive null check added in SPARK-39553.
    assignee        None
    status          Open
    url             https://issues.apache.org/jira/browse/SPARK-45776
    
    Check if the JIRA information is as expected(y/n): y
    JIRA is unassigned, choose assignee
    [0] Yang Jie (Reporter)
    Enter number of user, or userid, to assign to (blank to leave unassigned):0
    Enter comma-separated fix version(s) [4.0.0]:
    === JIRA SPARK-45776 ===
    summary         Remove the defensive null check added in SPARK-39553.
    assignee        Yang Jie
    status          RESOLVED
    url             https://issues.apache.org/jira/browse/SPARK-45776
    
    Successfully resolved SPARK-45776 with fixVersions=['4.0.0']!
    Enter a JIRA id[SPARK-39553]:
    ```
    ### Was this patch authored or co-authored using generative AI tooling?
    
    no
    
    Closes #43648 from yaooqinn/SPARK-45779.
    
    Authored-by: Kent Yao <y...@apache.org>
    Signed-off-by: Kent Yao <y...@apache.org>
---
 dev/merge_spark_pr.py | 70 ++++++++++++++++++++++++++++++++-------------------
 1 file changed, 44 insertions(+), 26 deletions(-)

diff --git a/dev/merge_spark_pr.py b/dev/merge_spark_pr.py
index 643bc37ced19..59cb02738979 100755
--- a/dev/merge_spark_pr.py
+++ b/dev/merge_spark_pr.py
@@ -248,37 +248,49 @@ def cherry_pick(pr_num, merge_hash, default_branch):
     return pick_ref
 
 
-def resolve_jira_issue(merge_branches, comment, default_jira_id=""):
-    jira_id = input("Enter a JIRA id [%s]: " % default_jira_id)
+def print_jira_issue_summary(issue):
+    summary = issue.fields.summary
+    assignee = issue.fields.assignee
+    if assignee is not None:
+        assignee = assignee.displayName
+    status = issue.fields.status.name
+    print("=== JIRA %s ===" % issue.key)
+    print(
+        "summary\t\t%s\nassignee\t%s\nstatus\t\t%s\nurl\t\t%s/%s\n"
+        % (summary, assignee, status, JIRA_BASE, issue.key)
+    )
+
+
+def get_jira_issue(prompt, default_jira_id=""):
+    jira_id = input("%s[%s]: " % (prompt, default_jira_id))
     if jira_id == "":
         jira_id = default_jira_id
         if jira_id == "":
             print("JIRA ID not found, skipping.")
-            return
-
+            return None
     try:
         issue = asf_jira.issue(jira_id)
+        print_jira_issue_summary(issue)
+        status = issue.fields.status.name
+        if status == "Resolved" or status == "Closed":
+            print("JIRA issue %s already has status '%s'" % (jira_id, status))
+            return None
+        if input("Check if the JIRA information is as expected(y/n): 
").lower() != "n":
+            return issue
+        else:
+            return get_jira_issue("Enter the revised JIRA ID again or leave 
blank to skip")
     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
+        print("ASF JIRA could not find %s: %s" % (jira_id, e))
+        return get_jira_issue("Enter the revised JIRA ID again or leave blank 
to skip")
 
-    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)
-    )
+
+def resolve_jira_issue(merge_branches, comment, default_jira_id=""):
+    issue = get_jira_issue("Enter a JIRA id", default_jira_id)
+    if issue is None:
+        return
+
+    if issue.fields.assignee is None:
+        choose_jira_assignee(issue)
 
     versions = asf_jira.project_versions("SPARK")
     # Consider only x.y.z, unreleased, unarchived versions
@@ -351,17 +363,23 @@ def resolve_jira_issue(merge_branches, comment, 
default_jira_id=""):
 
     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]
+    resolve = list(filter(lambda a: a["name"] == "Resolve Issue", 
asf_jira.transitions(issue.key)))[
+        0
+    ]
     resolution = list(filter(lambda r: r.raw["name"] == "Fixed", 
asf_jira.resolutions()))[0]
     asf_jira.transition_issue(
-        jira_id,
+        issue.key,
         resolve["id"],
         fixVersions=jira_fix_versions,
         comment=comment,
         resolution={"id": resolution.raw["id"]},
     )
 
-    print("Successfully resolved %s with fixVersions=%s!" % (jira_id, 
fix_versions))
+    try:
+        print_jira_issue_summary(asf_jira.issue(issue.key))
+    except Exception:
+        print("Unable to fetch JIRA issue %s after resolving" % issue.key)
+    print("Successfully resolved %s with fixVersions=%s!" % (issue.key, 
fix_versions))
 
 
 def choose_jira_assignee(issue):


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org

Reply via email to