fix(worktree-lifecycle): use GIT_SERVERS config for check_pr_status
- Extract hostname from pr_url instead of hardcoding domains - Look up server base URL from GIT_SERVERS config - Append /api/v1 to derive API URL (configurable per server) - Works with any server configured in GIT_SERVERS
This commit is contained in:
@@ -266,20 +266,25 @@ check_pr_status() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local api_url=""
|
local hostname=$(echo "$pr_url" | sed -E 's|https://([^/]+)/.*|\1|')
|
||||||
local token=""
|
|
||||||
|
|
||||||
if [[ "$pr_url" =~ git\.fbrns\.co ]]; then
|
local server_base="${GIT_SERVERS[$hostname]:-}"
|
||||||
api_url=$(echo "$pr_url" | sed -E 's|https://git\.fbrns\.co/([^/]+)/([^/]+)/pulls/([0-9]+)|https://git.fbrns.co/api/v1/repos/\1/\2/pulls/\3|')
|
if [ -z "$server_base" ]; then
|
||||||
token="${GITEA_TOKEN:-}"
|
|
||||||
elif [[ "$pr_url" =~ github\.com ]]; then
|
|
||||||
api_url=$(echo "$pr_url" | sed -E 's|https://github\.com/([^/]+)/([^/]+)/pulls/([0-9]+)|https://api.github.com/repos/\1/\2/pulls/\3|')
|
|
||||||
token="${GITHUB_TOKEN:-}"
|
|
||||||
else
|
|
||||||
echo "unknown_server"
|
echo "unknown_server"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local api_base="${server_base}/api/v1"
|
||||||
|
|
||||||
|
local api_url=$(echo "$pr_url" | sed -E 's|https://[^/]+/([^/]+)/([^/]+)/(pulls|merge_requests)/([0-9]+)|'"${api_base}"'/repos/\1/\2/\3/\4|')
|
||||||
|
|
||||||
|
local token=""
|
||||||
|
if [[ "$hostname" == "github.com" ]]; then
|
||||||
|
token="${GITHUB_TOKEN:-}"
|
||||||
|
else
|
||||||
|
token="${GITEA_TOKEN:-}"
|
||||||
|
fi
|
||||||
|
|
||||||
local response
|
local response
|
||||||
if [ -n "$token" ]; then
|
if [ -n "$token" ]; then
|
||||||
response=$(curl -s -H "Authorization: token $token" "$api_url" 2>/dev/null || echo "{}")
|
response=$(curl -s -H "Authorization: token $token" "$api_url" 2>/dev/null || echo "{}")
|
||||||
@@ -287,9 +292,9 @@ check_pr_status() {
|
|||||||
response=$(curl -s "$api_url" 2>/dev/null || echo "{}")
|
response=$(curl -s "$api_url" 2>/dev/null || echo "{}")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$pr_url" =~ git\.fbrns\.co ]]; then
|
|
||||||
local state=$(echo "$response" | python3 -c "import json, sys; d=json.load(sys.stdin); print(d.get('state', 'unknown'))" 2>/dev/null || echo "unknown")
|
local state=$(echo "$response" | python3 -c "import json, sys; d=json.load(sys.stdin); print(d.get('state', 'unknown'))" 2>/dev/null || echo "unknown")
|
||||||
local merged=$(echo "$response" | python3 -c "import json, sys; d=json.load(sys.stdin); print('true' if d.get('merged', False) else 'false')" 2>/dev/null || echo "false")
|
local merged=$(echo "$response" | python3 -c "import json, sys; d=json.load(sys.stdin); print('true' if d.get('merged', False) else 'false')" 2>/dev/null || echo "false")
|
||||||
|
|
||||||
if [ "$merged" = "true" ]; then
|
if [ "$merged" = "true" ]; then
|
||||||
echo "merged"
|
echo "merged"
|
||||||
elif [ "$state" = "closed" ]; then
|
elif [ "$state" = "closed" ]; then
|
||||||
@@ -299,19 +304,6 @@ check_pr_status() {
|
|||||||
else
|
else
|
||||||
echo "unknown"
|
echo "unknown"
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
local state=$(echo "$response" | python3 -c "import json, sys; d=json.load(sys.stdin); print(d.get('state', 'unknown'))" 2>/dev/null || echo "unknown")
|
|
||||||
local merged=$(echo "$response" | python3 -c "import json, sys; d=json.load(sys.stdin); print('true' if d.get('merged', False) else 'false')" 2>/dev/null || echo "false")
|
|
||||||
if [ "$merged" = "true" ]; then
|
|
||||||
echo "merged"
|
|
||||||
elif [ "$state" = "closed" ]; then
|
|
||||||
echo "closed"
|
|
||||||
elif [ "$state" = "open" ]; then
|
|
||||||
echo "open"
|
|
||||||
else
|
|
||||||
echo "unknown"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_ref_to_filename() {
|
issue_ref_to_filename() {
|
||||||
|
|||||||
Reference in New Issue
Block a user