mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-02-26 07:37:20 +00:00
This is a new step in my crusade against the braindead fad of starting PR titles with a word that is completely redundant with github labels, thus wasting prime first-line real-estate for something that isn't necessary. I noticed that every single one of these PRs are low-quality AI-slop, so I think there is a strong case to be made for these PRs to be auto-closed. A message is added before closing the PR, redirecting to our contribution guidelines, so I expect quality first-time contributors to read them and reopen the PR. In the case of spam PRs, the author is unlikely to revisit a given PR, and so auto-closing might have a positive impact. That's an experiment worth trying, imo.
83 lines
2.9 KiB
YAML
83 lines
2.9 KiB
YAML
name: PR Format Validation
|
|
|
|
on:
|
|
pull_request:
|
|
types: [opened, edited, synchronize]
|
|
|
|
jobs:
|
|
validate-pr:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Check for Spam PR
|
|
uses: actions/github-script@v7
|
|
with:
|
|
script: |
|
|
const prTitle = context.payload.pull_request.title;
|
|
const spamRegex = /^(feat|chore|fix)(\(.*\))?\s*:/i;
|
|
|
|
if (spamRegex.test(prTitle)) {
|
|
// Leave a comment explaining why
|
|
await github.rest.issues.createComment({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: context.payload.pull_request.number,
|
|
body: `## PR Closed as Spam
|
|
|
|
This PR was automatically closed because the title format \`feat:\`, \`fix:\`, or \`chore:\` is commonly associated with spam contributions.
|
|
|
|
If this is a legitimate contribution, please:
|
|
1. Review our contribution guidelines
|
|
2. Use the correct PR title format: \`directory, ...: description\`
|
|
3. Open a new PR with the proper title format
|
|
|
|
Thank you for your understanding.`
|
|
});
|
|
|
|
// Close the PR
|
|
await github.rest.pulls.update({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
pull_number: context.payload.pull_request.number,
|
|
state: 'closed'
|
|
});
|
|
|
|
core.setFailed('PR closed as spam due to suspicious title format');
|
|
return;
|
|
}
|
|
|
|
console.log('✅ PR passed spam check');
|
|
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Check PR Title Format
|
|
uses: actions/github-script@v7
|
|
with:
|
|
script: |
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const prTitle = context.payload.pull_request.title;
|
|
const titleRegex = /^([\w\s,{}/.]+): .+/;
|
|
|
|
if (!titleRegex.test(prTitle)) {
|
|
core.setFailed(`PR title "${prTitle}" does not match required format: directory, ...: description`);
|
|
return;
|
|
}
|
|
|
|
const match = prTitle.match(titleRegex);
|
|
const dirPart = match[1];
|
|
const directories = dirPart.split(',').map(d => d.trim());
|
|
const missingDirs = [];
|
|
for (const dir of directories) {
|
|
const fullPath = path.join(process.env.GITHUB_WORKSPACE, dir);
|
|
if (!fs.existsSync(fullPath)) {
|
|
missingDirs.push(dir);
|
|
}
|
|
}
|
|
|
|
if (missingDirs.length > 0) {
|
|
core.setFailed(`The following directories in the PR title do not exist: ${missingDirs.join(', ')}`);
|
|
return;
|
|
}
|
|
|
|
console.log('✅ PR title format is valid');
|