#!/bin/bash set -euo pipefail # ── Colors ─────────────────────────────────────────────────────────── RED='\033[0;31m' YELLOW='\033[1;33m' NC='\033[0m' # ── Logging ────────────────────────────────────────────────────────── log_error() { printf "${RED}[ERR]${NC} %s\n" "$*" >&2; } log_warn() { printf "${YELLOW}[WARN]${NC} %s\n" "$*" >&2; } # ── Usage ──────────────────────────────────────────────────────────── usage() { cat </dev/null; then log_error "Required command not found: ${cmd}" exit 1 fi done # ── Parse arguments ────────────────────────────────────────────────── GITLAB_URL="https://git.mws-team.ru" TOKEN_FILE="" translated=() while (( $# )); do case "$1" in --help) translated+=("-h"); shift ;; --token-file=*) translated+=("-t" "${1#*=}"); shift ;; --gitlab-url=*) translated+=("-g" "${1#*=}"); shift ;; --) translated+=("--"); shift; translated+=("$@"); break ;; *) translated+=("$1"); shift ;; esac done set -- "${translated[@]}" while getopts ":ht:g:" opt; do case "$opt" in h) usage ;; t) TOKEN_FILE="$OPTARG" ;; g) GITLAB_URL="$OPTARG" ;; :) log_error "Missing argument for -${OPTARG}"; usage ;; \?) log_error "Invalid option: -${OPTARG}"; usage ;; esac done shift $((OPTIND - 1)) # Positional argument: project ID PROJECT_ID="${1:-}" # ── Validate inputs ───────────────────────────────────────────────── [[ -z "$TOKEN_FILE" ]] && { log_error "Missing --token-file"; usage; } [[ ! -f "$TOKEN_FILE" ]] && { log_error "Token file not found: ${TOKEN_FILE}"; exit 1; } [[ -z "$PROJECT_ID" ]] && { log_error "Missing PROJECT_ID"; usage; } if ! [[ "$PROJECT_ID" =~ ^[0-9]+$ ]]; then log_error "PROJECT_ID must be a positive integer, got '${PROJECT_ID}'" exit 1 fi GITLAB_URL="${GITLAB_URL%/}" TOKEN="$(<"$TOKEN_FILE")" readonly TOKEN GITLAB_URL PROJECT_ID # ── Fetch project info ────────────────────────────────────────────── response="$(curl --silent --fail \ --header "Authorization: Bearer ${TOKEN}" \ "${GITLAB_URL}/api/v4/projects/${PROJECT_ID}")" || { log_error "API request failed for project ${PROJECT_ID}" exit 1 } # If the API returned an error message, show it; otherwise print project details. echo "$response" | jq ' if has("message") then .message else {name, name_with_namespace, path_with_namespace} end '