🤖 feat: complete gitea-client skill enhancements with new CI/CD monitoring commands

This commit is contained in:
2026-04-07 11:31:11 +02:00
parent 9e4731ce7a
commit c6a2d63a6d
2 changed files with 277 additions and 0 deletions

View File

@@ -52,6 +52,20 @@ api_request() {
fi
}
# List workflows
cmd_list_workflows() {
local owner="$1"
local repo="$2"
if [[ -z "$owner" || -z "$repo" ]]; then
echo "Usage: $0 list-workflows <owner> <repo>" >&2
exit 1
fi
local endpoint="/repos/${owner}/${repo}/actions/workflows"
api_request "GET" "$endpoint"
}
# List jobs
cmd_list_jobs() {
local owner="$1"
@@ -226,12 +240,16 @@ main() {
shift || true
case "$command" in
list-workflows) cmd_list_workflows "$@" ;;
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 "$@" ;;
monitor-workflow) cmd_monitor_workflow "$@" ;;
diagnose-job) cmd_diagnose_job "$@" ;;
recent-workflows) cmd_recent_workflows "$@" ;;
comment-pr) cmd_comment_pr "$@" ;;
pr-status) cmd_pr_status "$@" ;;
list-issues) cmd_list_issues "$@" ;;
@@ -245,12 +263,16 @@ main() {
echo "Usage: $0 <command> [args...]" >&2
echo "" >&2
echo "Commands:" >&2
echo " list-workflows <owner> <repo>" >&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 " monitor-workflow <owner> <repo> <workflow_run_id> [interval_seconds]" >&2
echo " diagnose-job <owner> <repo> <job_id>" >&2
echo " recent-workflows <owner> <repo> [limit] [status_filter]" >&2
echo " comment-pr <owner> <repo> <pr_number> <comment>" >&2
echo " pr-status <owner> <repo> <pr_number>" >&2
echo " list-issues <owner> <repo> [state]" >&2
@@ -389,4 +411,109 @@ cmd_get_wiki() {
api_request "GET" "$endpoint"
}
# Monitor workflow run until completion
cmd_monitor_workflow() {
local owner="$1"
local repo="$2"
local workflow_run_id="$3"
local interval="${4:-30}"
if [[ -z "$owner" || -z "$repo" || -z "$workflow_run_id" ]]; then
echo "Usage: $0 monitor-workflow <owner> <repo> <workflow_run_id> [interval_seconds]" >&2
exit 1
fi
echo "Monitoring workflow run $workflow_run_id (interval: ${interval}s)..."
echo "Press Ctrl+C to stop monitoring"
while true; do
local endpoint="/repos/${owner}/${repo}/actions/runs/${workflow_run_id}"
local status=$(api_request "GET" "$endpoint" | jq -r '.status')
local conclusion=$(api_request "GET" "$endpoint" | jq -r '.conclusion')
local updated_at=$(api_request "GET" "$endpoint" | jq -r '.updated_at')
echo "[$(date +'%Y-%m-%d %H:%M:%S')] Status: $status, Conclusion: ${conclusion:-not completed}, Updated: $updated_at"
# List jobs in this workflow
local jobs_endpoint="/repos/${owner}/${repo}/actions/runs/${workflow_run_id}/jobs"
local jobs=$(api_request "GET" "$jobs_endpoint")
echo "Jobs:"
echo "$jobs" | jq -r '.jobs[] | " \(.id): \(.name) - \(.status) \(if .conclusion then "(\(.conclusion))" else "" end)"'
# Check if workflow is completed
if [[ "$status" != "queued" && "$status" != "in_progress" && "$status" != "waiting" ]]; then
echo "Workflow run $workflow_run_id has completed with status: $status and conclusion: ${conclusion:-none}"
break
fi
sleep "$interval"
done
}
# Diagnose failed job
cmd_diagnose_job() {
local owner="$1"
local repo="$2"
local job_id="$3"
if [[ -z "$owner" || -z "$repo" || -z "$job_id" ]]; then
echo "Usage: $0 diagnose-job <owner> <repo> <job_id>" >&2
exit 1
fi
echo "Diagnosing job $job_id..."
# Get job details
local job_endpoint="/repos/${owner}/${repo}/actions/jobs/${job_id}"
local job_details=$(api_request "GET" "$job_endpoint")
echo "Job Details:"
echo "$job_details" | jq '. | {id, name, status, conclusion, started_at, completed_at, runner_name}'
# Get job logs
local logs_endpoint="/repos/${owner}/${repo}/actions/jobs/${job_id}/logs"
echo -e "\nLast 50 lines of logs:"
api_request "GET" "$logs_endpoint" | tail -50
# Look for errors
echo -e "\nError analysis:"
api_request "GET" "$logs_endpoint" | grep -i "error\|fail\|panic\|exception" | tail -10
# Get workflow run details
local run_id=$(echo "$job_details" | jq -r '.run_id')
local run_endpoint="/repos/${owner}/${repo}/actions/runs/${run_id}"
local run_details=$(api_request "GET" "$run_endpoint")
echo -e "\nWorkflow Run Details:"
echo "$run_details" | jq '. | {id, display_title, status, conclusion, head_branch, head_sha}'
}
# Get recent workflow runs summary
cmd_recent_workflows() {
local owner="$1"
local repo="$2"
local limit="${3:-10}"
local status_filter="${4:-}"
if [[ -z "$owner" || -z "$repo" ]]; then
echo "Usage: $0 recent-workflows <owner> <repo> [limit] [status_filter]" >&2
echo "Status filter options: all, completed, in_progress, queued, waiting" >&2
exit 1
fi
local endpoint="/repos/${owner}/${repo}/actions/runs?limit=${limit}"
if [[ -n "$status_filter" ]]; then
endpoint="$endpoint&status=$status_filter"
fi
local workflows=$(api_request "GET" "$endpoint")
echo "Recent Workflow Runs (showing $limit most recent):"
echo "$workflows" | jq -r '.workflow_runs[] | "\(.id): \(.display_title) - \(.status) \(if .conclusion then "(\(.conclusion))" else "" end) - \(.updated_at)"'
# Show summary statistics
echo -e "\nSummary:"
echo "$workflows" | jq -r '.workflow_runs | group_by(.conclusion) | .[] | " \(.[0].conclusion // "in_progress"): \(length)"'
}
main "$@"