Skip to content

Commit 23f7fd3

Browse files
committed
chore: add error-logging for ghn url opening
1 parent bc4e881 commit 23f7fd3

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

scripts/resolve-notification.sh

+14-7
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,20 @@ else
1919
# some notification types like ci-activity do not provide a thread
2020
github_url="https://github.com/notifications?query=is%3Aunread"
2121
else
22-
github_url=$(
23-
curl -sL -H "Accept: application/vnd.github+json" \
24-
-H "Authorization: Bearer $GITHUB_TOKEN" \
25-
-H "X-GitHub-Api-Version: 2022-11-28" \
26-
"$api_url" |
27-
grep --max-count=1 '"html_url"' | cut -d '"' -f 4 # skip `jq` dependency
28-
)
22+
response=$(curl -sL -H "Accept: application/vnd.github+json" \
23+
-H "Authorization: Bearer $GITHUB_TOKEN" \
24+
-H "X-GitHub-Api-Version: 2022-11-28" \
25+
"$api_url")
26+
# using `grep` here avoids `jq` dependency
27+
github_url=$(echo "$response" | grep --max-count=1 '"html_url"' | cut -d '"' -f4)
28+
29+
# VALIDATE
30+
if [[ -z "$github_url" ]]; then
31+
err_msg="ERROR: could not get url to open. Check debugging log"
32+
echo -n "$err_msg" # pass for Alfred notification
33+
print "$err_msg\nGithub response: $response" >&2 # pass to console
34+
return 1
35+
fi
2936
fi
3037

3138
if [[ "$mode" == "open" ]]; then

0 commit comments

Comments
 (0)