Skip to content

Commit 42b33c0

Browse files
authored
Add Differential Revision to PRs created by pytorchbot (#14476)
Test Plan: Ran ``` python .github/scripts/propose_ghstack_orig_pr.py --repo pytorch/executorch --ref 14368 ``` and print out `bot_metadata` variable. Here's the output: https://gist.github.com/mergennachin/8a5b44fded2f584fe7453ecd4e24b69c Also tested via ghexport via internal phabricator. It eventually produced this PR: #14481
1 parent 99e4fbe commit 42b33c0

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

.github/scripts/propose_ghstack_orig_pr.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@ def get_pr_stack_from_number(ref: str, repo: Repository) -> List[int]:
8686
return pr_stack
8787

8888

89+
def get_differential_revision(pr, repo: Repository) -> str:
90+
body = repo.get_pull(pr.number).body
91+
matches = re.findall(r"Differential Revision: .*", body)
92+
count = len(matches)
93+
if count == 1:
94+
# If there's more than one Differential Revision, let's just return empty
95+
# so that we can disambiguate manually.
96+
return matches[0]
97+
return ""
98+
99+
89100
def create_prs_for_orig_branch(pr_stack: List[int], repo: Repository):
90101
# For the first PR, we want to merge to `main` branch, and we will update
91102
# as we go through the stack
@@ -100,13 +111,15 @@ def create_prs_for_orig_branch(pr_stack: List[int], repo: Repository):
100111
# The PR we want to create is then "branch_to_merge" <- gh/user/x/orig
101112
# gh/user/x/orig is the clean diff between gh/user/x/base <- gh/user/x/head
102113
orig_branch_merge_head = pr.base.ref.replace("base", "orig")
114+
differential_revision_text = get_differential_revision(pr, repo)
103115
bot_metadata = f"""This PR was created by the merge bot to help merge the original PR into the main branch.
104116
ghstack PR number: https://github.com/pytorch/executorch/pull/{pr.number} by @{pr.user.login}
105117
^ Please use this as the source of truth for the PR details, comments, and reviews
106118
ghstack PR base: https://github.com/pytorch/executorch/tree/{pr.base.ref}
107119
ghstack PR head: https://github.com/pytorch/executorch/tree/{pr.head.ref}
108120
Merge bot PR base: https://github.com/pytorch/executorch/tree/{orig_branch_merge_base}
109121
Merge bot PR head: https://github.com/pytorch/executorch/tree/{orig_branch_merge_head}
122+
{differential_revision_text}
110123
@diff-train-skip-merge"""
111124

112125
existing_orig_pr = repo.get_pulls(

0 commit comments

Comments
 (0)