Files
stack/packages/mosaic/framework/tools/woodpecker/_lib.sh
Hermes Agent b90aec2024
Some checks failed
ci/woodpecker/push/ci Pipeline was canceled
ci/woodpecker/pr/ci Pipeline was canceled
fix(framework/tools): wrapper hardening — TLS validation, cred-path fallback, no-CI fast-exit (#550)
F-03: validate TLS by default. New _mosaic_tls_opt helper in _lib/credentials.sh
returns -k only for private-network IP literals (trusted LAN) or an explicit
MOSAIC_INSECURE_TLS opt-in; generic mosaic_http/_post/_patch helpers now use
`curl -sS $_tls` instead of `curl -sk`. Woodpecker scripts (_lib.sh,
pipeline-status/list/trigger.sh) talk only to the two public/valid CI hosts, so
`-sk` is changed to `-sS` (straight -k removal, no helper).

F-02: credentials.sh resolves MOSAIC_CREDENTIALS_FILE via a fallback chain —
env first, then ~/.config/mosaic/credentials.json, then the legacy
~/src/jarvis-brain/credentials.json retained as final fallback so the running
fleet keeps working.

F-06: pr-ci-wait.sh distinguishes a genuine no-CI condition (empty state AND no
statuses) as a new `no-status` state and fast-exits 0 after 3 consecutive empty
polls with a clear "no CI configured" message. Repos that DO have pipelines are
unaffected — any pipeline signal resets the streak and pending still waits.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kt2D8TsnDwhtzEAPijsNmR
2026-06-18 14:02:43 -05:00

51 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# _lib.sh — Shared helpers for Woodpecker CI tool scripts
#
# Usage: source "$(dirname "${BASH_SOURCE[0]}")/_lib.sh"
#
# Requires: WOODPECKER_URL and WOODPECKER_TOKEN to be set (via load_credentials)
# Resolve owner/repo name to numeric repo ID (required by Woodpecker v3 API)
# Usage: REPO_ID=$(wp_resolve_repo_id "owner/repo")
wp_resolve_repo_id() {
local full_name="$1"
local response http_code body repo_id
response=$(curl -sS -w "\n%{http_code}" \
-H "Authorization: Bearer $WOODPECKER_TOKEN" \
"${WOODPECKER_URL}/api/repos/lookup/${full_name}")
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
if [[ "$http_code" != "200" ]]; then
echo "Error: Failed to look up repo '${full_name}' (HTTP $http_code)" >&2
if echo "$body" | jq -e '.message' &>/dev/null; then
echo " $(echo "$body" | jq -r '.message')" >&2
fi
return 1
fi
repo_id=$(echo "$body" | jq -r '.id // empty')
if [[ -z "$repo_id" ]]; then
echo "Error: Repo lookup returned no ID for '${full_name}'" >&2
return 1
fi
echo "$repo_id"
}
# Auto-detect repo name from git remote origin
# Usage: REPO=$(wp_detect_repo)
wp_detect_repo() {
local remote_url
remote_url=$(git remote get-url origin 2>/dev/null || true)
if [[ -n "$remote_url" ]]; then
echo "$remote_url" | sed -E 's|\.git$||' | sed -E 's|.*[:/]([^/]+/[^/]+)$|\1|'
else
echo "Error: -r owner/repo required (not in a git repository)" >&2
return 1
fi
}