fix(git-hangman-lab): publish-package - handle cross-owner repo link gracefully

The link step now:
1. Extracts the actual repo owner from the git remote URL
2. Captures HTTP response status and body
3. Shows a clear warning when the repo belongs to a different owner
  (requires site admin or matching owner), instead of silently failing
This commit is contained in:
2026-04-14 19:46:31 +00:00
parent 0b0f7d2a9f
commit 436c723a2f

View File

@@ -88,9 +88,29 @@ do_docker() {
# Link package to repository
TOKEN=$(secret-mgr get-secret --key git-access-token 2>/dev/null || secret-mgr get-secret --key git)
REPO_NAME=$(basename "$REPO")
curl -s -X POST \
# Determine the actual owner of the git repository
REPO_OWNER="$OWNER"
if [[ -d "$REPO/.git" ]]; then
REMOTE_URL=$(git -C "$REPO" remote get-url origin 2>/dev/null || true)
if [[ "$REMOTE_URL" =~ git\.hangman-lab\.top/([^/]+)/ ]]; then
REPO_OWNER="${BASH_REMATCH[1]}"
fi
fi
LINK_RESP=$(curl -s -w "%{http_code}" -X POST \
-H "Authorization: token $TOKEN" \
"https://git.hangman-lab.top/api/v1/packages/${OWNER}/container/${IMAGE}/-/link/${REPO_NAME}" || true
"https://git.hangman-lab.top/api/v1/packages/${OWNER}/container/${IMAGE}/-/link/${REPO_NAME}")
LINK_STATUS="${LINK_RESP: -3}"
LINK_BODY="${LINK_RESP:0:-3}"
if [[ "$LINK_STATUS" != "200" && "$LINK_STATUS" != "201" ]]; then
if echo "$LINK_BODY" | grep -q '"message".*repository does not exist'; then
echo "Warning: repository '$REPO_NAME' is not owned by '$OWNER' — skipping link (requires site admin or matching owner)."
else
echo "Warning: package link failed (HTTP $LINK_STATUS): $LINK_BODY"
fi
fi
lock-mgr release "$LOCKFILE" "$KEY"
echo "Done: $FULL_IMAGE"