Skip to content

Commit 3fb0a51

Browse files
committed
ci: try fix warns on master
1 parent bf4ba80 commit 3fb0a51

File tree

1 file changed

+21
-87
lines changed

1 file changed

+21
-87
lines changed
Lines changed: 21 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Warn Master Branch PR
22

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

77
jobs:
@@ -33,7 +33,7 @@ jobs:
3333
github-token: ${{ secrets.GITHUB_TOKEN }}
3434
script: |
3535
const { repo, owner } = context.repo;
36-
const issue_number = context.issue.number;
36+
const issue_number = context.payload.pull_request.number;
3737
3838
// Skip if the PR author is github-actions[bot] (automated PR)
3939
const prAuthor = context.payload.pull_request.user.login;
@@ -42,94 +42,28 @@ jobs:
4242
return;
4343
}
4444
45-
// Check if this is a PR from a fork (external contributor)
46-
const headRepo = context.payload.pull_request.head.repo?.full_name;
47-
const baseRepo = context.payload.pull_request.base.repo.full_name;
48-
const isFromFork = headRepo && headRepo !== baseRepo;
45+
console.log(`Processing PR #${issue_number} from ${prAuthor}`);
4946
50-
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+
});
5153
52-
if (isFromFork) {
53-
console.log('PR is from a fork (external contributor)');
54-
// For fork PRs, try comment first, then review as fallback
55-
try {
56-
// Check if we already commented
57-
const comments = await github.rest.issues.listComments({
58-
owner,
59-
repo,
60-
issue_number
61-
});
62-
63-
const botComment = comments.data.find(comment =>
64-
comment.user.login === 'github-actions[bot]' &&
65-
comment.body.includes('⚠️ Warning: PR targeting master branch')
66-
);
67-
68-
if (!botComment) {
69-
await github.rest.issues.createComment({
70-
owner,
71-
repo,
72-
issue_number,
73-
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."
74-
});
75-
console.log('Comment added to fork PR #' + issue_number);
76-
} else {
77-
console.log('Comment already exists for fork PR #' + issue_number);
78-
}
79-
} catch (error) {
80-
console.log('Failed to create comment for fork PR, trying review:', error.message);
81-
// Fallback: try to add a review
82-
try {
83-
const reviews = await github.rest.pulls.listReviews({
84-
owner,
85-
repo,
86-
pull_number: issue_number
87-
});
88-
89-
const botReview = reviews.data.find(review =>
90-
review.user.login === 'github-actions[bot]' &&
91-
review.body && review.body.includes('⚠️ Warning: PR targeting master branch')
92-
);
93-
94-
if (!botReview) {
95-
await github.rest.pulls.createReview({
96-
owner,
97-
repo,
98-
pull_number: issue_number,
99-
event: 'COMMENT',
100-
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."
101-
});
102-
console.log('Review added to fork PR #' + issue_number);
103-
} else {
104-
console.log('Review already exists for fork PR #' + issue_number);
105-
}
106-
} catch (reviewError) {
107-
console.log('Both comment and review failed for fork PR:', reviewError.message);
108-
}
109-
}
110-
} else {
111-
// For PRs from the same repo (internal contributors)
112-
// Check if we already commented on this PR
113-
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({
11461
owner,
11562
repo,
116-
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.*"
11765
});
118-
119-
const botComment = comments.data.find(comment =>
120-
comment.user.login === 'github-actions[bot]' &&
121-
comment.body.includes('⚠️ Warning: PR targeting master branch')
122-
);
123-
124-
if (!botComment) {
125-
await github.rest.issues.createComment({
126-
owner,
127-
repo,
128-
issue_number,
129-
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.*"
130-
});
131-
console.log('Warning comment added to internal PR #' + issue_number);
132-
} else {
133-
console.log('Warning comment already exists for internal PR #' + issue_number);
134-
}
66+
console.log('Warning comment added to PR #' + issue_number);
67+
} else {
68+
console.log('Warning comment already exists for PR #' + issue_number);
13569
}

0 commit comments

Comments
 (0)