-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Expand file tree
/
Copy pathtrigger_workflow.ts
More file actions
110 lines (103 loc) · 3.26 KB
/
trigger_workflow.ts
File metadata and controls
110 lines (103 loc) · 3.26 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
import type { TriggerWorkflowParams, TriggerWorkflowResponse } from '@/tools/github/types'
import type { ToolConfig } from '@/tools/types'
export const triggerWorkflowTool: ToolConfig<TriggerWorkflowParams, TriggerWorkflowResponse> = {
id: 'github_trigger_workflow',
name: 'GitHub Trigger Workflow',
description:
'Trigger a workflow dispatch event for a GitHub Actions workflow. The workflow must have a workflow_dispatch trigger configured. Returns 204 No Content 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',
},
workflow_id: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Workflow ID (number) or workflow filename (e.g., "main.yaml")',
},
ref: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Git reference (branch or tag name) to run the workflow on',
},
inputs: {
type: 'object',
required: false,
visibility: 'user-or-llm',
description: 'Input keys and values configured in the workflow file',
},
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/workflows/${params.workflow_id}/dispatches`,
method: 'POST',
headers: (params) => ({
Accept: 'application/vnd.github+json',
Authorization: `Bearer ${params.apiKey}`,
'X-GitHub-Api-Version': '2022-11-28',
}),
body: (params) => ({
ref: params.ref,
...(params.inputs && { inputs: params.inputs }),
}),
},
transformResponse: async (response) => {
const content = `Workflow dispatched successfully on ref: ${response.url.includes('ref') ? 'requested ref' : 'default branch'}
The workflow run should start shortly.`
return {
success: true,
output: {
content,
metadata: {},
},
}
},
outputs: {
content: { type: 'string', description: 'Confirmation message' },
metadata: {
type: 'object',
description: 'Empty metadata object (204 No Content response)',
},
},
}
export const triggerWorkflowV2Tool: ToolConfig = {
id: 'github_trigger_workflow_v2',
name: triggerWorkflowTool.name,
description: triggerWorkflowTool.description,
version: '2.0.0',
params: triggerWorkflowTool.params,
request: triggerWorkflowTool.request,
oauth: triggerWorkflowTool.oauth,
transformResponse: async (response: Response, params) => {
return {
success: true,
output: {
triggered: response.status === 204,
workflow_id: params?.workflow_id ?? null,
ref: params?.ref ?? null,
},
}
},
outputs: {
triggered: { type: 'boolean', description: 'Whether workflow was triggered' },
workflow_id: { type: 'string', description: 'Workflow ID or filename', optional: true },
ref: { type: 'string', description: 'Git reference used', optional: true },
},
}