Skip to content

Commit 3bd9fa7

Browse files
authored
Merge branch 'master' into dev
2 parents 55e2b3a + 3fb0a51 commit 3bd9fa7

File tree

1 file changed

+36
-88
lines changed

1 file changed

+36
-88
lines changed
Lines changed: 36 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,39 @@
11
name: Warn Master Branch PR
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
types: [opened, reopened, synchronize]
66

77
jobs:
88
warn-master-branch-pr:
99
name: Warn about PR targeting master branch
10-
if: github.event.pull_request.base.ref == 'master'
1110
runs-on: ubuntu-latest
1211
permissions:
1312
issues: write
1413
pull-requests: write
1514
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+
1629
- name: Add warning comment
30+
if: github.event.pull_request.base.ref == 'master'
1731
uses: actions/github-script@v6
1832
with:
1933
github-token: ${{ secrets.GITHUB_TOKEN }}
2034
script: |
2135
const { repo, owner } = context.repo;
22-
const issue_number = context.issue.number;
36+
const issue_number = context.payload.pull_request.number;
2337
2438
// Skip if the PR author is github-actions[bot] (automated PR)
2539
const prAuthor = context.payload.pull_request.user.login;
@@ -28,94 +42,28 @@ jobs:
2842
return;
2943
}
3044
31-
// Check if this is a PR from a fork (external contributor)
32-
const headRepo = context.payload.pull_request.head.repo?.full_name;
33-
const baseRepo = context.payload.pull_request.base.repo.full_name;
34-
const isFromFork = headRepo && headRepo !== baseRepo;
45+
console.log(`Processing PR #${issue_number} from ${prAuthor}`);
3546
36-
console.log(`PR Details: Head repo: ${headRepo}, Base repo: ${baseRepo}, Is fork: ${isFromFork}`);
47+
// Check if we already commented
48+
const comments = await github.rest.issues.listComments({
49+
owner,
50+
repo,
51+
issue_number
52+
});
3753
38-
if (isFromFork) {
39-
console.log('PR is from a fork (external contributor)');
40-
// For fork PRs, try comment first, then review as fallback
41-
try {
42-
// Check if we already commented
43-
const comments = await github.rest.issues.listComments({
44-
owner,
45-
repo,
46-
issue_number
47-
});
48-
49-
const botComment = comments.data.find(comment =>
50-
comment.user.login === 'github-actions[bot]' &&
51-
comment.body.includes('⚠️ Warning: PR targeting master branch')
52-
);
53-
54-
if (!botComment) {
55-
await github.rest.issues.createComment({
56-
owner,
57-
repo,
58-
issue_number,
59-
body: "⚠️ **Warning: PR targeting master branch detected!** Please change the base branch to `dev` instead of `master`. See our [CONTRIBUTING.md](https://github.com/HyDE-Project/HyDE/blob/master/CONTRIBUTING.md) for details."
60-
});
61-
console.log('Comment added to fork PR #' + issue_number);
62-
} else {
63-
console.log('Comment already exists for fork PR #' + issue_number);
64-
}
65-
} catch (error) {
66-
console.log('Failed to create comment for fork PR, trying review:', error.message);
67-
// Fallback: try to add a review
68-
try {
69-
const reviews = await github.rest.pulls.listReviews({
70-
owner,
71-
repo,
72-
pull_number: issue_number
73-
});
74-
75-
const botReview = reviews.data.find(review =>
76-
review.user.login === 'github-actions[bot]' &&
77-
review.body && review.body.includes('⚠️ Warning: PR targeting master branch')
78-
);
79-
80-
if (!botReview) {
81-
await github.rest.pulls.createReview({
82-
owner,
83-
repo,
84-
pull_number: issue_number,
85-
event: 'COMMENT',
86-
body: "⚠️ **Warning: PR targeting master branch detected!** Please change the base branch to `dev` instead of `master`. See our [CONTRIBUTING.md](https://github.com/HyDE-Project/HyDE/blob/master/CONTRIBUTING.md) for details."
87-
});
88-
console.log('Review added to fork PR #' + issue_number);
89-
} else {
90-
console.log('Review already exists for fork PR #' + issue_number);
91-
}
92-
} catch (reviewError) {
93-
console.log('Both comment and review failed for fork PR:', reviewError.message);
94-
}
95-
}
96-
} else {
97-
// For PRs from the same repo (internal contributors)
98-
// Check if we already commented on this PR
99-
const comments = await github.rest.issues.listComments({
54+
const botComment = comments.data.find(comment =>
55+
comment.user.login === 'github-actions[bot]' &&
56+
comment.body.includes('⚠️ Warning: PR targeting master branch')
57+
);
58+
59+
if (!botComment) {
60+
await github.rest.issues.createComment({
10061
owner,
10162
repo,
102-
issue_number
63+
issue_number,
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.*"
10365
});
104-
105-
const botComment = comments.data.find(comment =>
106-
comment.user.login === 'github-actions[bot]' &&
107-
comment.body.includes('⚠️ Warning: PR targeting master branch')
108-
);
109-
110-
if (!botComment) {
111-
await github.rest.issues.createComment({
112-
owner,
113-
repo,
114-
issue_number,
115-
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.*"
116-
});
117-
console.log('Warning comment added to internal PR #' + issue_number);
118-
} else {
119-
console.log('Warning comment already exists for internal PR #' + issue_number);
120-
}
66+
console.log('Warning comment added to PR #' + issue_number);
67+
} else {
68+
console.log('Warning comment already exists for PR #' + issue_number);
12169
}

0 commit comments

Comments
 (0)