Update: 2025-05-30 09:14:57
This commit is contained in:
parent
1bf9f54c03
commit
129adb11e2
1 changed files with 22 additions and 14 deletions
|
@ -55,12 +55,8 @@ ssh-keyscan -t rsa bitbucket.org >> ~/.ssh/known_hosts 2>/dev/null || true
|
||||||
# ╰─────────────────────────────────────╯
|
# ╰─────────────────────────────────────╯
|
||||||
info "Verifying SSH access to Bitbucket..."
|
info "Verifying SSH access to Bitbucket..."
|
||||||
|
|
||||||
if ssh -T git@bitbucket.org 2>/dev/null; then
|
if ssh -T git@bitbucket.org 2>&1 | grep -q "authenticated"; then
|
||||||
info "✓ SSH access to Bitbucket verified."
|
info "✓ SSH access to Bitbucket verified."
|
||||||
elif ssh -T git@bitbucket.org 2>&1 | grep -q "successfully authenticated"; then
|
|
||||||
info "✓ SSH authentication to Bitbucket accepted."
|
|
||||||
elif ssh -T git@bitbucket.org; [[ $? == 1 ]]; then
|
|
||||||
info "✓ SSH connected — Bitbucket returned expected code 1."
|
|
||||||
else
|
else
|
||||||
warn "❌ SSH key not authorized with Bitbucket."
|
warn "❌ SSH key not authorized with Bitbucket."
|
||||||
echo "→ Visit: https://bitbucket.org/account/settings/ssh-keys/"
|
echo "→ Visit: https://bitbucket.org/account/settings/ssh-keys/"
|
||||||
|
@ -103,24 +99,36 @@ fi
|
||||||
# │ CREATE REMOTE IF NOT EXISTS │
|
# │ CREATE REMOTE IF NOT EXISTS │
|
||||||
# ╰─────────────────────────────────────╯
|
# ╰─────────────────────────────────────╯
|
||||||
REPO_EXISTS=$(curl -s -u "$BITBUCKET_USER:$APP_PASS" "$API_URL" | jq -r '.name // empty')
|
REPO_EXISTS=$(curl -s -u "$BITBUCKET_USER:$APP_PASS" "$API_URL" | jq -r '.name // empty')
|
||||||
|
|
||||||
if [ -z "$REPO_EXISTS" ]; then
|
if [ -z "$REPO_EXISTS" ]; then
|
||||||
info "Creating Bitbucket repository '$REPO_NAME'..."
|
info "Creating Bitbucket repository '$REPO_NAME'..."
|
||||||
curl -s -u "$BITBUCKET_USER:$APP_PASS" -X POST "$API_URL" \
|
CREATE_RESPONSE=$(curl -s -w "%{http_code}" -o /tmp/create_resp.txt -u "$BITBUCKET_USER:$APP_PASS" -X POST "$API_URL" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "{\"scm\": \"git\", \"is_private\": false, \"project\": {\"key\": \"~$BITBUCKET_USER\"}}" \
|
-d "{\"scm\": \"git\", \"is_private\": false}")
|
||||||
| grep -q '"uuid"' || warn "Repo may already exist or creation failed"
|
if [[ "$CREATE_RESPONSE" != "200" && "$CREATE_RESPONSE" != "201" ]]; then
|
||||||
|
cat /tmp/create_resp.txt
|
||||||
|
error "Failed to create repository (HTTP $CREATE_RESPONSE)"
|
||||||
|
fi
|
||||||
|
info "✓ Repository created."
|
||||||
else
|
else
|
||||||
info "Remote Bitbucket repo already exists."
|
info "✓ Remote Bitbucket repo already exists."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ╭─────────────────────────────────────╮
|
# ╭─────────────────────────────────────╮
|
||||||
# │ SET GIT REMOTE │
|
# │ REMOTE VALIDATION + SETUP │
|
||||||
# ╰─────────────────────────────────────╯
|
# ╰─────────────────────────────────────╯
|
||||||
if ! git remote get-url "$REMOTE_NAME" &>/dev/null; then
|
EXPECTED_REMOTE="$SSH_REMOTE"
|
||||||
git remote add "$REMOTE_NAME" "$SSH_REMOTE"
|
CURRENT_REMOTE=$(git remote get-url "$REMOTE_NAME" 2>/dev/null || echo "")
|
||||||
info "Remote set: $SSH_REMOTE"
|
|
||||||
|
if [[ "$CURRENT_REMOTE" != "$EXPECTED_REMOTE" ]]; then
|
||||||
|
if [ -n "$CURRENT_REMOTE" ]; then
|
||||||
|
warn "Removing incorrect remote: $CURRENT_REMOTE"
|
||||||
|
git remote remove "$REMOTE_NAME"
|
||||||
|
fi
|
||||||
|
info "Setting correct Bitbucket remote: $EXPECTED_REMOTE"
|
||||||
|
git remote add "$REMOTE_NAME" "$EXPECTED_REMOTE"
|
||||||
else
|
else
|
||||||
info "Remote already set: $(git remote get-url "$REMOTE_NAME")"
|
info "✓ Remote already correctly set to: $EXPECTED_REMOTE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ╭─────────────────────────────────────╮
|
# ╭─────────────────────────────────────╮
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue