feat(worktree-lifecycle): add PR tracking and safe destroy #138

Merged
shoko merged 4 commits from feat/worktree-lifecycle into main 2026-04-05 06:00:15 +02:00
Showing only changes of commit 3107dbf1e5 - Show all commits

View File

@@ -266,20 +266,25 @@ check_pr_status() {
return 1
fi
local api_url=""
local token=""
local hostname=$(echo "$pr_url" | sed -E 's|https://([^/]+)/.*|\1|')
if [[ "$pr_url" =~ git\.fbrns\.co ]]; then
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|')
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
local server_base="${GIT_SERVERS[$hostname]:-}"
if [ -z "$server_base" ]; then
echo "unknown_server"
return 1
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
if [ -n "$token" ]; then
response=$(curl -s -H "Authorization: token $token" "$api_url" 2>/dev/null || echo "{}")
Review

same with this, I dont want to be hardcoded here the domain. it should be configurable in a way user could always add later, by not changing this script

same with this, I dont want to be hardcoded here the domain. it should be configurable in a way user could always add later, by not changing this script
@@ -287,9 +292,9 @@ check_pr_status() {
response=$(curl -s "$api_url" 2>/dev/null || echo "{}")
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 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
@@ -299,19 +304,6 @@ check_pr_status() {
else
echo "unknown"
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() {