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

srowen pushed a commit to branch branch-3.4
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/branch-3.4 by this push:
     new 3c5e57d886b [SPARK-44813][INFRA] The Jira Python misses our assignee 
when it searches users again
3c5e57d886b is described below

commit 3c5e57d886b81808370353781bfce2b2ce20a473
Author: Kent Yao <y...@apache.org>
AuthorDate: Fri Aug 18 10:02:43 2023 -0500

    [SPARK-44813][INFRA] The Jira Python misses our assignee when it searches 
users again
    
    ### What changes were proposed in this pull request?
    
    This PR creates an alternative to the assign_issue function in 
jira.client.JIRA.
    
    The original one has an issue that it will search users again and only 
choose the assignee from 20 candidates. If it's unmatched, it picks the head 
blindly.
    
    For example,
    
    ```python
    >>> assignee = asf_jira.user("yao")
    >>> "SPARK-44801"
    'SPARK-44801'
    >>> asf_jira.assign_issue(issue.key, assignee.name)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'issue' is not defined
    >>> asf_jira.assign_issue("SPARK-44801", assignee.name)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File 
"/Users/hzyaoqin/python/lib/python3.11/site-packages/jira/client.py", line 123, 
in wrapper
        result = func(*arg_list, **kwargs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
      File 
"/Users/hzyaoqin/python/lib/python3.11/site-packages/jira/client.py", line 
1891, in assign_issue
        self._session.put(url, data=json.dumps(payload))
      File 
"/Users/hzyaoqin/python/lib/python3.11/site-packages/requests/sessions.py", 
line 649, in put
        return self.request("PUT", url, data=data, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File 
"/Users/hzyaoqin/python/lib/python3.11/site-packages/jira/resilientsession.py", 
line 246, in request
        elif raise_on_error(response, **processed_kwargs):
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File 
"/Users/hzyaoqin/python/lib/python3.11/site-packages/jira/resilientsession.py", 
line 71, in raise_on_error
        raise JIRAError(
    jira.exceptions.JIRAError: JiraError HTTP 400 url: 
https://issues.apache.org/jira/rest/api/latest/issue/SPARK-44801/assignee
            response text = {"errorMessages":[],"errors":{"assignee":"User 
'airhot' cannot be assigned issues."}}
    ```
    
    The Jira userid 'yao' fails to return my JIRA profile as a candidate(20 in 
total) to match. So, 'airhot' from the head replaces me as an assignee.
    
    ### Why are the changes needed?
    
    bugfix for merge_spark_pr
    
    ### Does this PR introduce _any_ user-facing change?
    
    no
    
    ### How was this patch tested?
    
    test locally
    
    ```python
    >>> def assign_issue(client: jira.client.JIRA, issue: int, assignee: str) 
-> bool:
    ...     """Assign an issue to a user.
    ...
    ...     Args:
    ...         issue (Union[int, str]): the issue ID or key to assign
    ...         assignee (str): the user to assign the issue to. None will set 
it to unassigned. -1 will set it to Automatic.
    ...
    ...     Returns:
    ...         bool
    ...     """
    ...     url = getattr(client, "_get_latest_url")(f"issue/{issue}/assignee")
    ...     payload = {"name": assignee}
    ...     getattr(client, "_session").put(url, data=json.dumps(payload))
    ...     return True
    ...
    
    >>>
    >>> assign_issue(asf_jira, "SPARK-44801", "yao")
    True
    ```
    
    Closes #42496 from yaooqinn/SPARK-44813.
    
    Authored-by: Kent Yao <y...@apache.org>
    Signed-off-by: Sean Owen <sro...@gmail.com>
    (cherry picked from commit 00255bc63b1a3bbe80bedc639b88d4a8e3f88f72)
    Signed-off-by: Sean Owen <sro...@gmail.com>
---
 dev/merge_spark_pr.py | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/dev/merge_spark_pr.py b/dev/merge_spark_pr.py
index 1621432c01c..8a5b6ebe8ef 100755
--- a/dev/merge_spark_pr.py
+++ b/dev/merge_spark_pr.py
@@ -372,7 +372,7 @@ def choose_jira_assignee(issue, asf_jira):
                 except BaseException:
                     # assume it's a user id, and try to assign (might fail, we 
just prompt again)
                     assignee = asf_jira.user(raw_assignee)
-                asf_jira.assign_issue(issue.key, assignee.name)
+                assign_issue(issue.key, assignee.name)
                 return assignee
         except KeyboardInterrupt:
             raise
@@ -381,6 +381,19 @@ def choose_jira_assignee(issue, asf_jira):
             print("Error assigning JIRA, try again (or leave blank and fix 
manually)")
 
 
+def assign_issue(client: jira.client.JIRA, issue: int, assignee: str) -> bool:
+    """
+    Assign an issue to a user, which is a shorthand for 
jira.client.JIRA.assign_issue.
+    The original one has an issue that it will search users again and only 
choose the assignee
+    from 20 candidates. If it's unmatched, it picks the head blindly. In our 
case, the assignee
+    is already resolved.
+    """
+    url = getattr(client, "_get_latest_url")(f"issue/{issue}/assignee")
+    payload = {"name": assignee}
+    getattr(client, "_session").put(url, data=json.dumps(payload))
+    return True
+
+
 def resolve_jira_issues(title, merge_branches, comment):
     jira_ids = re.findall("SPARK-[0-9]{4,5}", title)
 


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

Reply via email to