1# Labels pull requests by author: 'bot' for bot accounts, 'staff' for
2# staff team members, 'guild' for guild members, 'first contribution' for
3# first-time external contributors.
4name: PR Labeler
5
6on:
7 pull_request_target:
8 types: [opened]
9
10permissions:
11 contents: read
12
13jobs:
14 check-authorship-and-label:
15 if: github.repository == 'zed-industries/zed'
16 runs-on: namespace-profile-2x4-ubuntu-2404
17 timeout-minutes: 5
18 steps:
19 - id: get-app-token
20 uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v3.0.0
21 with:
22 app-id: ${{ secrets.ZED_COMMUNITY_BOT_APP_ID }}
23 private-key: ${{ secrets.ZED_COMMUNITY_BOT_PRIVATE_KEY }}
24 owner: zed-industries
25
26 - id: apply-authorship-label
27 uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
28 with:
29 github-token: ${{ steps.get-app-token.outputs.token }}
30 script: |
31 const BOT_LABEL = 'bot';
32 const STAFF_LABEL = 'staff';
33 const GUILD_LABEL = 'guild';
34 const FIRST_CONTRIBUTION_LABEL = 'first contribution';
35 const STAFF_TEAM_SLUG = 'staff';
36 const GUILD_MEMBERS = [
37 '11happy',
38 'AidanV',
39 'AmaanBilwar',
40 'MostlyKIGuess',
41 'OmChillure',
42 'Palanikannan1437',
43 'Shivansh-25',
44 'SkandaBhat',
45 'TwistingTwists',
46 'YEDASAVG',
47 'Ziqi-Yang',
48 'alanpjohn',
49 'arjunkomath',
50 'austincummings',
51 'ayushk-1801',
52 'criticic',
53 'dongdong867',
54 'emamulandalib',
55 'eureka928',
56 'feitreim',
57 'iam-liam',
58 'iksuddle',
59 'ishaksebsib',
60 'lingyaochu',
61 'loadingalias',
62 'marcocondrache',
63 'mchisolm0',
64 'nairadithya',
65 'nihalxkumar',
66 'notJoon',
67 'polyesterswing',
68 'prayanshchh',
69 'razeghi71',
70 'sarmadgulzar',
71 'seanstrom',
72 'th0jensen',
73 'tommyming',
74 'transitoryangel',
75 'virajbhartiya',
76 ];
77
78 const pr = context.payload.pull_request;
79 const author = pr.user.login;
80
81 if (pr.user.type === 'Bot') {
82 await github.rest.issues.addLabels({
83 owner: context.repo.owner,
84 repo: context.repo.repo,
85 issue_number: pr.number,
86 labels: [BOT_LABEL]
87 });
88 console.log(`PR #${pr.number} by ${author}: labeled '${BOT_LABEL}' (user type: '${pr.user.type}')`);
89 return;
90 }
91
92 let isStaff = false;
93 try {
94 const response = await github.rest.teams.getMembershipForUserInOrg({
95 org: 'zed-industries',
96 team_slug: STAFF_TEAM_SLUG,
97 username: author
98 });
99 isStaff = response.data.state === 'active';
100 } catch (error) {
101 if (error.status !== 404) {
102 throw error;
103 }
104 }
105
106 if (isStaff) {
107 await github.rest.issues.addLabels({
108 owner: context.repo.owner,
109 repo: context.repo.repo,
110 issue_number: pr.number,
111 labels: [STAFF_LABEL]
112 });
113 console.log(`PR #${pr.number} by ${author}: labeled '${STAFF_LABEL}' (staff team member)`);
114 return;
115 }
116
117 const authorLower = author.toLowerCase();
118 const isGuildMember = GUILD_MEMBERS.some(
119 (member) => member.toLowerCase() === authorLower
120 );
121 if (isGuildMember) {
122 await github.rest.issues.addLabels({
123 owner: context.repo.owner,
124 repo: context.repo.repo,
125 issue_number: pr.number,
126 labels: [GUILD_LABEL]
127 });
128 console.log(`PR #${pr.number} by ${author}: labeled '${GUILD_LABEL}' (guild member)`);
129 // No early return: guild members can also get 'first contribution'
130 }
131
132 // We use inverted logic here due to a suspected GitHub bug where first-time contributors
133 // get 'NONE' instead of 'FIRST_TIME_CONTRIBUTOR' or 'FIRST_TIMER'.
134 // https://github.com/orgs/community/discussions/78038
135 // This will break if GitHub ever adds new associations.
136 const association = pr.author_association;
137 const knownAssociations = ['CONTRIBUTOR', 'COLLABORATOR', 'MEMBER', 'OWNER', 'MANNEQUIN'];
138
139 if (knownAssociations.includes(association)) {
140 console.log(`PR #${pr.number} by ${author}: not a first-time contributor (association: '${association}')`);
141 return;
142 }
143
144 await github.rest.issues.addLabels({
145 owner: context.repo.owner,
146 repo: context.repo.repo,
147 issue_number: pr.number,
148 labels: [FIRST_CONTRIBUTION_LABEL]
149 });
150 console.log(`PR #${pr.number} by ${author}: labeled '${FIRST_CONTRIBUTION_LABEL}' (association: '${association}')`);