diff --git a/git-hangman-lab/scripts/pr b/git-hangman-lab/scripts/pr index 48e8a7e..0a1ab72 100755 --- a/git-hangman-lab/scripts/pr +++ b/git-hangman-lab/scripts/pr @@ -134,6 +134,30 @@ cmd_commits() { echo "$RESPONSE" | jq -r '.[] | "\(.sha[0:7])\t\(.commit.message | split("\n")[0])"' 2>/dev/null || echo "$RESPONSE" } +# Subcommand: show +cmd_show() { + local repo_path="$1" + local pr_index="$2" + + get_repo_info "$repo_path" + local token + token="$(ensure_token)" + + echo "Showing PR #$pr_index in: $OWNER/$REPO_NAME" + + RESPONSE=$(curl -s -X GET "https://git.hangman-lab.top/api/v1/repos/${OWNER}/${REPO_NAME}/pulls/${pr_index}" \ + -H 'accept: application/json' \ + -H "Authorization: token ${token}") + + if echo "$RESPONSE" | jq -e '.message' >/dev/null 2>&1; then + ERROR_MSG=$(echo "$RESPONSE" | jq -r '.message') + echo "Error: $ERROR_MSG" + exit 1 + fi + + echo "$RESPONSE" | jq '.' +} + # Subcommand: merge cmd_merge() { local repo_path="$1" @@ -194,9 +218,9 @@ cmd_merge() { 200) MERGED=$(echo "$RESPONSE" | jq -r '.merged') if [[ "$MERGED" == "true" ]]; then - echo "Pull request merged successfully!" + echo "merge success" else - echo "Error: Failed to merge pull request" + echo "merge failed" echo "$RESPONSE" | jq '.' exit 1 fi @@ -217,7 +241,7 @@ cmd_merge() { exit 1 ;; 405) - echo "$RESPONSE" | jq -r '.message' + echo "merge failed check the pr status" exit 1 ;; *) @@ -243,6 +267,7 @@ usage() { echo " commits List commits in a PR" echo " merge [commit-id] [title] [message]" echo " Merge a pull request" + echo " show Show PR details" echo "" echo " can be: merge, squash, rebase, manually-merged" exit 2 @@ -285,6 +310,13 @@ case "$COMMAND" in fi cmd_merge "$@" ;; + show) + if [[ $# -lt 2 ]]; then + echo "Error: show requires " + exit 2 + fi + cmd_show "$@" + ;; *) echo "Error: Unknown command: $COMMAND" usage