fix: try project_v2_item trigger (singular) #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Add Label on Project Status Change | ||
| on: | ||
| workflow_dispatch: | ||
| project_v2_item: | ||
| types: [edited] | ||
| jobs: | ||
| add-label: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Check project item status and add label | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| try { | ||
| const { data: item } = await github.graphql(` | ||
| query($id: ID!) { | ||
| node(id: $id) { | ||
| ... on ProjectV2Item { | ||
| content { | ||
| ... on Issue { | ||
| number | ||
| repository { | ||
| name | ||
| owner { login } | ||
| } | ||
| } | ||
| } | ||
| fieldValues(first: 10) { | ||
| nodes { | ||
| ... on ProjectV2ItemFieldSingleSelectValue { | ||
| field { name } | ||
| name | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| `, { id: context.payload.project_v2_item.node_id }); | ||
| const statusField = item.fieldValues.nodes.find(f => f.field.name === "Status"); | ||
| console.log("current status:", statusField?.name); | ||
| if ( | ||
| statusField?.name === "Need To Verify" && | ||
| item.content?.number | ||
| ) { | ||
| const issue = item.content; | ||
| await github.rest.issues.addLabels({ | ||
| owner: issue.repository.owner.login, | ||
| repo: issue.repository.name, | ||
| issue_number: issue.number, | ||
| labels: ["kind/need-to-verify"] | ||
| }); | ||
| console.log("Label added: kind/need-to-verify"); | ||
| } else { | ||
| console.log("Not a matching item, skip"); | ||
| } | ||
| } catch (error) { | ||
| console.error("Action failed:", error.message); | ||
| throw error; | ||
| } | ||