holdenk commented on code in PR #60472:
URL: https://github.com/apache/spark/pull/60472#discussion_r4621008931


##########
dev/merge_spark_pr.py:
##########
@@ -960,25 +1082,104 @@ def comment(self, pr_num, body):
         print("DRY-RUN: would post the following comment on PR #%s:\n%s" % 
(pr_num, body))
         return None
 
+    def create_pr(self, base, head, title, body):
+        # Return a fake PR so the 'p' path takes its success branch in a dry 
run (and the
+        # merge comment logs a backport-PR line rather than the "PR not 
opened" fallback).
+        fake_url = "https://github.com/apache/spark/pull/DRY-RUN";
+        print(
+            "DRY-RUN: would open a draft backport PR against %s from %s:\n  
title: %s\n  body: %s"
+            % (base, head, title, body)
+        )
+        return {"html_url": fake_url, "number": 0}
+
 
 # Set in main(): GitHub() normally, DryRunGitHub() for a dry run. Module-level 
default so the
 # top-level except handler and any early failure path have a usable client.
 github = GitHub()
 
 
 def post_merge_comment(pr_num, merged_commits):
-    """Post a comment on the PR recording every branch the change landed on 
and a
-    link to the resulting commit, so the merge is traceable from the PR page.
+    """Post a comment on the PR recording every branch the change landed on 
(with a
+    commit link) or has a pending backport for, so the merge is traceable from 
the PR page.
+
+    ``merged_commits`` is an ordered list of (branch, marker) pairs, the merge 
sink
+    first followed by each cherry-pick target, markers as in _do_cherry_pick: 
a pushed
+    commit hash, a backport PR URL, or a `fork:<owner>:<branch>` marker.
+
+    >>> from contextlib import redirect_stdout
+    >>> from io import StringIO
+    >>> from unittest.mock import patch
+    >>> captured = {}
+    >>> def fake_comment(num, body):
+    ...     captured["num"] = num
+    ...     captured["body"] = body
+    >>> with (
+    ...     patch.object(github, "comment", side_effect=fake_comment),
+    ...     redirect_stdout(StringIO()),
+    ... ):
+    ...     post_merge_comment(42, [("master", "abc123"), ("branch-4.2", 
"def456")])
+    >>> captured["num"]
+    42
+    >>> "- merged into master https://github.com/apache/spark/commit/abc123"; 
in captured["body"]
+    True
+    >>> "- merged into branch-4.2 
https://github.com/apache/spark/commit/def456"; in captured["body"]
+    True
+
+    A backport-PR marker (a URL) renders as a PR link, not a commit link:
+
+    >>> with (
+    ...     patch.object(github, "comment", side_effect=fake_comment),
+    ...     redirect_stdout(StringIO()),
+    ... ):
+    ...     post_merge_comment(
+    ...         42, [("master", "abc123"), ("branch-4.2", 
"https://github.com/apache/spark/pull/99";)])

Review Comment:
   Yeah we can probably 86 a bunch of the doctests.



-- 
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