-
Notifications
You must be signed in to change notification settings - Fork 13.3k
93 lines (84 loc) · 3.27 KB
/
Copy pathpr-validation.yml
File metadata and controls
93 lines (84 loc) · 3.27 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: "PR Validation"
on:
pull_request_target:
types: [opened, reopened, synchronize]
permissions:
pull-requests: write
jobs:
check-commit-authors:
runs-on: ubuntu-latest
name: Verify commit author emails
steps:
- name: Check commit authors linked to GitHub
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const prNumber = context.payload.pull_request.number;
const commits = await github.rest.pulls.listCommits({
owner,
repo,
pull_number: prNumber,
per_page: 100,
});
const unlinked = commits.data.filter(c => !c.author);
if (unlinked.length === 0) {
core.info('All commit authors are linked to GitHub accounts.');
return;
}
const details = unlinked.map(c =>
`| \`${c.sha.slice(0, 7)}\` | ${c.commit.author.name} | ${c.commit.author.email} |`
).join('\n');
const body = [
'### ⚠️ Commit Author Verification Failed',
'',
'The following commits have author emails **not linked to any GitHub account**.',
'This will prevent CLA signing and block your PR from being merged.',
'',
'| Commit | Author | Email |',
'|--------|--------|-------|',
details,
'',
'**How to fix:**',
'1. Add your commit email to your GitHub account: https://github.com/settings/emails',
'2. Or update your local git config to use an email already linked to GitHub:',
' ```',
' git config user.name "Your GitHub Username"',
' git config user.email "your-github-email@example.com"',
' ```',
'3. Amend your commits and force-push:',
' ```',
' git rebase -i HEAD~' + unlinked.length + ' # mark commits as "edit" and amend author',
' git push --force-with-lease',
' ```',
'',
'*This check will re-run automatically after you push.*',
].join('\n');
// Post or update comment
const marker = '<!-- pr-validation-author-check -->';
const commentBody = marker + '\n' + body;
const existingComments = await github.rest.issues.listComments({
owner,
repo,
issue_number: prNumber,
});
const existing = existingComments.data.find(c => c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existing.id,
body: commentBody,
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number: prNumber,
body: commentBody,
});
}
core.setFailed(
`${unlinked.length} commit(s) have author emails not linked to a GitHub account. ` +
'See the PR comment for fix instructions.'
);