|
| 1 | +name: Check for ghstack PRs |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, reopened, synchronize] |
| 6 | + |
| 7 | +jobs: |
| 8 | + check-ghstack: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + permissions: |
| 11 | + pull-requests: write |
| 12 | + steps: |
| 13 | + - name: Check for ghstack usage |
| 14 | + uses: actions/github-script@v7 |
| 15 | + with: |
| 16 | + script: | |
| 17 | + const pr = context.payload.pull_request; |
| 18 | + const headRef = pr.head.ref; |
| 19 | + const prBody = pr.body || ''; |
| 20 | + |
| 21 | + // ghstack branches follow pattern: gh/<username>/<number>/head |
| 22 | + const isGhstack = /^gh\/[^/]+\/\d+\/head$/.test(headRef); |
| 23 | + |
| 24 | + if (!isGhstack) { |
| 25 | + core.info('No ghstack patterns detected. PR is good to go!'); |
| 26 | + return; |
| 27 | + } |
| 28 | + |
| 29 | + core.info('ghstack PR detected'); |
| 30 | + |
| 31 | + // Check if we've already commented |
| 32 | + const { data: comments } = await github.rest.issues.listComments({ |
| 33 | + owner: context.repo.owner, |
| 34 | + repo: context.repo.repo, |
| 35 | + issue_number: pr.number, |
| 36 | + }); |
| 37 | + |
| 38 | + const alreadyCommented = comments.some(c => |
| 39 | + c.user.type === 'Bot' && c.body.includes('ghstack PRs are not supported') |
| 40 | + ); |
| 41 | + |
| 42 | + if (!alreadyCommented) { |
| 43 | + await github.rest.issues.createComment({ |
| 44 | + owner: context.repo.owner, |
| 45 | + repo: context.repo.repo, |
| 46 | + issue_number: pr.number, |
| 47 | + body: `## ⚠️ ghstack PRs are not supported. |
| 48 | + This pull request appears to be created using [ghstack](https://github.com/ezyang/ghstack). |
| 49 | + **We do not support ghstack in this repository.** |
| 50 | +
|
| 51 | + Please resubmit as a regular pull request: |
| 52 | + 1. Create a branch from main |
| 53 | + 2. Cherry-pick or apply your changes |
| 54 | + 3. Open a new pull request |
| 55 | + |
| 56 | + See our [Contributing Guide](https://github.com/pytorch/tutorials/blob/main/CONTRIBUTING.md) for details.`, |
| 57 | + }); |
| 58 | + } |
| 59 | + |
| 60 | + core.setFailed('ghstack PRs are not supported. Please resubmit as a regular pull request.'); |
0 commit comments