[maintainer-tools] github-merge-pr: ask for confirmation before pushing to git
LEDE Commits
lede-commits at lists.infradead.org
Wed Jan 11 07:23:11 PST 2023
ansuel pushed a commit to maintainer-tools.git, branch master:
https://git.openwrt.org/191b21c81fb437935cdc2103175114b5071a3ecc
commit 191b21c81fb437935cdc2103175114b5071a3ecc
Author: Christian Marangi <ansuelsmth at gmail.com>
AuthorDate: Wed Jan 11 16:01:50 2023 +0100
github-merge-pr: ask for confirmation before pushing to git
Ask for confirmation before pushing to git. This can be useful to give
an extra and last look at the merging pull request.
Signed-off-by: Christian Marangi <ansuelsmth at gmail.com>
---
github-merge-pr.sh | 96 ++++++++++++++++++++++++++++++++----------------------
1 file changed, 57 insertions(+), 39 deletions(-)
diff --git a/github-merge-pr.sh b/github-merge-pr.sh
index bfd7e2a..f8758d3 100755
--- a/github-merge-pr.sh
+++ b/github-merge-pr.sh
@@ -15,6 +15,21 @@ BRANCH="${2:-master}"
DRY_RUN="$3"
GIT=git
+yesno() {
+ local prompt="$1"
+ local default="${2:-n}"
+ local input
+
+ while [ 1 ]; do
+ printf "%s y/n [%s] > " "$prompt" "$default"
+ read input
+ case "${input:-$default}" in
+ y*) return 0 ;;
+ n*) return 1 ;;
+ esac
+ done
+}
+
if ! command -v jq &> /dev/null; then
echo "jq could not be found! This script require jq!"
exit 1
@@ -98,48 +113,51 @@ if ! $GIT merge --ff-only $PR_USER/$PR_BRANCH; then
exit 11
fi
-echo "Pushing to openwrt git server"
-if ! $GIT push; then
- echo "Failed to push to $BRANCH but left branch as is." >&2
- exit 12
-fi
-
-echo "Deleting branch $LOCAL_PR_BRANCH"
-$GIT branch -D $LOCAL_PR_BRANCH
+if yesno "Push to openwrt $BRANCH" "y"; then
+ echo "Pushing to openwrt git server"
+ if ! $GIT push; then
+ echo "Failed to push to $BRANCH but left branch as is." >&2
+ exit 12
+ fi
-# Default close comment
-COMMENT="Thanks! Rebased on top of $BRANCH and merged!"
-
-if [ -n "$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."
- echo ""
- echo "If you do not provide a comment, the default will be: "
- echo "[$COMMENT]"
-
- echo -n "Comment > "
- read usercomment
-
- echo "Sending message to PR..."
-
- comment="${usercomment:-$COMMENT}"
- comment="${comment//\\/\\\\}"
- 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"
- then
- echo "" >&2
- echo "Something failed while sending comment to the PR via ">&2
- echo "the Github API, please review the state manually at " >&2
- echo "https://github.com/$REPO/pull/$PRID" >&2
- exit 6
+ # Default close comment
+ COMMENT="Thanks! Rebased on top of $BRANCH and merged!"
+
+ if [ -n "$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."
+ echo ""
+ echo "If you do not provide a comment, the default will be: "
+ echo "[$COMMENT]"
+
+ echo -n "Comment > "
+ read usercomment
+
+ echo "Sending message to PR..."
+
+ comment="${usercomment:-$COMMENT}"
+ comment="${comment//\\/\\\\}"
+ 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"
+ then
+ echo "" >&2
+ echo "Something failed while sending comment to the PR via ">&2
+ echo "the Github API, please review the state manually at " >&2
+ echo "https://github.com/$REPO/pull/$PRID" >&2
+ exit 6
+ fi
fi
+
+ echo -e "\n"
+ echo "The PR has been merged!"
+ echo -e "\n"
fi
-echo ""
-echo "The PR has been merged!"
+echo "Deleting branch $LOCAL_PR_BRANCH"
+$GIT branch -D $LOCAL_PR_BRANCH
exit 0
More information about the lede-commits
mailing list