1name: Community Champion Auto Labeler
2
3on:
4 issues:
5 types: [opened]
6 pull_request_target:
7 types: [opened]
8
9jobs:
10 label_community_champion:
11 if: github.repository_owner == 'zed-industries'
12 runs-on: ubuntu-latest
13 steps:
14 - name: Check if author is a community champion and apply label
15 uses: actions/github-script@v7
16 with:
17 script: |
18 const communityChampionBody = `${{ secrets.COMMUNITY_CHAMPIONS }}`;
19
20 const communityChampions = communityChampionBody
21 .split('\n')
22 .map(handle => handle.trim().toLowerCase());
23
24 let author;
25 if (context.eventName === 'issues') {
26 author = context.payload.issue.user.login;
27 } else if (context.eventName === 'pull_request_target') {
28 author = context.payload.pull_request.user.login;
29 }
30
31 if (!author || !communityChampions.includes(author.toLowerCase())) {
32 return;
33 }
34
35 const issueNumber = context.payload.issue?.number || context.payload.pull_request?.number;
36
37 try {
38 await github.rest.issues.addLabels({
39 owner: context.repo.owner,
40 repo: context.repo.repo,
41 issue_number: issueNumber,
42 labels: ['community champion']
43 });
44
45 console.log(`Applied 'community champion' label to #${issueNumber} by ${author}`);
46 } catch (error) {
47 console.error(`Failed to apply label: ${error.message}`);
48 }