diff mbox series

[1/3] request-pull: introduce display_message() function

Message ID 20211003122943.338199-2-bagasdotme@gmail.com (mailing list archive)
State New, archived
Headers show
Series request-pull: write to file option | expand

Commit Message

Bagas Sanjaya Oct. 3, 2021, 12:29 p.m. UTC
Move displaying PR message logic into display_message. While at it, use
local variable $format and $dashline to shorten argument typing to git
show.

Signed-off-by: Bagas Sanjaya <bagasdotme@gmail.com>
---
 git-request-pull.sh | 57 ++++++++++++++++++++++++++++-----------------
 1 file changed, 35 insertions(+), 22 deletions(-)
diff mbox series

Patch

diff --git a/git-request-pull.sh b/git-request-pull.sh
index 2d0e44656c..88a7a9cf0d 100755
--- a/git-request-pull.sh
+++ b/git-request-pull.sh
@@ -136,37 +136,50 @@  fi
 
 url=$(git ls-remote --get-url "$url")
 
-git show -s --format='The following changes since commit %H:
+display_message() {
+	local format
+	local dash_line
+
+	dash_line="----------------------------------------------------------------"
+	format='The following changes since commit %H:
 
   %s (%ci)
 
 are available in the Git repository at:
-' $merge_base &&
-echo "  $url $pretty_remote" &&
-git show -s --format='
-for you to fetch changes up to %H:
+'
+
+	git show -s --format="$format" $merge_base &&
+	echo "  $url $pretty_remote" &&
+	format='for you to fetch changes up to %H:
 
   %s (%ci)
+'
+	git show -s --format="
+$format
+$dash_line" $headrev &&
 
-----------------------------------------------------------------' $headrev &&
+	if test $(git cat-file -t "$head") = tag
+	then
+		git cat-file tag "$head" |
+		sed -n -e '1,/^$/d' -e '/^-----BEGIN PGP /q' -e p
+		echo
+		echo "$dash_line"
+	fi &&
 
-if test $(git cat-file -t "$head") = tag
-then
-	git cat-file tag "$head" |
-	sed -n -e '1,/^$/d' -e '/^-----BEGIN PGP /q' -e p
-	echo
-	echo "----------------------------------------------------------------"
-fi &&
+	if test -n "$branch_name"
+	then
+		echo "(from the branch description for $branch_name local branch)"
+		echo
+		git config "branch.$branch_name.description"
+		echo "$dash_line"
+	fi &&
 
-if test -n "$branch_name"
-then
-	echo "(from the branch description for $branch_name local branch)"
-	echo
-	git config "branch.$branch_name.description"
-	echo "----------------------------------------------------------------"
-fi &&
+	git shortlog ^$baserev $headrev &&
+	git diff -M --stat --summary $patch $merge_base..$headrev
+}
 
-git shortlog ^$baserev $headrev &&
-git diff -M --stat --summary $patch $merge_base..$headrev || status=1
+message=$(display_message) || status=1
+
+echo "$message"
 
 exit $status