-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathget_workflow_run.ts
More file actions
157 lines (147 loc) · 4.6 KB
/
Copy pathget_workflow_run.ts
File metadata and controls
157 lines (147 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import type { GetWorkflowRunParams, WorkflowRunResponse } from '@/tools/github/types'
import {
HEAD_COMMIT_OUTPUT,
PR_REFERENCE_OUTPUT,
REFERENCED_WORKFLOW_OUTPUT,
USER_OUTPUT,
WORKFLOW_RUN_OUTPUT_PROPERTIES,
} from '@/tools/github/types'
import type { ToolConfig } from '@/tools/types'
export const getWorkflowRunTool: ToolConfig<GetWorkflowRunParams, WorkflowRunResponse> = {
id: 'github_get_workflow_run',
name: 'GitHub Get Workflow Run',
description:
'Get detailed information about a specific workflow run by ID. Returns status, conclusion, timing, and links to the run.',
version: '1.0.0',
params: {
owner: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Repository owner (user or organization)',
},
repo: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Repository name',
},
run_id: {
type: 'number',
required: true,
visibility: 'user-or-llm',
description: 'Workflow run ID',
},
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'GitHub Personal Access Token',
},
},
request: {
url: (params) =>
`https://api.github.com/repos/${params.owner}/${params.repo}/actions/runs/${params.run_id}`,
method: 'GET',
headers: (params) => ({
Accept: 'application/vnd.github+json',
Authorization: `Bearer ${params.apiKey}`,
'X-GitHub-Api-Version': '2022-11-28',
}),
},
transformResponse: async (response) => {
const data = await response.json()
const content = `Workflow Run #${data.run_number}: ${data.name}
Status: ${data.status}${data.conclusion ? ` - ${data.conclusion}` : ''}
Branch: ${data.head_branch}
Commit: ${data.head_sha.substring(0, 7)}
Event: ${data.event}
Triggered by: ${data.triggering_actor?.login || 'Unknown'}
Started: ${data.run_started_at || data.created_at}
${data.updated_at ? `Updated: ${data.updated_at}` : ''}
${data.run_attempt ? `Attempt: ${data.run_attempt}` : ''}
URL: ${data.html_url}
Logs: ${data.logs_url}`
return {
success: true,
output: {
content,
metadata: {
id: data.id,
name: data.name,
status: data.status,
conclusion: data.conclusion,
html_url: data.html_url,
run_number: data.run_number,
},
},
}
},
outputs: {
content: { type: 'string', description: 'Human-readable workflow run details' },
metadata: {
type: 'object',
description: 'Workflow run metadata',
properties: {
id: { type: 'number', description: 'Workflow run ID' },
name: { type: 'string', description: 'Workflow name' },
status: { type: 'string', description: 'Run status' },
conclusion: { type: 'string', description: 'Run conclusion' },
html_url: { type: 'string', description: 'GitHub web URL' },
run_number: { type: 'number', description: 'Run number' },
},
},
},
}
export const getWorkflowRunV2Tool: ToolConfig<GetWorkflowRunParams, any> = {
id: 'github_get_workflow_run_v2',
name: getWorkflowRunTool.name,
description: getWorkflowRunTool.description,
version: '2.0.0',
params: getWorkflowRunTool.params,
request: getWorkflowRunTool.request,
transformResponse: async (response: Response) => {
const data = await response.json()
return {
success: true,
output: {
id: data.id,
name: data.name,
head_branch: data.head_branch,
head_sha: data.head_sha,
run_number: data.run_number,
run_attempt: data.run_attempt,
event: data.event,
status: data.status,
conclusion: data.conclusion ?? null,
workflow_id: data.workflow_id,
html_url: data.html_url,
logs_url: data.logs_url,
jobs_url: data.jobs_url,
artifacts_url: data.artifacts_url,
triggering_actor: data.triggering_actor,
pull_requests: data.pull_requests ?? [],
referenced_workflows: data.referenced_workflows ?? [],
head_commit: data.head_commit,
run_started_at: data.run_started_at,
created_at: data.created_at,
updated_at: data.updated_at,
},
}
},
outputs: {
...WORKFLOW_RUN_OUTPUT_PROPERTIES,
triggering_actor: USER_OUTPUT,
pull_requests: {
type: 'array',
description: 'Associated pull requests',
items: PR_REFERENCE_OUTPUT,
},
referenced_workflows: {
type: 'array',
description: 'Referenced workflows',
items: REFERENCED_WORKFLOW_OUTPUT,
},
head_commit: HEAD_COMMIT_OUTPUT,
},
}