forked from hesreallyhim/awesome-claude-code
-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (135 loc) · 6.3 KB
/
Copy pathclose-resource-pr.yml
File metadata and controls
154 lines (135 loc) · 6.3 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
name: Close Resource Submission PRs
on:
pull_request_target:
types: [opened]
jobs:
detect-and-close:
name: Detect Resource Submission PR
runs-on: ubuntu-latest
# Skip PRs from bots (GitHub Actions bot, Dependabot, etc.)
if: github.event.pull_request.user.type != 'Bot'
permissions:
pull-requests: write
steps:
- name: Check if PR is a resource submission
id: detect
uses: actions/github-script@v7
with:
script: |
const title = context.payload.pull_request.title || '';
const body = context.payload.pull_request.body || '';
const combined = `${title}\n${body}`.toLowerCase();
// ── High-signal title patterns ──────────────────────────
const highSignalTitlePatterns = [
// "Add [resource]: My Tool" or "Add [resource]: My Tool to Hooks"
/^add\s*\[resource\]\s*:/i,
// "[Resource]: My Tool"
/^\[resource\]\s*:/i,
// "Add <name> to <section>" (common PR title for list additions)
/^add\s+.+\s+to\s+(slash.?commands?|hooks?|claude\.?md|tooling|skills?|agent|mcp|plugins?|workflows?|status.?lines?)/i,
];
let titleHighSignal = false;
for (const pattern of highSignalTitlePatterns) {
if (pattern.test(title)) {
titleHighSignal = true;
console.log(`High-signal title match: ${pattern}`);
break;
}
}
// ── Body phrase patterns (medium signal) ────────────────
const bodyPhrases = [
/add(ing)?\s+(a\s+)?(new\s+)?resource/i,
/submit(ting)?\s+(a\s+)?resource/i,
/resource\s+(submission|recommendation)/i,
/please\s+add\s+(this|my)/i,
/adding\s+.+\s+to\s+the\s+(list|awesome\s+list)/i,
/new\s+entry\s+(for|in)\s+/i,
/recommend(ing)?\s+(this|a)\s+(tool|resource|project)/i,
];
let bodyMatchCount = 0;
for (const pattern of bodyPhrases) {
if (pattern.test(combined)) {
bodyMatchCount++;
console.log(`Body phrase match: ${pattern}`);
}
}
// ── CSV / README file changes (very high signal) ────────
// Check if the PR touches THE_RESOURCES_TABLE.csv or README.md
const files = await github.rest.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
per_page: 50,
});
let touchesResourceFiles = false;
for (const file of files.data) {
if (
file.filename === 'THE_RESOURCES_TABLE.csv' ||
file.filename === 'README.md' ||
file.filename.startsWith('README_ALTERNATIVES/')
) {
touchesResourceFiles = true;
console.log(`Touches resource file: ${file.filename}`);
break;
}
}
// ── Decision logic ──────────────────────────────────────
// High-signal title alone is enough
// Body phrases + resource file changes is enough
// 2+ body phrase matches is enough
const isResourceSubmission =
titleHighSignal ||
(bodyMatchCount >= 1 && touchesResourceFiles) ||
bodyMatchCount >= 2;
console.log(`Title high signal: ${titleHighSignal}`);
console.log(`Body match count: ${bodyMatchCount}`);
console.log(`Touches resource files: ${touchesResourceFiles}`);
console.log(`Is resource submission: ${isResourceSubmission}`);
core.setOutput('is_resource_submission', isResourceSubmission.toString());
- name: Post comment and close PR
if: steps.detect.outputs.is_resource_submission == 'true'
uses: actions/github-script@v7
with:
script: |
const pr_number = context.payload.pull_request.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
const templateUrl = `https://github.com/${owner}/${repo}/issues/new?template=recommend-resource.yml`;
const contributingUrl = `https://github.com/${owner}/${repo}/blob/main/docs/CONTRIBUTING.md`;
const body = [
'## ⚠️ Resource submissions are not accepted via pull request',
'',
'Thank you for your interest in contributing to Awesome Claude Code!',
'',
'However, resource recommendations **must** be submitted through our issue template, not as a pull request. The entire resource pipeline — validation, review, and merging — is managed by automation. Even the maintainer does not use PRs to add entries to the list.',
'',
'**To submit your resource correctly:**',
'',
`1. 📖 Read the [CONTRIBUTING.md](${contributingUrl}) document`,
`2. 📝 [Submit your resource using the official template](${templateUrl})`,
'3. ✅ The bot will validate your submission automatically',
'4. 👀 A maintainer will review it once validation passes',
'',
'If this PR is **not** a resource submission (e.g., it\'s a bug fix or improvement), please comment below and we\'ll reopen it.',
'',
'---',
'*This PR has been automatically closed.*',
].join('\n');
await github.rest.issues.createComment({
owner,
repo,
issue_number: pr_number,
body,
});
await github.rest.pulls.update({
owner,
repo,
pull_number: pr_number,
state: 'closed',
});
await github.rest.issues.addLabels({
owner,
repo,
issue_number: pr_number,
labels: ['needs-template'],
});