0
Update a check run
One script reply has been approved by the moderators Verified

Note: The Checks API only looks for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty pull_requests array.

Updates a check run for a specific commit in a repository. Your GitHub App must have the checks:write permission to edit check runs.

Created by hugo697 173 days ago Viewed 3735 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 173 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Update a check run
6
 * **Note:** The Checks API only looks for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array.
7

8
Updates a check run for a specific commit in a repository. Your GitHub App must have the `checks:write` permission to edit check runs.
9
 */
10
export async function main(
11
  auth: Github,
12
  owner: string,
13
  repo: string,
14
  check_run_id: string,
15
  body: (
16
    | { status?: "completed"; [k: string]: unknown }
17
    | { status?: "queued" | "in_progress"; [k: string]: unknown }
18
  ) & {
19
    actions?: {
20
      description: string;
21
      identifier: string;
22
      label: string;
23
      [k: string]: unknown;
24
    }[];
25
    completed_at?: string;
26
    conclusion?:
27
      | "action_required"
28
      | "cancelled"
29
      | "failure"
30
      | "neutral"
31
      | "success"
32
      | "skipped"
33
      | "stale"
34
      | "timed_out";
35
    details_url?: string;
36
    external_id?: string;
37
    name?: string;
38
    output?: {
39
      annotations?: {
40
        annotation_level: "notice" | "warning" | "failure";
41
        end_column?: number;
42
        end_line: number;
43
        message: string;
44
        path: string;
45
        raw_details?: string;
46
        start_column?: number;
47
        start_line: number;
48
        title?: string;
49
        [k: string]: unknown;
50
      }[];
51
      images?: {
52
        alt: string;
53
        caption?: string;
54
        image_url: string;
55
        [k: string]: unknown;
56
      }[];
57
      summary: string;
58
      text?: string;
59
      title?: string;
60
      [k: string]: unknown;
61
    };
62
    started_at?: string;
63
    status?: "queued" | "in_progress" | "completed";
64
    [k: string]: unknown;
65
  }
66
) {
67
  const url = new URL(
68
    `https://api.github.com/repos/${owner}/${repo}/check-runs/${check_run_id}`
69
  );
70

71
  const response = await fetch(url, {
72
    method: "PATCH",
73
    headers: {
74
      "Content-Type": "application/json",
75
      Authorization: "Bearer " + auth.token,
76
    },
77
    body: JSON.stringify(body),
78
  });
79
  if (!response.ok) {
80
    const text = await response.text();
81
    throw new Error(`${response.status} ${text}`);
82
  }
83
  return await response.json();
84
}
85