issue-routing-helper.yml 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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: "Ensure a single 'Team: *' label with 'Status: Untriaged'"
  22. run: |
  23. 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(",")')
  24. gh issue edit ${{ github.event.issue.number }} --remove-label "$labels_to_remove" --add-label '${{ github.event.label.name }},Status: Untriaged'
  25. - name: "Mention/ping assigned team for triage"
  26. run: |
  27. # Get team label mention name:
  28. team_label='${{ github.event.label.name }}'
  29. team_name="${team_label:6}" # Strip the first 6 chars, which is the 'Team: ' part
  30. team_slug="${team_name// /-}" # Replace spaces with hyphens for url/slug friendliness
  31. mention_slug=$(gh api "/orgs/getsentry/teams/$team_slug" -q .slug || true)
  32. if [ "${mention_slug::1}" = "{" ]; then
  33. # Hack around https://github.com/getsentry/.github/issues/77
  34. mention_slug=""
  35. fi
  36. if [[ -z "$mention_slug" ]]; then
  37. echo "Couldn't find team mention from slug, trying the label description"
  38. team_slug=$(gh api "/repos/$GH_REPO/labels/$team_label" -q '.description')
  39. mention_slug=$(gh api "/orgs/getsentry/teams/$team_slug" -q .slug || true)
  40. if [ "${mention_slug::1}" = "{" ]; then
  41. # Hack around https://github.com/getsentry/.github/issues/77
  42. mention_slug=""
  43. fi
  44. fi
  45. if [[ -n "$mention_slug" ]]; then
  46. echo "Routing to @getsentry/$mention_slug for [triage](https://develop.sentry.dev/processing-tickets/#3-triage). ⏲️" > comment_body
  47. else
  48. echo "[Failed]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID) to route to \`${{ github.event.label.name }}\`. 😕" > comment_body
  49. echo "" >> comment_body
  50. echo "Defaulting to @getsentry/open-source for [triage](https://develop.sentry.dev/processing-tickets/#3-triage). ⏲️" >> comment_body
  51. fi
  52. gh issue comment ${{ github.event.issue.number }} --body-file comment_body