Support git credential store fallback for Gitea API auth
This commit is contained in:
24
gp
24
gp
@@ -482,7 +482,7 @@ show_status_and_confirm() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Function to extract Gitea API URL and token from git remote
|
# Function to extract Gitea API URL and token from git remote
|
||||||
# Returns: sets GITEA_API_BASE and GITEA_API_TOKEN, or returns 1
|
# Returns: sets GITEA_API_BASE and GITEA_AUTH_HEADER, or returns 1
|
||||||
parse_gitea_remote() {
|
parse_gitea_remote() {
|
||||||
local remote_url
|
local remote_url
|
||||||
remote_url=$(git remote get-url origin 2>/dev/null) || return 1
|
remote_url=$(git remote get-url origin 2>/dev/null) || return 1
|
||||||
@@ -509,10 +509,26 @@ parse_gitea_remote() {
|
|||||||
|
|
||||||
# Use GITEA_TOKEN env var if no token in URL
|
# Use GITEA_TOKEN env var if no token in URL
|
||||||
[ -z "$token" ] && token="${GITEA_TOKEN:-}"
|
[ -z "$token" ] && token="${GITEA_TOKEN:-}"
|
||||||
|
|
||||||
|
# Fall back to git credential store
|
||||||
|
if [ -z "$token" ]; then
|
||||||
|
local cred_out
|
||||||
|
cred_out=$(printf 'protocol=https\nhost=%s\n\n' "$host" | git credential fill 2>/dev/null) || true
|
||||||
|
local cred_user cred_pass
|
||||||
|
cred_user=$(echo "$cred_out" | grep '^username=' | cut -d= -f2-)
|
||||||
|
cred_pass=$(echo "$cred_out" | grep '^password=' | cut -d= -f2-)
|
||||||
|
if [ -n "$cred_user" ] && [ -n "$cred_pass" ]; then
|
||||||
|
GITEA_AUTH_HEADER="Basic $(printf '%s:%s' "$cred_user" "$cred_pass" | base64)"
|
||||||
|
GITEA_API_BASE="https://${host}/api/v1/repos/${owner}/${repo}"
|
||||||
|
GITEA_HTML_BASE="https://${host}/${owner}/${repo}"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
[ -z "$token" ] && return 1
|
[ -z "$token" ] && return 1
|
||||||
|
|
||||||
|
GITEA_AUTH_HEADER="token $token"
|
||||||
GITEA_API_BASE="https://${host}/api/v1/repos/${owner}/${repo}"
|
GITEA_API_BASE="https://${host}/api/v1/repos/${owner}/${repo}"
|
||||||
GITEA_API_TOKEN="$token"
|
|
||||||
GITEA_HTML_BASE="https://${host}/${owner}/${repo}"
|
GITEA_HTML_BASE="https://${host}/${owner}/${repo}"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@@ -566,7 +582,7 @@ wait_for_workflow() {
|
|||||||
|
|
||||||
# Poll API for the run
|
# Poll API for the run
|
||||||
local response
|
local response
|
||||||
response=$(curl -sf "${GITEA_API_BASE}/actions/runs?limit=5" -H "Authorization: token ${GITEA_API_TOKEN}" 2>/dev/null) || true
|
response=$(curl -sf "${GITEA_API_BASE}/actions/runs?limit=5" -H "Authorization: ${GITEA_AUTH_HEADER}" 2>/dev/null) || true
|
||||||
|
|
||||||
if [ -n "$response" ]; then
|
if [ -n "$response" ]; then
|
||||||
# Find the run matching our commit SHA
|
# Find the run matching our commit SHA
|
||||||
@@ -591,7 +607,7 @@ for r in d.get('workflow_runs', []):
|
|||||||
|
|
||||||
# Fetch per-job status
|
# Fetch per-job status
|
||||||
local jobs_response
|
local jobs_response
|
||||||
jobs_response=$(curl -sf "${GITEA_API_BASE}/actions/runs/${run_id}/jobs" -H "Authorization: token ${GITEA_API_TOKEN}" 2>/dev/null) || true
|
jobs_response=$(curl -sf "${GITEA_API_BASE}/actions/runs/${run_id}/jobs" -H "Authorization: ${GITEA_AUTH_HEADER}" 2>/dev/null) || true
|
||||||
|
|
||||||
# Clear previous output
|
# Clear previous output
|
||||||
local i
|
local i
|
||||||
|
|||||||
Reference in New Issue
Block a user