forked from alirezarezvani/claude-skills
-
Notifications
You must be signed in to change notification settings - Fork 0
75 lines (65 loc) · 2.76 KB
/
Copy pathenforce-pr-target.yml
File metadata and controls
75 lines (65 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
---
name: Enforce PR Target Branch
on:
pull_request_target:
types: [opened, edited, ready_for_review]
branches: [main]
permissions:
pull-requests: write
jobs:
check-target:
runs-on: ubuntu-latest
steps:
- name: Block PRs targeting main (only dev -> main promotion allowed)
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
const author = pr.user.login;
const headRef = pr.head.ref;
const sameRepo = pr.head.repo.full_name === context.payload.repository.full_name;
// HARD RULE (CLAUDE.md > Git Workflow): main only receives
// dev -> main promotion PRs. Branch-based, not author-based —
// maintainers are not exempt.
if (sameRepo && headRef === 'dev') {
console.log(`✅ dev -> main promotion PR — allowed.`);
return;
}
// Maintainers: fail the check and explain, but don't auto-close
// (avoids nuking intentional work; retarget instead).
const maintainers = ['alirezarezvani'];
const isMaintainer = maintainers.includes(author);
const nextStep = isMaintainer
? 'This check will re-run automatically once the base branch is changed.'
: 'This PR has been closed automatically; reopen it after retargeting, ' +
'or open a new PR against `dev`.';
const message = [
`👋 Hi @${author}, thanks for your contribution!`,
'',
'All PRs must target the `dev` branch, not `main`. The `main` branch',
'only receives `dev -> main` promotion PRs (see CLAUDE.md > Git Workflow).',
'',
'**How to fix:** click "Edit" at the top right of this PR and change',
'the base branch to `dev`.',
'',
nextStep,
'',
'See our [Contributing Guide]' +
'(https://github.com/alirezarezvani/claude-skills/blob/dev/CONTRIBUTING.md)' +
' for details.',
].join('\n');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
body: message,
});
if (!isMaintainer) {
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
state: 'closed',
});
}
core.setFailed(`PR #${pr.number} targets main from '${headRef}' (not dev). ${isMaintainer ? 'Retarget to dev.' : 'Closed automatically.'}`);