|
1 | 1 | name: Warn Master Branch PR |
2 | 2 |
|
3 | 3 | on: |
4 | | - pull_request: |
| 4 | + pull_request_target: |
5 | 5 | types: [opened, reopened, synchronize] |
6 | 6 |
|
7 | 7 | jobs: |
8 | 8 | warn-master-branch-pr: |
9 | 9 | name: Warn about PR targeting master branch |
10 | | - if: github.event.pull_request.base.ref == 'master' |
11 | 10 | runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + issues: write |
| 13 | + pull-requests: write |
12 | 14 | steps: |
| 15 | + - name: Debug PR info |
| 16 | + uses: actions/github-script@v6 |
| 17 | + with: |
| 18 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 19 | + script: | |
| 20 | + console.log('=== PR DEBUG INFO ==='); |
| 21 | + console.log('Base ref:', context.payload.pull_request.base.ref); |
| 22 | + console.log('Head ref:', context.payload.pull_request.head.ref); |
| 23 | + console.log('Base repo:', context.payload.pull_request.base.repo.full_name); |
| 24 | + console.log('Head repo:', context.payload.pull_request.head.repo?.full_name); |
| 25 | + console.log('PR author:', context.payload.pull_request.user.login); |
| 26 | + console.log('PR number:', context.payload.pull_request.number); |
| 27 | + console.log('=== END DEBUG ==='); |
| 28 | + |
13 | 29 | - name: Add warning comment |
| 30 | + if: github.event.pull_request.base.ref == 'master' |
14 | 31 | uses: actions/github-script@v6 |
15 | 32 | with: |
16 | 33 | github-token: ${{ secrets.GITHUB_TOKEN }} |
17 | 34 | script: | |
18 | 35 | const { repo, owner } = context.repo; |
19 | | - const issue_number = context.issue.number; |
| 36 | + const issue_number = context.payload.pull_request.number; |
20 | 37 | |
21 | 38 | // Skip if the PR author is github-actions[bot] (automated PR) |
22 | 39 | const prAuthor = context.payload.pull_request.user.login; |
|
25 | 42 | return; |
26 | 43 | } |
27 | 44 | |
28 | | - // Check if we already commented on this PR |
| 45 | + console.log(`Processing PR #${issue_number} from ${prAuthor}`); |
| 46 | + |
| 47 | + // Check if we already commented |
29 | 48 | const comments = await github.rest.issues.listComments({ |
30 | 49 | owner, |
31 | 50 | repo, |
|
42 | 61 | owner, |
43 | 62 | repo, |
44 | 63 | issue_number, |
45 | | - body: "⚠️ **Warning: PR targeting master branch detected!**\n\n**This PR is targeting `master` but should target `dev` instead.**\n\nAccording to our [CONTRIBUTING.md](https://github.com/HyDE-Project/HyDE/blob/master/CONTRIBUTING.md) and [RELEASE_POLICY.md](https://github.com/HyDE-Project/HyDE/blob/master/RELEASE_POLICY.md):\n\n- **All pull requests must be submitted to the `dev` branch**\n- Changes go through `dev` first for testing before being merged to `master` during release windows\n- **PRs to `master` are only allowed for emergencies**\n\n**Required Action:**\n1. **Rebase this PR to target the `dev` branch instead**\n2. Update the base branch from `master` to `dev`\n3. Follow the [pull request template](https://github.com/HyDE-Project/HyDE/blob/master/.github/PULL_REQUEST_TEMPLATE.md)\n\n**If this is an emergency fix, please add a comment explaining why it needs to target `master` directly.**\n\n---\n*This is an automated message enforcing our contribution workflow.*" |
| 64 | + body: "⚠️ **Warning: PR targeting master branch detected!**\n\n**This PR is targeting `master` but should target `dev` instead.**\n\nAccording to our [CONTRIBUTING.md](https://github.com/HyDE-Project/HyDE/blob/master/CONTRIBUTING.md) and [RELEASE_POLICY.md](https://github.com/HyDE-Project/HyDE/blob/master/RELEASE_POLICY.md):\n\n- **All pull requests must be submitted to the `dev` branch**\n- Changes go through `dev` first for testing before being merged to `master` during release windows\n- **PRs to `master` are only allowed for emergencies**\n\n**Required Action:**\n1. **Change the base branch from `master` to `dev`**\n2. Follow the [pull request template](https://github.com/HyDE-Project/HyDE/blob/master/.github/PULL_REQUEST_TEMPLATE.md)\n\n**If this is an emergency fix, please add a comment explaining why it needs to target `master` directly.**\n\n---\n*This is an automated message enforcing our contribution workflow.*" |
46 | 65 | }); |
47 | 66 | console.log('Warning comment added to PR #' + issue_number); |
48 | 67 | } else { |
|
0 commit comments