Skip to content

Commit c1a1443

Browse files
committed
feat: add API handler for workflow execution
1 parent 91c7105 commit c1a1443

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/api-client.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getConfig } from './utils.js'
22
import { got } from 'got'
3-
import { APIHealthResponse, APIProjectDetails, APIGithubOrgDetails, APIChecklistItem, APICheckItem, APIWorkflowItem } from './types.js'
3+
import { APIHealthResponse, APIProjectDetails, APIGithubOrgDetails, APIChecklistItem, APICheckItem, APIWorkflowItem, APIWorkflowRunItem } from './types.js'
44

55
export const apiClient = () => {
66
const config = getConfig()
@@ -79,3 +79,16 @@ export const getAllWorkflows = async (): Promise<APIWorkflowItem[]> => {
7979
}
8080
return response.body as APIWorkflowItem[]
8181
}
82+
83+
export const runWorkflow = async (workflowId: string, data: any): Promise<APIWorkflowRunItem> => {
84+
const client = apiClient()
85+
const payload = data ? { data } : {}
86+
const response = await client.post(`workflow/${workflowId}/run`, {
87+
json: payload,
88+
responseType: 'json'
89+
})
90+
if (response.statusCode !== 202) {
91+
throw new Error(`Failed to run the workflow: ${response.statusCode} ${response.body}`)
92+
}
93+
return response.body as APIWorkflowRunItem
94+
}

0 commit comments

Comments
 (0)