返回 CodeWhale
issue-gate.yml
根目录 / .github / workflows / issue-gate.yml
1 name: Contribution intake - issues
2
3 on:
4 issues:
5 types: [opened, reopened]
6
7 permissions:
8 contents: read
9 issues: write
10
11 jobs:
12 gate:
13 runs-on: ubuntu-latest
14 steps:
15 - name: Welcome new external issue reporters
16 uses: actions/github-script@v9
17 with:
18 script: |
19 const issue = context.payload.issue;
20 const owner = context.repo.owner;
21 const repo = context.repo.repo;
22 const privileged = new Set(['OWNER', 'MEMBER', 'COLLABORATOR']);
23
24 if (privileged.has(issue.author_association)) return;
25 if (issue.user.login === 'github-actions[bot]') return;
26
27 function parseAllowlist(content) {
28 return new Set(
29 content
30 .split(/\r?\n/)
31 .map(line => line.replace(/#.*/, '').trim().toLowerCase())
32 .filter(Boolean)
33 );
34 }
35
36 async function readAllowlist() {
37 try {
38 const { data } = await github.rest.repos.getContent({
39 owner,
40 repo,
41 path: '.github/APPROVED_CONTRIBUTORS',
42 ref: context.payload.repository.default_branch,
43 });
44 if (Array.isArray(data) || data.type !== 'file') return new Set();
45 return parseAllowlist(
46 Buffer.from(data.content, data.encoding || 'base64').toString('utf8')
47 );
48 } catch (error) {
49 if (error.status === 404) return new Set();
50 throw error;
51 }
52 }
53
54 const allowlist = await readAllowlist();
55 const login = issue.user.login.toLowerCase();
56 if (
57 allowlist.has(`all:${login}`) ||
58 allowlist.has(`issue:${login}`)
59 ) {
60 return;
61 }
62
63 const marker = '<!-- codewhale-issue-intake -->';
64 const { data: comments } = await github.rest.issues.listComments({
65 owner,
66 repo,
67 issue_number: issue.number,
68 per_page: 100,
69 });
70 if (comments.some(comment => (comment.body || '').includes(marker))) return;
71
72 await github.rest.issues.createComment({
73 owner,
74 repo,
75 issue_number: issue.number,
76 body: [
77 marker,
78 `Thanks @${issue.user.login} for the report.`,
79 '',
80 'This issue is staying open for maintainer triage. CodeWhale gets better because people bring us real edge cases from real machines, providers, regions, and workflows.',
81 '',
82 'If you can add a reproduction, logs, version output, screenshots, or the provider/model involved, that makes it much easier for us to verify and harvest the fix. Maintainers may comment `/lgtmi` to mark recurring issue reporters as approved so this intake note is skipped next time.',
83 ].join('\n'),
84 });
85
85 lines YAML