first_contribution_labeler.yml

 1name: First Contribution Labeler
 2
 3on:
 4  pull_request_target:
 5    types: [opened]
 6
 7permissions:
 8  contents: read
 9
10jobs:
11  label_first_contribution:
12    if: github.repository == 'zed-industries/zed'
13    runs-on: ubuntu-latest
14    timeout-minutes: 5
15    steps:
16      - id: get-app-token
17        uses: actions/create-github-app-token@bef1eaf1c0ac2b148ee2a0a74c65fbe6db0631f1 # v2.1.4
18        with:
19          app-id: ${{ secrets.ZED_COMMUNITY_BOT_APP_ID }}
20          private-key: ${{ secrets.ZED_COMMUNITY_BOT_PRIVATE_KEY }}
21          owner: zed-industries
22
23      - id: check-and-label
24        uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
25        with:
26          github-token: ${{ steps.get-app-token.outputs.token }}
27          script: |
28            const LABEL_NAME = 'first contribution';
29
30            const pr = context.payload.pull_request;
31            const author = pr.user.login;
32
33            // Skip bots (they shouldn't have FIRST_TIME* association anyway, but just in case)
34            if (author.endsWith('[bot]')) {
35              console.log(`Skipping bot: ${author}`);
36              return;
37            }
38
39            // Check if this is a first-time contributor.
40            // These two values are mutually exclusive, so we need to check both:
41            // - FIRST_TIME_CONTRIBUTOR: has contributed to other repos, but not this one
42            // - FIRST_TIMER: has never contributed to any public repository on GitHub
43            const association = pr.author_association;
44
45            if (association !== 'FIRST_TIME_CONTRIBUTOR' && association !== 'FIRST_TIMER') {
46              console.log(`Author ${author} has association '${association}', not a first-time contributor`);
47              return;
48            }
49
50            // Skip staff members
51            try {
52              const response = await github.rest.teams.getMembershipForUserInOrg({
53                org: 'zed-industries',
54                team_slug: 'staff',
55                username: author
56              });
57              if (response.data.state === 'active') {
58                console.log(`Skipping staff member: ${author}`);
59                return;
60              }
61            } catch (error) {
62              if (error.status !== 404) {
63                throw error;
64              }
65              // 404 means user is not a staff member, continue
66            }
67
68            await github.rest.issues.addLabels({
69              owner: context.repo.owner,
70              repo: context.repo.repo,
71              issue_number: pr.number,
72              labels: [LABEL_NAME]
73            });
74
75            console.log(`Applied '${LABEL_NAME}' label to PR #${pr.number} by ${author}`);