Skip to content

Commit caea6dd

Browse files
committed
Update
[ghstack-poisoned]
2 parents 1c66ae4 + 8c96805 commit caea6dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+4642
-205
lines changed

.github/scripts/propose_ghstack_orig_pr.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ def parse_args():
2626
required=True,
2727
)
2828
parser.add_argument(
29-
"--pr",
30-
type=int,
31-
help="Number of the PR in the stack to check and create corresponding PR",
29+
"--ref",
30+
type=str,
31+
help="Ref fo PR in the stack to check and create corresponding PR",
3232
required=True,
3333
)
3434
return parser.parse_args()
@@ -68,12 +68,18 @@ def extract_stack_from_body(pr_body: str) -> List[int]:
6868
return list(reversed(prs))
6969

7070

71-
def get_pr_stack_from_number(pr_number: int, repo: Repository) -> List[int]:
71+
def get_pr_stack_from_number(ref: str, repo: Repository) -> List[int]:
72+
if ref.isnumeric():
73+
pr_number = int(ref)
74+
else:
75+
branch_name = ref.replace("refs/heads/", "")
76+
pr_number = repo.get_branch(branch_name).commit.get_pulls()[0].number
77+
7278
pr_stack = extract_stack_from_body(repo.get_pull(pr_number).body)
7379

7480
if not pr_stack:
7581
raise Exception(
76-
f"Could not find PR stack in body of #{pr_number}. "
82+
f"Could not find PR stack in body of ref. "
7783
+ "Please make sure that the PR was created with ghstack."
7884
)
7985

@@ -100,14 +106,15 @@ def create_prs_for_orig_branch(pr_stack: List[int], repo: Repository):
100106
ghstack PR base: https://github.com/pytorch/executorch/tree/{pr.base.ref}
101107
ghstack PR head: https://github.com/pytorch/executorch/tree/{pr.head.ref}
102108
Merge bot PR base: https://github.com/pytorch/executorch/tree/{orig_branch_merge_base}
103-
Merge bot PR head: https://github.com/pytorch/executorch/tree/{orig_branch_merge_head}"""
109+
Merge bot PR head: https://github.com/pytorch/executorch/tree/{orig_branch_merge_head}
110+
@diff-train-skip-merge"""
104111

105112
existing_orig_pr = repo.get_pulls(
106113
head="pytorch:" + orig_branch_merge_head,
107114
base=orig_branch_merge_base,
108-
state="open",
115+
state="all",
109116
)
110-
if existing_orig_pr.totalCount > 0:
117+
if existing_orig_pr.totalCount > 0 and existing_orig_pr[0].title == pr.title:
111118
print(
112119
f"PR for {orig_branch_merge_head} already exists {existing_orig_pr[0]}"
113120
)
@@ -128,7 +135,7 @@ def main():
128135

129136
with Github(auth=Auth.Token(os.environ["GITHUB_TOKEN"])) as gh:
130137
repo = gh.get_repo(args.repo)
131-
create_prs_for_orig_branch(get_pr_stack_from_number(args.pr, repo), repo)
138+
create_prs_for_orig_branch(get_pr_stack_from_number(args.ref, repo), repo)
132139

133140

134141
if __name__ == "__main__":

.github/workflows/ghstack_land.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ jobs:
3232
run: |
3333
pip install pygithub
3434
35-
PR_NUMBER=$(echo "$GITHUB_REF" | grep -oE '[0-9]+')
36-
37-
python .github/scripts/propose_ghstack_orig_pr.py --pr $PR_NUMBER --repo pytorch/executorch
35+
python .github/scripts/propose_ghstack_orig_pr.py --ref $GITHUB_REF --repo pytorch/executorch
3836
env:
3937
GITHUB_TOKEN: ${{ secrets.GH_PYTORCHBOT_CHERRY_PICK_TOKEN }}
4038
GITHUB_REF: ${{ github.ref }}

0 commit comments

Comments
 (0)