Skip to content

Commit

Permalink
fix the issue that sync_pr.sh fails to work when TEST is unset (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oreoxmt authored Nov 29, 2023
1 parent 7ab99e6 commit f2b63f7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sync_pr.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Sync a PR
name: Sync documentation changes from a PR to the preview branch

on:
push:
Expand Down
12 changes: 5 additions & 7 deletions sync_pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,28 @@
# 1. Install jq
# 2. Set the GITHUB_TOKEN environment variable

set -e

test -n "$TEST" && set -x
set -ex

check_prerequisites() {
# Verify if jq is installed and GITHUB_TOKEN is set.
which jq &>/dev/null || (echo "Error: jq is required but not installed. You can download and install jq from <https://stedolan.github.io/jq/download/>." && exit 1)

test -n "$TEST" && set +x
set +x

test -n "$GITHUB_TOKEN" || (echo "Error: GITHUB_TOKEN (repo scope) is required but not set." && exit 1)

test -n "$TEST" && set -x
set -x
}

get_pr_base_branch() {
# Get the base branch of a PR using GitHub API <https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request>
test -n "$TEST" && set +x
set +x

BASE_BRANCH=$(curl -fsSL -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/pulls/$PR_NUMBER" |
jq -r '.base.ref')

test -n "$TEST" && set -x
set -x

# Ensure that BASE_BRANCH is not empty
test -n "$BASE_BRANCH" || (echo "Error: Cannot get BASE_BRANCH." && exit 1)
Expand Down

0 comments on commit f2b63f7

Please sign in to comment.