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
Outdated
Review

I don't want this to be in the code. this should be a custom configurable. don't we have repos.json or anything? or servers.json? I forget. the place where we configure which instances are we using (github, gitlab, selfhosted gitea, etc)

I don't want this to be in the code. this should be a custom configurable. don't we have repos.json or anything? or servers.json? I forget. the place where we configure which instances are we using (github, gitlab, selfhosted gitea, etc)
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|')
Outdated
Review

this is totally killing the feature in a way that the git instance should be registered here wont work in the open internet

this is totally killing the feature in a way that the git instance should be registered here wont work in the open internet
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,30 +292,17 @@ 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
echo "closed"
elif [ "$state" = "open" ]; then
echo "open"
else
echo "unknown"
fi
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
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
echo "unknown"
fi
}