🤖 feat: add Gitea client skill for CI/CD monitoring
Add comprehensive Gitea client skill with capabilities to: - Monitor CI/CD job status and workflows - Fetch detailed job logs and action logs - List workflow jobs to identify failures - Comment on pull requests - Save logs to files for analysis Includes: - Main client script with authentication support - Complete documentation and usage examples - Support for both GITEA_API_TOKEN and GITEA_API_TOKEN_FILE - Comprehensive error handling and workflows Enables AI agents to monitor, diagnose, and interact with Gitea Actions workflows and pull requests.
This commit is contained in:
254
.vibe/skills/gitea-client/scripts/gitea-client.sh
Executable file
254
.vibe/skills/gitea-client/scripts/gitea-client.sh
Executable file
@@ -0,0 +1,254 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Gitea Client - Main script for interacting with Gitea API
|
||||
# Usage: gitea-client.sh <command> [args...]
|
||||
|
||||
set -e
|
||||
|
||||
# Configuration
|
||||
GITEA_API_BASE="https://gitea.arcodange.lab/api/v1"
|
||||
|
||||
# Get authentication token
|
||||
get_auth_token() {
|
||||
if [[ -n "${GITEA_API_TOKEN_FILE:-}" ]]; then
|
||||
if [[ -f "$GITEA_API_TOKEN_FILE" ]]; then
|
||||
cat "$GITEA_API_TOKEN_FILE"
|
||||
return
|
||||
else
|
||||
echo "Error: Token file $GITEA_API_TOKEN_FILE not found" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n "${GITEA_API_TOKEN:-}" ]]; then
|
||||
echo "$GITEA_API_TOKEN"
|
||||
return
|
||||
fi
|
||||
|
||||
echo "Error: No Gitea API token provided" >&2
|
||||
echo "Set either GITEA_API_TOKEN or GITEA_API_TOKEN_FILE environment variable" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Make API request
|
||||
api_request() {
|
||||
local method="$1"
|
||||
local endpoint="$2"
|
||||
local data="${3:-}"
|
||||
|
||||
local token=$(get_auth_token)
|
||||
local url="${GITEA_API_BASE}${endpoint}"
|
||||
|
||||
local headers=(
|
||||
"Authorization: token ${token}"
|
||||
"Accept: application/json"
|
||||
"Content-Type: application/json"
|
||||
)
|
||||
|
||||
if [[ "$method" == "GET" ]]; then
|
||||
curl -s -X GET "$url" -H "${headers[0]}" -H "${headers[1]}"
|
||||
else
|
||||
curl -s -X "$method" "$url" -H "${headers[0]}" -H "${headers[1]}" -H "${headers[2]}" -d "$data"
|
||||
fi
|
||||
}
|
||||
|
||||
# List jobs
|
||||
cmd_list_jobs() {
|
||||
local owner="$1"
|
||||
local repo="$2"
|
||||
local workflow_id="$3"
|
||||
local limit="${4:-10}"
|
||||
|
||||
if [[ -z "$owner" || -z "$repo" || -z "$workflow_id" ]]; then
|
||||
echo "Usage: $0 list-jobs <owner> <repo> <workflow_id> [limit]" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local endpoint="/repos/${owner}/${repo}/actions/workflows/${workflow_id}/runs?limit=${limit}"
|
||||
api_request "GET" "$endpoint"
|
||||
}
|
||||
|
||||
# Get job status
|
||||
cmd_job_status() {
|
||||
local owner="$1"
|
||||
local repo="$2"
|
||||
local job_id="$3"
|
||||
|
||||
if [[ -z "$owner" || -z "$repo" || -z "$job_id" ]]; then
|
||||
echo "Usage: $0 job-status <owner> <repo> <job_id>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local endpoint="/repos/${owner}/${repo}/actions/runs/${job_id}"
|
||||
api_request "GET" "$endpoint"
|
||||
}
|
||||
|
||||
# Get job logs
|
||||
cmd_job_logs() {
|
||||
local owner="$1"
|
||||
local repo="$2"
|
||||
local job_id="$3"
|
||||
local output_file="${4:-}"
|
||||
|
||||
if [[ -z "$owner" || -z "$repo" || -z "$job_id" ]]; then
|
||||
echo "Usage: $0 job-logs <owner> <repo> <job_id> [output_file]" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local endpoint="/repos/${owner}/${repo}/actions/runs/${job_id}/logs"
|
||||
local logs=$(api_request "GET" "$endpoint")
|
||||
|
||||
if [[ -n "$output_file" ]]; then
|
||||
echo "$logs" > "$output_file"
|
||||
echo "Logs saved to: $output_file"
|
||||
else
|
||||
echo "$logs"
|
||||
fi
|
||||
}
|
||||
|
||||
# Get action job logs
|
||||
cmd_action_logs() {
|
||||
local owner="$1"
|
||||
local repo="$2"
|
||||
local action_job_id="$3"
|
||||
local output_file="${4:-}"
|
||||
|
||||
if [[ -z "$owner" || -z "$repo" || -z "$action_job_id" ]]; then
|
||||
echo "Usage: $0 action-logs <owner> <repo> <action_job_id> [output_file]" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local endpoint="/repos/${owner}/${repo}/actions/jobs/${action_job_id}/logs"
|
||||
local logs=$(api_request "GET" "$endpoint")
|
||||
|
||||
if [[ -n "$output_file" ]]; then
|
||||
echo "$logs" > "$output_file"
|
||||
echo "Logs saved to: $output_file"
|
||||
else
|
||||
echo "$logs"
|
||||
fi
|
||||
}
|
||||
|
||||
# List workflow jobs
|
||||
cmd_list_workflow_jobs() {
|
||||
local owner="$1"
|
||||
local repo="$2"
|
||||
local workflow_run_id="$3"
|
||||
|
||||
if [[ -z "$owner" || -z "$repo" || -z "$workflow_run_id" ]]; then
|
||||
echo "Usage: $0 list-workflow-jobs <owner> <repo> <workflow_run_id>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local endpoint="/repos/${owner}/${repo}/actions/runs/${workflow_run_id}/jobs"
|
||||
api_request "GET" "$endpoint"
|
||||
}
|
||||
|
||||
# Wait for job completion
|
||||
cmd_wait_job() {
|
||||
local owner="$1"
|
||||
local repo="$2"
|
||||
local job_id="$3"
|
||||
local timeout="${4:-300}"
|
||||
|
||||
if [[ -z "$owner" || -z "$repo" || -z "$job_id" ]]; then
|
||||
echo "Usage: $0 wait-job <owner> <repo> <job_id> [timeout]" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local start_time=$(date +%s)
|
||||
local end_time=$((start_time + timeout))
|
||||
|
||||
echo "Waiting for job ${job_id} to complete (timeout: ${timeout}s)..."
|
||||
|
||||
while [[ $(date +%s) -lt $end_time ]]; do
|
||||
local status=$(cmd_job_status "$owner" "$repo" "$job_id" | jq -r '.status')
|
||||
|
||||
case "$status" in
|
||||
"completed")
|
||||
echo "Job completed successfully"
|
||||
return 0
|
||||
;;
|
||||
"failed")
|
||||
echo "Job failed"
|
||||
return 1
|
||||
;;
|
||||
"cancelled")
|
||||
echo "Job was cancelled"
|
||||
return 2
|
||||
;;
|
||||
*)
|
||||
echo "Current status: ${status}"
|
||||
sleep 5
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo "Timeout reached"
|
||||
return 3
|
||||
}
|
||||
|
||||
# Comment on PR
|
||||
cmd_comment_pr() {
|
||||
local owner="$1"
|
||||
local repo="$2"
|
||||
local pr_number="$3"
|
||||
local comment="$4"
|
||||
|
||||
if [[ -z "$owner" || -z "$repo" || -z "$pr_number" || -z "$comment" ]]; then
|
||||
echo "Usage: $0 comment-pr <owner> <repo> <pr_number> <comment>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local endpoint="/repos/${owner}/${repo}/issues/${pr_number}/comments"
|
||||
local data="{\"body\": \"${comment}\"}"
|
||||
api_request "POST" "$endpoint" "$data"
|
||||
}
|
||||
|
||||
# Get PR status
|
||||
cmd_pr_status() {
|
||||
local owner="$1"
|
||||
local repo="$2"
|
||||
local pr_number="$3"
|
||||
|
||||
if [[ -z "$owner" || -z "$repo" || -z "$pr_number" ]]; then
|
||||
echo "Usage: $0 pr-status <owner> <repo> <pr_number>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local endpoint="/repos/${owner}/${repo}/pulls/${pr_number}"
|
||||
api_request "GET" "$endpoint"
|
||||
}
|
||||
|
||||
# Main command routing
|
||||
main() {
|
||||
local command="${1:-}"
|
||||
shift || true
|
||||
|
||||
case "$command" in
|
||||
list-jobs) cmd_list_jobs "$@" ;;
|
||||
job-status) cmd_job_status "$@" ;;
|
||||
job-logs) cmd_job_logs "$@" ;;
|
||||
action-logs) cmd_action_logs "$@" ;;
|
||||
list-workflow-jobs) cmd_list_workflow_jobs "$@" ;;
|
||||
wait-job) cmd_wait_job "$@" ;;
|
||||
comment-pr) cmd_comment_pr "$@" ;;
|
||||
pr-status) cmd_pr_status "$@" ;;
|
||||
*)
|
||||
echo "Usage: $0 <command> [args...]" >&2
|
||||
echo "" >&2
|
||||
echo "Commands:" >&2
|
||||
echo " list-jobs <owner> <repo> <workflow_id> [limit]" >&2
|
||||
echo " job-status <owner> <repo> <job_id>" >&2
|
||||
echo " job-logs <owner> <repo> <job_id> [output_file]" >&2
|
||||
echo " action-logs <owner> <repo> <action_job_id> [output_file]" >&2
|
||||
echo " list-workflow-jobs <owner> <repo> <workflow_run_id>" >&2
|
||||
echo " wait-job <owner> <repo> <job_id> [timeout]" >&2
|
||||
echo " comment-pr <owner> <repo> <pr_number> <comment>" >&2
|
||||
echo " pr-status <owner> <repo> <pr_number>" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user