94 lines
3.3 KiB
YAML
94 lines
3.3 KiB
YAML
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.'
|
|
);
|