Skip to content

Commit 33e9bef

Browse files
authored
Improve error handling around gh api (#79)
1 parent 21f67d6 commit 33e9bef

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

.github/workflows/issue-routing-helper.yml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,37 @@ jobs:
1919
!contains(github.event.issue.labels.*.name, 'Status: In Progress')
2020
steps:
2121
- name: "Ensure a single 'Team: *' label with 'Status: Untriaged'"
22+
env:
23+
team_label: ${{ github.event.label.name }}
24+
issue_number: ${{ github.event.issue.number }}
2225
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'
26+
labels_to_remove="$(gh api --paginate "/repos/$GH_REPO/labels" | jq -r --arg label_name "$team_label" '[.[].name | select((startswith("Team: ") or startswith("Status: ")) and . != $label_name and . != "Status: Untriaged")] | join(",")')
27+
gh issue edit "$issue_number" --remove-label "$labels_to_remove" --add-label "${team_label},Status: Untriaged"
2528
- name: "Mention/ping assigned team for triage"
29+
env:
30+
team_label: ${{ github.event.label.name }}
31+
issue_number: ${{ github.event.issue.number }}
2632
run: |
2733
# Get team label mention name:
28-
team_label='${{ github.event.label.name }}'
2934
team_name="${team_label:6}" # Strip the first 6 chars, which is the 'Team: ' part
3035
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
36+
if ! mention_slug="$(gh api "/orgs/getsentry/teams/$team_slug" -q .slug)"; then
3437
mention_slug=""
3538
fi
3639
3740
if [[ -z "$mention_slug" ]]; then
3841
echo "Couldn't find team mention from slug, trying the label description"
39-
team_slug=$(gh api "/repos/$GH_REPO/labels/$team_label" -q '.description')
40-
mention_slug=$(gh api "/orgs/getsentry/teams/$team_slug" -q .slug || true)
41-
if [ "${mention_slug::1}" = "{" ]; then
42-
# Hack around https://github.com/getsentry/.github/issues/77
42+
team_slug="$(gh api "/repos/$GH_REPO/labels/$team_label" -q '.description')"
43+
if ! mention_slug="$(gh api "/orgs/getsentry/teams/$team_slug" -q .slug)"; then
4344
mention_slug=""
4445
fi
4546
fi
4647
4748
if [[ -n "$mention_slug" ]]; then
4849
echo "Routing to @getsentry/$mention_slug for [triage](https://develop.sentry.dev/processing-tickets/#3-triage). ⏲️" > comment_body
4950
else
50-
echo "[Failed]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID) to route to \`${{ github.event.label.name }}\`. 😕" > comment_body
51+
echo "[Failed]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID) to route to \`$team_label\`. 😕" > comment_body
5152
echo "" >> comment_body
5253
echo "Defaulting to @getsentry/open-source for [triage](https://develop.sentry.dev/processing-tickets/#3-triage). ⏲️" >> comment_body
5354
fi
54-
gh issue comment ${{ github.event.issue.number }} --body-file comment_body
55+
gh issue comment "$issue_number" --body-file comment_body

0 commit comments

Comments
 (0)