issue-routing-helper.yml 2.3 KB

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