-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathrerun_workflow.ts
More file actions
125 lines (117 loc) · 3.4 KB
/
Copy pathrerun_workflow.ts
File metadata and controls
125 lines (117 loc) · 3.4 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
import type { RerunWorkflowParams, RerunWorkflowResponse } from '@/tools/github/types'
import type { ToolConfig } from '@/tools/types'
export const rerunWorkflowTool: ToolConfig<RerunWorkflowParams, RerunWorkflowResponse> = {
id: 'github_rerun_workflow',
name: 'GitHub Rerun Workflow',
description:
'Rerun a workflow run. Optionally enable debug logging for the rerun. Returns 201 Created on success.',
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 to rerun',
},
enable_debug_logging: {
type: 'boolean',
required: false,
visibility: 'user-or-llm',
description: 'Enable debug logging for the rerun (default: false)',
default: false,
},
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}/rerun`,
method: 'POST',
headers: (params) => ({
Accept: 'application/vnd.github+json',
Authorization: `Bearer ${params.apiKey}`,
'X-GitHub-Api-Version': '2022-11-28',
}),
body: (params) => ({
...(params.enable_debug_logging !== undefined && {
enable_debug_logging: params.enable_debug_logging,
}),
}),
},
transformResponse: async (response, params) => {
if (!params) {
return {
success: false,
error: 'Missing parameters',
output: {
content: '',
metadata: {
run_id: 0,
status: 'error',
},
},
}
}
const content = `Workflow run #${params.run_id} has been queued for rerun.${params.enable_debug_logging ? '\nDebug logging is enabled for this rerun.' : ''}
The rerun should start shortly.`
return {
success: true,
output: {
content,
metadata: {
run_id: params.run_id,
status: 'rerun_initiated',
},
},
}
},
outputs: {
content: { type: 'string', description: 'Rerun confirmation message' },
metadata: {
type: 'object',
description: 'Rerun metadata',
properties: {
run_id: { type: 'number', description: 'Workflow run ID' },
status: { type: 'string', description: 'Rerun status (rerun_initiated)' },
},
},
},
}
export const rerunWorkflowV2Tool: ToolConfig = {
id: 'github_rerun_workflow_v2',
name: rerunWorkflowTool.name,
description: rerunWorkflowTool.description,
version: '2.0.0',
params: rerunWorkflowTool.params,
request: rerunWorkflowTool.request,
oauth: rerunWorkflowTool.oauth,
transformResponse: async (response: Response, params) => {
return {
success: true,
output: {
rerun_requested: response.status === 201,
run_id: params?.run_id ?? null,
},
}
},
outputs: {
rerun_requested: { type: 'boolean', description: 'Whether rerun was requested' },
run_id: { type: 'number', description: 'Workflow run ID', optional: true },
},
}