catch_blank_issues.yml

 1name: "Label new and reopened blank issues for triage"
 2
 3on:
 4  issues:
 5    types:
 6      - opened
 7      - reopened
 8
 9permissions:
10  contents: read
11
12jobs:
13  add-triage-label:
14    if: github.repository == 'zed-industries/zed'
15    runs-on: ubuntu-latest
16    timeout-minutes: 5
17    steps:
18      - id: get-app-token
19        uses: actions/create-github-app-token@bef1eaf1c0ac2b148ee2a0a74c65fbe6db0631f1 # v2.1.4
20        with:
21          app-id: ${{ secrets.ZED_COMMUNITY_BOT_APP_ID }}
22          private-key: ${{ secrets.ZED_COMMUNITY_BOT_PRIVATE_KEY }}
23          owner: zed-industries
24
25      - id: check-staff
26        uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
27        with:
28          github-token: ${{ steps.get-app-token.outputs.token }}
29          script: |
30            try {
31              const response = await github.rest.teams.getMembershipForUserInOrg({
32                org: 'zed-industries',
33                team_slug: 'staff',
34                username: context.payload.sender.login
35              });
36              return response.data.state === 'active';
37            } catch (error) {
38              if (error.status === 404) {
39                return false;
40              }
41              throw error;
42            }
43
44      - if: steps.check-staff.outputs.result == 'true'
45        run: |
46          echo "::notice::Skipping issue #${{ github.event.issue.number }} - actor is staff member"
47
48      - if: steps.check-staff.outputs.result == 'false'
49        id: add-label
50        uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
51        with:
52          github-token: ${{ steps.get-app-token.outputs.token }}
53          script: |
54            const issue = context.payload.issue;
55            const hasTriageLabel = issue.labels.some(
56              label => label.name === 'state:needs triage'
57            );
58
59            if (hasTriageLabel) {
60              console.log('Issue already has state:needs triage, skipping');
61              return;
62            }
63
64            await github.rest.issues.addLabels({
65              owner: context.repo.owner,
66              repo: context.repo.repo,
67              issue_number: issue.number,
68              labels: ['state:needs triage']
69            });
70
71            console.log(`Added state:needs triage to issue #${issue.number}`);