diff --git a/scripts/monitor-deploy.sh b/scripts/monitor-deploy.sh index 56abce52..82521c23 100755 --- a/scripts/monitor-deploy.sh +++ b/scripts/monitor-deploy.sh @@ -78,14 +78,14 @@ get_project_info() { case $project in app) - PROJECT_ID="graham%2Ftowerops" # URL-encoded graham/towerops + PROJECT_ID="77257437" # Numeric ID for graham/towerops PROJECT_NAME="Towerops" K8S_NAMESPACE="towerops" K8S_DEPLOYMENT="towerops" HAS_K8S=true ;; agent) - PROJECT_ID="towerops%2Ftowerops-agent" # URL-encoded towerops/towerops-agent + PROJECT_ID="63766041" # Numeric ID for towerops/towerops-agent PROJECT_NAME="Towerops Agent" HAS_K8S=false ;; @@ -98,8 +98,19 @@ get_project_info() { gitlab_api() { local endpoint=$1 - curl -s -H "PRIVATE-TOKEN: $GITLAB_ACCESS_TOKEN" \ - "https://gitlab.com/api/v4${endpoint}" + local response=$(curl -sL -w "\n%{http_code}" -H "PRIVATE-TOKEN: $GITLAB_ACCESS_TOKEN" \ + "https://gitlab.com/api/v4${endpoint}") + + local http_code=$(echo "$response" | tail -n1) + local body=$(echo "$response" | sed '$d') + + if [ "$http_code" != "200" ]; then + echo -e "${RED}API Error (HTTP $http_code):${NC}" >&2 + echo "$body" >&2 + return 1 + fi + + echo "$body" } get_current_branch() { @@ -108,8 +119,13 @@ get_current_branch() { get_latest_pipeline() { local branch=$1 - gitlab_api "/projects/${PROJECT_ID}/pipelines?ref=${branch}&per_page=1" | \ - jq -r '.[0] // empty' + local response=$(gitlab_api "/projects/${PROJECT_ID}/pipelines?ref=${branch}&per_page=1") + + if [ $? -ne 0 ] || [ -z "$response" ]; then + return 1 + fi + + echo "$response" | jq -r '.[0] // empty' } get_pipeline_jobs() {