spark-test commented on code in PR #60371:
URL: https://github.com/apache/spark/pull/60371#discussion_r4556020366


##########
dev/merge_spark_pr.py:
##########
@@ -692,6 +697,70 @@ def get_json_pages(url):
     return items
 
 
+def mergeable_warning(pr_num, pr):
+    """Return the warning to confirm before merging `pr`, the PR as read from 
GitHub, or None.

Review Comment:
   **Nit (P3):** With the serial comma, this sentence reads as "return A, B, or 
C", so "the PR as read from GitHub" looks like a second possible result rather 
than a description of `pr`. Because the function does read the PR from GitHub 
again, that reading is plausible, although it only ever returns a warning 
string or None. Putting the description in parentheses keeps it out of the list:
   
   ```suggestion
       """Return the warning to confirm before merging `pr` (the PR as read 
from GitHub), or None.
   ```
   
   **Verification:**
   - **Inspection:** The summary line of the mergeable_warning docstring reads 
as returning either a warning to confirm or None, with the description of `pr` 
outside the list of results.



##########
dev/merge_spark_pr.py:
##########
@@ -692,6 +697,70 @@ def get_json_pages(url):
     return items
 
 
+def mergeable_warning(pr_num, pr):
+    """Return the warning to confirm before merging `pr`, the PR as read from 
GitHub, or None.
+
+    GitHub computes whether an open PR is mergeable in a background job, and 
reports
+    `mergeable` as null until the job is done, e.g. right after a push to the 
PR or to its base
+    branch. Taking that null for a conflict, this script warned that #59961 
was not mergeable
+    right after a push to master, though GitHub reported it as mergeable a 
little later. So an
+    open PR that reads as null is read again, up to MERGEABLE_RETRIES times,
+    MERGEABLE_RETRY_SECONDS apart. GitHub does not compute it for a closed PR, 
which always
+    reads as null, so a closed PR is not read again.
+
+    >>> from unittest.mock import patch
+    >>> def warning(state, *mergeables):
+    ...     # Read the PR with the first of `mergeables`, and serve the rest 
to the re-reads.
+    ...     rereads = iter(mergeables[1:])
+    ...     def get_json(url):
+    ...         assert url == GITHUB_API_BASE + "/pulls/1", url
+    ...         return {"mergeable": next(rereads)}
+    ...     pr = {"state": state, "mergeable": mergeables[0]}
+    ...     with (
+    ...         patch.dict(mergeable_warning.__globals__, get_json=get_json),
+    ...         patch("time.sleep") as sleep,
+    ...     ):
+    ...         return mergeable_warning("1", pr), sleep.call_count
+
+    A PR that GitHub has checked is not read again:
+
+    >>> warning("open", True)
+    (None, 0)
+    >>> warning("open", False)
+    ('Pull request 1 is not mergeable in its current form.', 0)
+
+    An open PR that reads as null is read again until GitHub has checked it, 
up to five times:
+
+    >>> warning("open", None, None, True)
+    Waiting for GitHub to check whether pull request 1 is mergeable...
+    (None, 2)
+    >>> warning("open", None, False)
+    Waiting for GitHub to check whether pull request 1 is mergeable...
+    ('Pull request 1 is not mergeable in its current form.', 1)
+    >>> warning("open", *[None] * 6)
+    Waiting for GitHub to check whether pull request 1 is mergeable...
+    ('GitHub is still checking whether pull request 1 is mergeable.', 5)
+
+    A closed PR is not read again:
+
+    >>> warning("closed", None)
+    ('Pull request 1 is not mergeable in its current form.', 0)
+    """
+    mergeable = pr["mergeable"]
+    if mergeable is None and pr["state"] == "open":
+        print("Waiting for GitHub to check whether pull request %s is 
mergeable..." % pr_num)
+        for _ in range(MERGEABLE_RETRIES):
+            time.sleep(MERGEABLE_RETRY_SECONDS)
+            mergeable = get_json("%s/pulls/%s" % (GITHUB_API_BASE, 
pr_num))["mergeable"]

Review Comment:
   **Nit (P3):** `main()` reads the PR at line 3333 and may then wait on the 
modified-body prompt, but this loop keeps only `["mergeable"]` from each 
re-read and never looks at the fresh `state`. If the PR is closed after that 
read, before or during the wait, for example by another committer's merge or by 
its author, each re-read returns a closed PR with `mergeable: null`. The 
docstring notes that GitHub never computes that for a closed PR, yet the loop 
keeps waiting and then tells the committer that GitHub is still checking a PR 
that is in fact closed, possibly already merged.
   
   In a repro of this helper with stubbed reads, an open PR first read as null 
whose re-reads report it closed with `mergeable: null` got five re-reads, five 
2-second sleeps, and "GitHub is still checking whether pull request 1 is 
mergeable." With the PR already closed at the first read, the helper returns 
"Pull request 1 is not mergeable in its current form." without re-reading, and 
the base branch shows that warning at once for an open PR read as null. A 
closed re-read carrying `true` got no warning at all.
   
   Taking `state` from each re-read and returning the not-mergeable warning as 
soon as a re-read reports the PR closed would fix this. The re-read stub in the 
doctest (line 717) would then need to return a `state` with each re-read, 
because the script runs its doctests every time it starts and exits if one 
fails.
   
   **Verification:**
   - **Regression:** An open PR first read with mergeable null whose first 
re-read reports it closed with mergeable null gets the not-mergeable warning 
after one re-read and one sleep, where the current code makes five re-reads and 
returns the still-checking warning.
   - **Regression:** An open PR first read with mergeable null whose re-read 
reports it closed with mergeable true gets the not-mergeable warning rather 
than no warning.
   - **Behavior:** With re-reads that report the PR open, the existing outcomes 
keep their warnings and sleep counts: there is no re-read for a first read of 
true or false or of a closed PR, re-reads stop at true or at false, and five 
null re-reads end in the still-checking warning.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to