Add automation or script to update Remaining days to 0 whenever an issue is closed #14
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: Auto-Set Remaining Days to 0 on Issue Closed | |
| on: | |
| issues: | |
| types: [closed] | |
| jobs: | |
| update_remaining_days: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v4 | |
| - name: Install jq | |
| run: sudo apt-get update && sudo apt-get install -y jq | |
| - name: Authenticate GitHub CLI | |
| env: | |
| GH_TOKEN: ${{ secrets.UPDATE_PROJECT_V2_PAT }} | |
| run: echo "${GH_TOKEN}" | gh auth login --with-token | |
| - name: Debug - List projects linked to this issue | |
| env: | |
| GH_TOKEN: ${{ secrets.UPDATE_PROJECT_V2_PAT }} | |
| run: | | |
| echo "🔍 Listing all projects linked to issue ${{ github.event.issue.number }}..." | |
| gh issue view ${{ github.event.issue.number }} \ | |
| --repo ${{ github.repository }} \ | |
| --json projectsV2 \ | |
| | jq . | |
| - name: Set Remaining Days to 0 if issue is in Project 183 | |
| env: | |
| GH_TOKEN: ${{ secrets.UPDATE_PROJECT_V2_PAT }} | |
| run: | | |
| echo "🔍 Checking if issue ${{ github.event.issue.number }} belongs to Project 183..." | |
| # Find the project item ID for project 183 among the issue’s linked projects | |
| ITEM_ID=$(gh issue view ${{ github.event.issue.number }} \ | |
| --repo ${{ github.repository }} \ | |
| --json projectsV2 \ | |
| | jq -r '.projectsV2[] | select(.number==183) | .item.id') | |
| if [ -z "$ITEM_ID" ]; then | |
| echo "ℹ️ Issue is not in Project 183. Nothing to update." | |
| exit 0 | |
| fi | |
| echo "✅ Found Project Item ID in Project 183: $ITEM_ID" | |
| # Find the field ID for "Remaining Days" | |
| FIELD_ID=$(gh project field-list --owner microsoft --number 183 --format json \ | |
| | jq -r '.[] | select(.name=="Remaining Days") | .id') | |
| if [ -z "$FIELD_ID" ]; then | |
| echo "❌ No field named 'Remaining Days' found in Project 183." | |
| exit 1 | |
| fi | |
| echo "✅ Found Field ID for Remaining Days: $FIELD_ID" | |
| # Update the field value to 0 | |
| gh project item-update --owner microsoft --number 183 \ | |
| --id "$ITEM_ID" --field-id "$FIELD_ID" --value "0" | |
| echo "🎉 Successfully set Remaining Days = 0 for issue ${{ github.event.issue.number }}" |