gengliangwang commented on code in PR #60371:
URL: https://github.com/apache/spark/pull/60371#discussion_r4557884552
##########
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:
Done in d94fb437ebd7: Each re-read now checks the PR's `state`. If a re-read
finds the PR closed, it counts as not mergeable and the loop stops, so we no
longer report that GitHub is still checking. The doctest stub returns a `state`
with each re-read now, and I added doctests for a re-read that finds the PR
closed with null and with true.
##########
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:
Done in d94fb437ebd7: The description of `pr` in the docstring summary is
now in parentheses, so the line no longer reads as listing three possible
results.
--
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]