1 | |
2 |
|
3 | |
4 | * Update Pull Request |
5 | * Update a pull request's title, body, state or base branch. Only the fields you set change: empty text keeps the current value, and maintainer_can_modify stays as it is unless set to true or false. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Github, |
9 | owner: string, |
10 | repo: string, |
11 | pull_number: number, |
12 | title: string | undefined, |
13 | body: string | undefined, |
14 | state: "open" | "closed" | undefined, |
15 | base: string | undefined, |
16 | maintainer_can_modify: "keep" | "true" | "false" = "keep" |
17 | ) { |
18 | const response = await fetch( |
19 | `https://api.github.com/repos/${owner}/${repo}/pulls/${pull_number}`, |
20 | { |
21 | method: "PATCH", |
22 | headers: { |
23 | Authorization: `Bearer ${auth.token}`, |
24 | "Content-Type": "application/json", |
25 | Accept: "application/vnd.github+json", |
26 | "X-GitHub-Api-Version": "2022-11-28", |
27 | }, |
28 | body: JSON.stringify({ |
29 | title: title || undefined, |
30 | body: body || undefined, |
31 | state: state || undefined, |
32 | base: base || undefined, |
33 | maintainer_can_modify: |
34 | maintainer_can_modify === "true" |
35 | ? true |
36 | : maintainer_can_modify === "false" |
37 | ? false |
38 | : undefined, |
39 | }), |
40 | } |
41 | ) |
42 |
|
43 | if (!response.ok) { |
44 | throw new Error(`${response.status} ${await response.text()}`) |
45 | } |
46 |
|
47 | return await response.json() |
48 | } |
49 |
|