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
  8jobs:
  9  add-to-project:
 10    if: >
 11      github.repository == 'zed-industries/zed' &&
 12      github.event.issue.state == 'closed' &&
 13      github.event.issue.type.name == 'Bug' &&
 14      github.event.comment.user.type != 'Bot'
 15    runs-on: ubuntu-latest
 16    steps:
 17      - id: get-app-token
 18        uses: actions/create-github-app-token@bef1eaf1c0ac2b148ee2a0a74c65fbe6db0631f1 # v2.1.4
 19        with:
 20          app-id: ${{ secrets.ZED_COMMUNITY_BOT_APP_ID }}
 21          private-key: ${{ secrets.ZED_COMMUNITY_BOT_PRIVATE_KEY }}
 22          owner: zed-industries
 23
 24      - id: check-staff
 25        uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
 26        with:
 27          github-token: ${{ steps.get-app-token.outputs.token }}
 28          script: |
 29            try {
 30              const response = await github.rest.teams.getMembershipForUserInOrg({
 31                org: 'zed-industries',
 32                team_slug: 'staff',
 33                username: context.payload.comment.user.login
 34              });
 35              return response.data.state === 'active';
 36            } catch (error) {
 37              // 404 means user is not a member
 38              if (error.status === 404) {
 39                return false;
 40              }
 41              throw error;
 42            }
 43
 44      # Add to the support team's board for triage
 45      - id: add-to-project
 46        if: steps.check-staff.outputs.result == 'false'
 47        uses: actions/add-to-project@244f685bbc3b7adfa8466e08b698b5577571133e # v1.0.2
 48        with:
 49          project-url: https://github.com/orgs/zed-industries/projects/71
 50          github-token: ${{ steps.get-app-token.outputs.token }}
 51
 52      # Set status to "Incoming" (overrides project's default "Closed" automation)
 53      - if: steps.add-to-project.outputs.itemId
 54        uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
 55        with:
 56          github-token: ${{ steps.get-app-token.outputs.token }}
 57          script: |
 58            const itemId = '${{ steps.add-to-project.outputs.itemId }}';
 59            const projectNumber = 71;
 60
 61            // Get project ID and Status field in one query
 62            const { organization } = await github.graphql(`
 63              query($org: String!, $projectNumber: Int!) {
 64                organization(login: $org) {
 65                  projectV2(number: $projectNumber) {
 66                    id
 67                    field(name: "Status") {
 68                      ... on ProjectV2SingleSelectField {
 69                        id
 70                        options {
 71                          id
 72                          name
 73                        }
 74                      }
 75                    }
 76                  }
 77                }
 78              }
 79            `, { org: 'zed-industries', projectNumber });
 80
 81            const project = organization.projectV2;
 82            if (!project.field) {
 83              throw new Error('Could not find "Status" field in project');
 84            }
 85
 86            const incomingOption = project.field.options.find(o => o.name === 'Incoming');
 87            if (!incomingOption) {
 88              throw new Error('Could not find "Incoming" status option');
 89            }
 90
 91            // Update the item's status
 92            await github.graphql(`
 93              mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!, $optionId: String!) {
 94                updateProjectV2ItemFieldValue(input: {
 95                  projectId: $projectId
 96                  itemId: $itemId
 97                  fieldId: $fieldId
 98                  value: { singleSelectOptionId: $optionId }
 99                }) {
100                  projectV2Item {
101                    id
102                  }
103                }
104              }
105            `, {
106              projectId: project.id,
107              itemId,
108              fieldId: project.field.id,
109              optionId: incomingOption.id
110            });