From 785ea2b795a1ea221515c729087b2fd685c3d602 Mon Sep 17 00:00:00 2001 From: Svetlana Karslioglu Date: Wed, 21 Jan 2026 14:43:50 -0800 Subject: [PATCH 1/2] Add ghstack PR detection and error message Updated ghstack detection logic and modified the comment body for clarity. --- .github/workflows/is-gh-stack.yml | 60 +++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 .github/workflows/is-gh-stack.yml diff --git a/.github/workflows/is-gh-stack.yml b/.github/workflows/is-gh-stack.yml new file mode 100644 index 0000000000..e32488abdf --- /dev/null +++ b/.github/workflows/is-gh-stack.yml @@ -0,0 +1,60 @@ +name: Check for ghstack PRs + +on: + pull_request: + types: [opened, reopened, synchronize] + +jobs: + check-ghstack: + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - name: Check for ghstack usage + uses: actions/github-script@v7 + with: + script: | + const pr = context.payload.pull_request; + const headRef = pr.head.ref; + const prBody = pr.body || ''; + + // ghstack branches follow pattern: gh///head + const isGhstack = /^gh\/[^/]+\/\d+\/head$/.test(headRef); + + if (!isGhstack) { + core.info('No ghstack patterns detected. PR is good to go!'); + return; + } + + core.info('ghstack PR detected'); + + // Check if we've already commented + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pr.number, + }); + + const alreadyCommented = comments.some(c => + c.user.type === 'Bot' && c.body.includes('ghstack PRs are not supported') + ); + + if (!alreadyCommented) { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pr.number, + body: `## ⚠️ ghstack PRs are not supported. + This pull request appears to be created using [ghstack](https://github.com/ezyang/ghstack). + **We do not support ghstack in this repository.** + + Please resubmit as a regular pull request: + 1. Create a branch from main + 2. Cherry-pick or apply your changes + 3. Open a new pull request + + See our [Contributing Guide](https://github.com/pytorch/tutorials/blob/main/CONTRIBUTING.md) for details.`, + }); + } + + core.setFailed('ghstack PRs are not supported. Please resubmit as a regular pull request.'); From 54da101ae86063aafaf094de8a44ca517fd22c33 Mon Sep 17 00:00:00 2001 From: Svetlana Karslioglu Date: Wed, 21 Jan 2026 15:20:47 -0800 Subject: [PATCH 2/2] Fix lint --- .github/workflows/is-gh-stack.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/is-gh-stack.yml b/.github/workflows/is-gh-stack.yml index e32488abdf..d1ab173e73 100644 --- a/.github/workflows/is-gh-stack.yml +++ b/.github/workflows/is-gh-stack.yml @@ -17,28 +17,28 @@ jobs: const pr = context.payload.pull_request; const headRef = pr.head.ref; const prBody = pr.body || ''; - + // ghstack branches follow pattern: gh///head const isGhstack = /^gh\/[^/]+\/\d+\/head$/.test(headRef); - + if (!isGhstack) { core.info('No ghstack patterns detected. PR is good to go!'); return; } - + core.info('ghstack PR detected'); - + // Check if we've already commented const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: pr.number, }); - - const alreadyCommented = comments.some(c => + + const alreadyCommented = comments.some(c => c.user.type === 'Bot' && c.body.includes('ghstack PRs are not supported') ); - + if (!alreadyCommented) { await github.rest.issues.createComment({ owner: context.repo.owner, @@ -52,9 +52,9 @@ jobs: 1. Create a branch from main 2. Cherry-pick or apply your changes 3. Open a new pull request - + See our [Contributing Guide](https://github.com/pytorch/tutorials/blob/main/CONTRIBUTING.md) for details.`, }); } - + core.setFailed('ghstack PRs are not supported. Please resubmit as a regular pull request.');