1 | |
2 | type Circleci = { |
3 | token: string |
4 | } |
5 | |
6 | * Rerun a workflow |
7 | * Reruns a workflow. |
8 | */ |
9 | export async function main( |
10 | auth: Circleci, |
11 | id: string, |
12 | body: { |
13 | enable_ssh?: false | true |
14 | from_failed?: false | true |
15 | jobs?: string[] |
16 | sparse_tree?: false | true |
17 | } |
18 | ) { |
19 | const url = new URL(`https://circleci.com/api/v2/workflow/${id}/rerun`) |
20 |
|
21 | const response = await fetch(url, { |
22 | method: 'POST', |
23 | headers: { |
24 | 'Content-Type': 'application/json', |
25 | 'Circle-Token': auth.token |
26 | }, |
27 | body: JSON.stringify(body) |
28 | }) |
29 | if (!response.ok) { |
30 | const text = await response.text() |
31 | throw new Error(`${response.status} ${text}`) |
32 | } |
33 | return await response.json() |
34 | } |
35 |
|