mirror of
https://github.com/arjunkomath/openclaw-railway-template.git
synced 2026-08-14 00:48:11 +00:00
PR checks
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
name: Auto-close spam PRs
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [opened]
|
||||
|
||||
jobs:
|
||||
check-spam:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
pull-requests: write
|
||||
steps:
|
||||
- uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const pr = context.payload.pull_request;
|
||||
const author = pr.user.login;
|
||||
|
||||
// Skip PRs from repo owner
|
||||
if (author === 'arjunkomath') {
|
||||
console.log('PR from repo owner, skipping.');
|
||||
return;
|
||||
}
|
||||
|
||||
const title = pr.title || '';
|
||||
const body = (pr.body || '').trim();
|
||||
const headBranch = pr.head.ref;
|
||||
|
||||
// Strip template boilerplate to measure actual content
|
||||
const templatePatterns = [
|
||||
/<!--.*?-->/gs,
|
||||
/^## .+$/gm,
|
||||
/^- \[ \] .+$/gm,
|
||||
/^Fixes #\s*$/gm,
|
||||
];
|
||||
let strippedBody = body;
|
||||
for (const pattern of templatePatterns) {
|
||||
strippedBody = strippedBody.replace(pattern, '');
|
||||
}
|
||||
strippedBody = strippedBody.trim();
|
||||
|
||||
let reason = '';
|
||||
|
||||
// Check: empty or near-empty body
|
||||
if (strippedBody.length < 50) {
|
||||
reason = 'PR description is empty or too short';
|
||||
}
|
||||
|
||||
// Check: title too short
|
||||
if (!reason && title.length < 20) {
|
||||
reason = 'PR title is too short';
|
||||
}
|
||||
|
||||
if (!reason) {
|
||||
console.log('PR looks legitimate, skipping.');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Closing PR #${pr.number}: ${reason}`);
|
||||
|
||||
// Comment and close
|
||||
await github.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: pr.number,
|
||||
body: `This PR was automatically closed. Reason: **${reason}**.`
|
||||
});
|
||||
|
||||
await github.rest.pulls.update({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
pull_number: pr.number,
|
||||
state: 'closed',
|
||||
});
|
||||
Reference in New Issue
Block a user