issue-routing-helper.yml 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. name: Issue Routing Helper
  2. on:
  3. issues:
  4. types: [labeled]
  5. env:
  6. # Use GH_RELEASE_PAT as github-actions bot is not allowed to ping teams
  7. GH_TOKEN: ${{ secrets.GH_RELEASE_PAT }}
  8. GH_REPO: ${{ github.repository }}
  9. jobs:
  10. route:
  11. runs-on: ubuntu-latest
  12. if: >-
  13. github.event.issue.state == 'open'
  14. &&
  15. startsWith(github.event.label.name, 'Team: ')
  16. &&
  17. !contains(github.event.issue.labels.*.name, 'Status: Backlog')
  18. &&
  19. !contains(github.event.issue.labels.*.name, 'Status: In Progress')
  20. steps:
  21. - name: "Check Membership of issue creator"
  22. id: "check_membership"
  23. env:
  24. issue_number: ${{ github.event.issue.number }}
  25. run: |
  26. author_association=$(gh api "repos/$GH_REPO/issues/$issue_number" -q .author_association)
  27. echo "membership=$author_association" >> $GITHUB_OUTPUT
  28. - name: "Ensure a single 'Team: *' label with 'Status: Untriaged'"
  29. env:
  30. team_label: ${{ github.event.label.name }}
  31. issue_number: ${{ github.event.issue.number }}
  32. membership: ${{ steps.check_membership.outputs.membership }}
  33. if: >-
  34. env.membership != 'OWNER'
  35. &&
  36. env.membership != 'MEMBER'
  37. run: |
  38. labels_to_remove=$(gh api --paginate "/repos/$GH_REPO/labels" -q '[.[].name | select((startswith("Team: ") or startswith("Status: ")) and . != "${{ github.event.label.name }}" and . != "Status: Untriaged")] | join(",")')
  39. gh issue edit ${{ github.event.issue.number }} --remove-label "$labels_to_remove" --add-label '${{ github.event.label.name }},Status: Untriaged'
  40. - name: "Mention/ping assigned team for triage"
  41. env:
  42. team_label: ${{ github.event.label.name }}
  43. issue_number: ${{ github.event.issue.number }}
  44. membership: ${{ steps.check_membership.outputs.membership }}
  45. if: >-
  46. env.membership != 'OWNER'
  47. &&
  48. env.membership != 'MEMBER'
  49. run: |
  50. # Get team label mention name:
  51. team_label='${{ github.event.label.name }}'
  52. team_name="${team_label:6}" # Strip the first 6 chars, which is the 'Team: ' part
  53. team_slug="${team_name// /-}" # Replace spaces with hyphens for url/slug friendliness
  54. mention_slug=$(gh api "/orgs/getsentry/teams/$team_slug" -q .slug || true)
  55. if [ "${mention_slug::1}" = "{" ]; then
  56. # Hack around https://github.com/getsentry/.github/issues/77
  57. mention_slug=""
  58. fi
  59. if [[ -z "$mention_slug" ]]; then
  60. echo "Couldn't find team mention from slug, trying the label description"
  61. team_slug=$(gh api "/repos/$GH_REPO/labels/$team_label" -q '.description')
  62. mention_slug=$(gh api "/orgs/getsentry/teams/$team_slug" -q .slug || true)
  63. if [ "${mention_slug::1}" = "{" ]; then
  64. # Hack around https://github.com/getsentry/.github/issues/77
  65. mention_slug=""
  66. fi
  67. fi
  68. if [[ -n "$mention_slug" ]]; then
  69. echo "Routing to @getsentry/$mention_slug for [triage](https://develop.sentry.dev/processing-tickets/#3-triage). ⏲️" > comment_body
  70. else
  71. echo "[Failed]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID) to route to \`${{ github.event.label.name }}\`. 😕" > comment_body
  72. echo "" >> comment_body
  73. echo "Defaulting to @getsentry/open-source for [triage](https://develop.sentry.dev/processing-tickets/#3-triage). ⏲️" >> comment_body
  74. fi
  75. gh issue comment ${{ github.event.issue.number }} --body-file comment_body