Fix GitLab API calls - use numeric project IDs
- Changed from URL-encoded paths to numeric project IDs - Added -L flag to curl to follow redirects - Improved error handling with HTTP status codes - Shows API errors with response body
This commit is contained in:
parent
b036716eb7
commit
6be6ff34f9
1 changed files with 22 additions and 6 deletions
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue