Move Open Roles item to Filled when issue is closed #22
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: Move Open Roles item to Filled when issue is closed | |
| on: | |
| issues: | |
| types: | |
| - closed | |
| env: | |
| GH_TOKEN: ${{ secrets.ACTIONS_TOKEN }} | |
| OPEN_ROLES_PROJECT_ID: PVT_kwDOAA7NZM4AmdbW | |
| STATUS_FIELD_ID: PVTSSF_lADOAA7NZM4AmdbWzgeWrcw | |
| FILLED_OPTION_ID: "47fc9ee4" | |
| jobs: | |
| closed-to-filled: | |
| # Only act on open role issues | |
| if: contains(github.event.issue.labels.*.name, 'open role') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Set Open Roles item to Filled | |
| run: | | |
| ISSUE_NODE_ID="${{ github.event.issue.node_id }}" | |
| # Find the item on Open Roles board | |
| RESULT=$(gh api graphql -f query=' | |
| query($project: ID!) { | |
| node(id: $project) { | |
| ... on ProjectV2 { | |
| items(first: 100) { | |
| nodes { | |
| id | |
| fieldValueByName(name: "Status") { | |
| ... on ProjectV2ItemFieldSingleSelectValue { optionId } | |
| } | |
| content { ... on Issue { id } } | |
| } | |
| } | |
| } | |
| } | |
| }' -f project="$OPEN_ROLES_PROJECT_ID") | |
| ITEM_ID=$(echo "$RESULT" | jq -r ".data.node.items.nodes[] | select(.content.id == \"$ISSUE_NODE_ID\") | .id") | |
| CURRENT=$(echo "$RESULT" | jq -r ".data.node.items.nodes[] | select(.content.id == \"$ISSUE_NODE_ID\") | .fieldValueByName.optionId // \"\"") | |
| if [ -z "$ITEM_ID" ]; then | |
| echo "Issue not on Open Roles board — nothing to update." | |
| exit 0 | |
| fi | |
| # Guard: skip if already Filled (prevents loop with filled-to-close) | |
| if [ "$CURRENT" == "$FILLED_OPTION_ID" ]; then | |
| echo "Already 'Filled' — skipping." | |
| exit 0 | |
| fi | |
| echo "Issue closed — setting Open Roles item to 'Filled'..." | |
| gh api graphql -f query=' | |
| mutation($project: ID!, $item: ID!, $field: ID!, $option: String!) { | |
| updateProjectV2ItemFieldValue(input: { | |
| projectId: $project, | |
| itemId: $item, | |
| fieldId: $field, | |
| value: { singleSelectOptionId: $option } | |
| }) { | |
| projectV2Item { id } | |
| } | |
| }' \ | |
| -f project="$OPEN_ROLES_PROJECT_ID" \ | |
| -f item="$ITEM_ID" \ | |
| -f field="$STATUS_FIELD_ID" \ | |
| -f option="$FILLED_OPTION_ID" | |
| echo "Done." |