fix: use /pulls instead of /pulls/pinned (#4)
This commit was merged in pull request #4.
This commit is contained in:
@@ -52,6 +52,7 @@ Manage pull requests on git.hangman-lab.top.
|
||||
{baseDir}/scripts/git-ctrl pr list <repo-local-path>
|
||||
{baseDir}/scripts/git-ctrl pr commits <repo-local-path> <pr-index>
|
||||
{baseDir}/scripts/git-ctrl pr merge <repo-local-path> <pr-index> <do> [commit-id] [title] [message]
|
||||
{baseDir}/scripts/git-ctrl pr show <repo-local-path> <pr-index>
|
||||
```
|
||||
|
||||
> **Note**: The access token will be automatically generated if not found.
|
||||
|
||||
@@ -11,7 +11,7 @@ if [[ $# -eq 0 ]]; then
|
||||
echo " check-git-cred Verify git credentials"
|
||||
echo " create-git-account Create a new git account"
|
||||
echo " create-repo Create a new repository"
|
||||
echo " pr Pull request operations (create/list/commits/merge)"
|
||||
echo " pr Pull request operations (create/list/commits/merge/show)"
|
||||
echo " generate-access-token Generate access token for current user"
|
||||
echo " link-keycloak Link Keycloak account with Gitea"
|
||||
echo " repo-add-collaborators Add collaborator to repository"
|
||||
|
||||
@@ -97,7 +97,7 @@ cmd_list() {
|
||||
|
||||
echo "Listing PRs for: $OWNER/$REPO_NAME"
|
||||
|
||||
RESPONSE=$(curl -s -X GET "https://git.hangman-lab.top/api/v1/repos/${OWNER}/${REPO_NAME}/pulls/pinned" \
|
||||
RESPONSE=$(curl -s -X GET "https://git.hangman-lab.top/api/v1/repos/${OWNER}/${REPO_NAME}/pulls" \
|
||||
-H 'accept: application/json' \
|
||||
-H "Authorization: token ${token}")
|
||||
|
||||
@@ -134,6 +134,40 @@ 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 '{
|
||||
id, number, title, body, state, draft, mergeable, merged,
|
||||
additions, deletions, changed_files, comments,
|
||||
html_url, diff_url, patch_url,
|
||||
labels,
|
||||
milestone,
|
||||
base: .base | {label, ref, sha},
|
||||
head: .head | {label, ref, sha},
|
||||
merge_base,
|
||||
created_at, updated_at, closed_at
|
||||
}'
|
||||
}
|
||||
|
||||
# Subcommand: merge
|
||||
cmd_merge() {
|
||||
local repo_path="$1"
|
||||
@@ -180,27 +214,61 @@ cmd_merge() {
|
||||
merge_when_checks_succeed: true
|
||||
}')
|
||||
|
||||
RESPONSE=$(curl -s -X POST "https://git.hangman-lab.top/api/v1/repos/${OWNER}/${REPO_NAME}/pulls/${pr_index}/merge" \
|
||||
TEMP_FILE=$(mktemp)
|
||||
HTTP_CODE=$(curl -s -o "$TEMP_FILE" -w "%{http_code}" -X POST "https://git.hangman-lab.top/api/v1/repos/${OWNER}/${REPO_NAME}/pulls/${pr_index}/merge" \
|
||||
-H 'accept: application/json' \
|
||||
-H 'Content-Type: application/json' \
|
||||
-H "Authorization: token ${token}" \
|
||||
-d "$json")
|
||||
|
||||
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
|
||||
RESPONSE=$(cat "$TEMP_FILE")
|
||||
rm -f "$TEMP_FILE"
|
||||
|
||||
MERGED=$(echo "$RESPONSE" | jq -r '.merged')
|
||||
|
||||
if [[ "$MERGED" == "true" ]]; then
|
||||
echo "Pull request merged successfully!"
|
||||
else
|
||||
echo "Error: Failed to merge pull request"
|
||||
echo "$RESPONSE" | jq '.'
|
||||
exit 1
|
||||
fi
|
||||
case "$HTTP_CODE" in
|
||||
200)
|
||||
MERGED=$(echo "$RESPONSE" | jq -r '.merged')
|
||||
if [[ "$MERGED" == "true" ]]; then
|
||||
echo "merge success"
|
||||
else
|
||||
echo "merge failed"
|
||||
echo "$RESPONSE" | jq '.'
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
409)
|
||||
ERROR_MSG=$(echo "$RESPONSE" | jq -r '.message // "Conflicting changes"')
|
||||
echo "Error [$HTTP_CODE]: $ERROR_MSG"
|
||||
exit 1
|
||||
;;
|
||||
404)
|
||||
ERROR_MSG=$(echo "$RESPONSE" | jq -r '.message // "Not found"')
|
||||
echo "Error [$HTTP_CODE]: $ERROR_MSG"
|
||||
exit 1
|
||||
;;
|
||||
423)
|
||||
ERROR_MSG=$(echo "$RESPONSE" | jq -r '.message // "Repository is archived"')
|
||||
echo "Error [$HTTP_CODE]: $ERROR_MSG"
|
||||
exit 1
|
||||
;;
|
||||
405)
|
||||
echo "merge failed check the pr status"
|
||||
# Fetch PR details to show merge status
|
||||
PR_INFO=$(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}")
|
||||
echo "$PR_INFO" | jq '{mergeable: .mergeable, head_sha: .head.sha, base_ref: .base.ref, head_ref: .head.ref}'
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
if echo "$RESPONSE" | jq -e '.message' >/dev/null 2>&1; then
|
||||
ERROR_MSG=$(echo "$RESPONSE" | jq -r '.message')
|
||||
echo "Error [$HTTP_CODE]: $ERROR_MSG"
|
||||
else
|
||||
echo "Error [$HTTP_CODE]: Unknown error"
|
||||
fi
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Usage
|
||||
@@ -214,6 +282,7 @@ usage() {
|
||||
echo " commits <repo-local-path> <pr-index> List commits in a PR"
|
||||
echo " merge <repo-local-path> <pr-index> <do> [commit-id] [title] [message]"
|
||||
echo " Merge a pull request"
|
||||
echo " show <repo-local-path> <pr-index> Show PR details"
|
||||
echo ""
|
||||
echo " <do> can be: merge, squash, rebase, manually-merged"
|
||||
exit 2
|
||||
@@ -256,6 +325,13 @@ case "$COMMAND" in
|
||||
fi
|
||||
cmd_merge "$@"
|
||||
;;
|
||||
show)
|
||||
if [[ $# -lt 2 ]]; then
|
||||
echo "Error: show requires <repo-local-path> <pr-index>"
|
||||
exit 2
|
||||
fi
|
||||
cmd_show "$@"
|
||||
;;
|
||||
*)
|
||||
echo "Error: Unknown command: $COMMAND"
|
||||
usage
|
||||
|
||||
Reference in New Issue
Block a user