enforce-milestone.yml 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. name: Enforce milestone on close
  2. on:
  3. issues:
  4. types:
  5. - closed
  6. permissions:
  7. issues: write
  8. jobs:
  9. check-milestone:
  10. name: Check Milestone
  11. if: github.repository == 'netbox-community/netbox' && github.event.issue.state_reason == 'completed'
  12. runs-on: ubuntu-slim
  13. steps:
  14. - name: Reopen issues completed without a milestone
  15. env:
  16. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  17. GH_REPO: ${{ github.repository }}
  18. ISSUE: ${{ github.event.issue.number }}
  19. run: |
  20. # Grace period, in case the milestone is assigned immediately after closure
  21. sleep 90
  22. # Re-check the issue: bail out if it has been reopened or a milestone has since been set
  23. DATA=$(gh issue view "$ISSUE" --json state,milestone)
  24. STATE=$(jq -r '.state' <<< "$DATA")
  25. MILESTONE=$(jq -r '.milestone.title // ""' <<< "$DATA")
  26. if [ "$STATE" != "CLOSED" ] || [ -n "$MILESTONE" ]; then
  27. echo "Nothing to do (state=$STATE, milestone=${MILESTONE:-none})"
  28. exit 0
  29. fi
  30. gh issue reopen "$ISSUE" --comment \
  31. "This issue was closed as completed without a milestone assigned, and has been reopened automatically. Please assign the milestone for the upcoming release, then close the issue again."