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

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


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

commit b24dbc995b7188883974754b5429136ba6527d6b
Author: Kent Yao <y...@apache.org>
AuthorDate: Sat Aug 19 02:03:29 2023 +0800

    [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: Kent Yao <y...@apache.org>
    (cherry picked from commit 8fb799d47bbd5d5ce9db35283d08ab1a31dc37b9)
    Signed-off-by: Kent Yao <y...@apache.org>
---
 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 6d86e918310..94cf3ac262c 100755
--- a/dev/merge_spark_pr.py
+++ b/dev/merge_spark_pr.py
@@ -373,7 +373,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(asf_jira, issue.key, assignee.name)
                 return assignee
         except KeyboardInterrupt:
             raise
@@ -382,6 +382,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