diff options
| author | Christian Marangi | 2024-04-29 10:40:17 +0000 |
|---|---|---|
| committer | Christian Marangi | 2024-04-29 10:46:26 +0000 |
| commit | a598bb4775856efbc62de7ce9959c4f44bd8dbbb (patch) | |
| tree | 237ec556b557925f37e349b59dfee910c591f052 | |
| parent | db54a345e510b88f7f0f6623428f5198efe50396 (diff) | |
| download | maintainer-tools-a598bb4775856efbc62de7ce9959c4f44bd8dbbb.tar.gz | |
github-merge-pr: move script config to separate file
Move script config to separate file, .config, to make it easier to
update the script and pull changes without having to rebase or re-set
values.
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
| -rw-r--r-- | .gitignore | 1 | ||||
| -rwxr-xr-x | github-merge-pr.sh | 21 |
2 files changed, 15 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2ec2572 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.config
\ No newline at end of file diff --git a/github-merge-pr.sh b/github-merge-pr.sh index 4a61a3f..64cd6bf 100755 --- a/github-merge-pr.sh +++ b/github-merge-pr.sh @@ -12,7 +12,10 @@ # REPO_NAME is optional and defaults to openwrt. It does # describe the repository name to use to pull PR info from. +# Script .config variables # Github repository owner or organization name. +# By default set to openwrt, set this line in .config to overwrite +# the default value. GITHUB_REPO_OWNER="openwrt" # Your repository token, generate this token at your profile page: @@ -20,10 +23,14 @@ GITHUB_REPO_OWNER="openwrt" # - Click on "Generate new token" # - Enter a description, e.g. "pr.sh" and pick the "repo" scope # - Hit "Generate token" -#TOKEN="d41d8cd98f00b204e9800998ecf8427e" +# Set this line in .config to provide a GITHUB_TOKEN and add comments +#GITHUB_TOKEN="d41d8cd98f00b204e9800998ecf8427e" # -# Uncomment this line to use SSH key to rebase PR branch -# USE_SSH=1 +# Set this line in .config to use SSH key to rebase PR branch +# GITHUB_USE_SSH=1 + +# Everything in .config will overwrite the default values set up +[ -f .config ] && source .config PRID="$1" BRANCH="${2:-main}" @@ -93,7 +100,7 @@ fi PR_USER="$(echo "$PR_INFO" | jq -r ".head.user.login")" PR_BRANCH="$(echo "$PR_INFO" | jq -r ".head.ref")" LOCAL_PR_BRANCH="$PR_BRANCH"-"$PR_USER" -if [ "$USE_SSH" = "1" ]; then +if [ "$GITHUB_USE_SSH" = "1" ]; then PR_REPO="$(echo "$PR_INFO" | jq -r ".head.repo.ssh_url")" else PR_REPO="$(echo "$PR_INFO" | jq -r ".head.repo.html_url")" @@ -171,7 +178,7 @@ else # Default close comment COMMENT="Thanks! Rebased on top of $BRANCH and merged!" - if [ -n "$TOKEN" ] && [ -z "$DRY_RUN" ]; then + if [ -n "$GITHUB_TOKEN" ] && [ -z "$DRY_RUN" ]; then echo "" echo "Enter a comment and hit <enter> to close the PR at Github automatically now." echo "Hit <ctrl>-<c> to exit." @@ -189,8 +196,8 @@ else comment="${comment//\"/\\\"}" comment="$(printf '{"body":"%s"}' "$comment")" - if ! curl -s -o /dev/null -w "%{http_code} %{url_effective}\\n" --user "$TOKEN:x-oauth-basic" --request POST --data "$comment" "https://api.github.com/repos/$REPO/issues/$PRID/comments" || \ - ! curl -s -o /dev/null -w "%{http_code} %{url_effective}\\n" --user "$TOKEN:x-oauth-basic" --request PATCH --data '{"state":"closed"}' "https://api.github.com/repos/$REPO/pulls/$PRID" + if ! curl -s -o /dev/null -w "%{http_code} %{url_effective}\\n" --user "$GITHUB_TOKEN:x-oauth-basic" --request POST --data "$comment" "https://api.github.com/repos/$REPO/issues/$PRID/comments" || \ + ! curl -s -o /dev/null -w "%{http_code} %{url_effective}\\n" --user "$GITHUB_TOKEN:x-oauth-basic" --request PATCH --data '{"state":"closed"}' "https://api.github.com/repos/$REPO/pulls/$PRID" then echo "" >&2 echo "Something failed while sending comment to the PR via ">&2 |