Skip to content

Commit dc68976

Browse files
feat: nudge users to enable the PR comment when github-token is missing (#163)
1 parent c4792cf commit dc68976

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

breaking/entrypoint.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,17 @@ readonly github_token="${17}"
3737
# a PR that never had changes stays comment-free).
3838
post_review_comment () {
3939
review_url="$1"
40-
[ -z "$github_token" ] && return 0
4140
pr_number=$(echo "$GITHUB_REF" | sed -n 's|refs/pull/\([0-9]*\)/merge|\1|p')
41+
if [ -z "$github_token" ]; then
42+
# No token to comment with. If we produced a review link on a PR, nudge
43+
# the user to enable the PR comment rather than failing silently (the
44+
# link is still in the job summary). This is the default for anyone who
45+
# upgraded the action version without adding github-token + permissions.
46+
if [ -n "$review_url" ] && [ -n "$pr_number" ]; then
47+
echo "::notice::oasdiff put the side-by-side review link in the job summary. To post it as a pull-request comment instead, pass 'github-token: \${{ github.token }}' to the action and grant the job 'permissions: pull-requests: write'. See https://www.oasdiff.com/docs/github-action"
48+
fi
49+
return 0
50+
fi
4251
[ -z "$pr_number" ] && return 0
4352
owner="${GITHUB_REPOSITORY%%/*}"
4453
repo="${GITHUB_REPOSITORY#*/}"

changelog/entrypoint.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,17 @@ readonly github_token="${17}"
5656
# had changes stays comment-free).
5757
post_review_comment () {
5858
review_url="$1"
59-
[ -z "$github_token" ] && return 0
6059
pr_number=$(echo "$GITHUB_REF" | sed -n 's|refs/pull/\([0-9]*\)/merge|\1|p')
60+
if [ -z "$github_token" ]; then
61+
# No token to comment with. If we produced a review link on a PR, nudge
62+
# the user to enable the PR comment rather than failing silently (the
63+
# link is still in the job summary). This is the default for anyone who
64+
# upgraded the action version without adding github-token + permissions.
65+
if [ -n "$review_url" ] && [ -n "$pr_number" ]; then
66+
echo "::notice::oasdiff put the side-by-side review link in the job summary. To post it as a pull-request comment instead, pass 'github-token: \${{ github.token }}' to the action and grant the job 'permissions: pull-requests: write'. See https://www.oasdiff.com/docs/github-action"
67+
fi
68+
return 0
69+
fi
6170
[ -z "$pr_number" ] && return 0
6271
owner="${GITHUB_REPOSITORY%%/*}"
6372
repo="${GITHUB_REPOSITORY#*/}"

0 commit comments

Comments
 (0)