add_commented_closed_issue_to_project.yml

 1name: "Surface closed issues someone's commented on"
 2
 3on:
 4  issue_comment:
 5    types:
 6      - created
 7
 8permissions:
 9  contents: read
10
11jobs:
12  add-to-project:
13    if: >
14      github.repository == 'zed-industries/zed' &&
15      github.event.issue.state == 'closed' &&
16      github.event.issue.pull_request == null &&
17      github.event.issue.type != null &&
18      github.event.issue.type.name == 'Bug' &&
19      github.event.comment.user.type != 'Bot'
20    runs-on: ubuntu-latest
21    timeout-minutes: 5
22    steps:
23      - id: get-app-token
24        uses: actions/create-github-app-token@bef1eaf1c0ac2b148ee2a0a74c65fbe6db0631f1 # v2.1.4
25        with:
26          app-id: ${{ secrets.ZED_COMMUNITY_BOT_APP_ID }}
27          private-key: ${{ secrets.ZED_COMMUNITY_BOT_PRIVATE_KEY }}
28          owner: zed-industries
29
30      - id: check-staff
31        uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
32        with:
33          github-token: ${{ steps.get-app-token.outputs.token }}
34          script: |
35            try {
36              const response = await github.rest.teams.getMembershipForUserInOrg({
37                org: 'zed-industries',
38                team_slug: 'staff',
39                username: context.payload.comment.user.login
40              });
41              return response.data.state === 'active';
42            } catch (error) {
43              // 404 means user is not a member
44              if (error.status === 404) {
45                return false;
46              }
47              throw error;
48            }
49
50      - if: steps.check-staff.outputs.result == 'true'
51        run: |
52          echo "::notice::Skipping issue #${{ github.event.issue.number }} - commenter is staff member"
53
54      # github-script outputs are JSON strings, so we compare against 'false' (string)
55      - if: steps.check-staff.outputs.result == 'false'
56        run: |
57          echo "::notice::Adding issue #${{ github.event.issue.number }} to project (comment by ${{ github.event.comment.user.login }})"
58
59      - if: steps.check-staff.outputs.result == 'false'
60        uses: actions/add-to-project@244f685bbc3b7adfa8466e08b698b5577571133e # v1.0.2
61        with:
62          project-url: https://github.com/orgs/zed-industries/projects/73
63          github-token: ${{ steps.get-app-token.outputs.token }}