0
Create 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.

Created by hugo697 173 days ago Viewed 3738 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 173 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Create a check run
6
 * **Note:** The Checks API only looks for pushes in the repository where the check suite or check run were created.
7
 */
8
export async function main(
9
  auth: Github,
10
  owner: string,
11
  repo: string,
12
  body: {
13
    actions?: {
14
      description: string;
15
      identifier: string;
16
      label: string;
17
      [k: string]: unknown;
18
    }[];
19
    completed_at?: string;
20
    conclusion?:
21
      | "action_required"
22
      | "cancelled"
23
      | "failure"
24
      | "neutral"
25
      | "success"
26
      | "skipped"
27
      | "stale"
28
      | "timed_out";
29
    details_url?: string;
30
    external_id?: string;
31
    head_sha: string;
32
    name: string;
33
    output?: {
34
      annotations?: {
35
        annotation_level: "notice" | "warning" | "failure";
36
        end_column?: number;
37
        end_line: number;
38
        message: string;
39
        path: string;
40
        raw_details?: string;
41
        start_column?: number;
42
        start_line: number;
43
        title?: string;
44
        [k: string]: unknown;
45
      }[];
46
      images?: {
47
        alt: string;
48
        caption?: string;
49
        image_url: string;
50
        [k: string]: unknown;
51
      }[];
52
      summary: string;
53
      text?: string;
54
      title: string;
55
      [k: string]: unknown;
56
    };
57
    started_at?: string;
58
    status?: "queued" | "in_progress" | "completed";
59
    [k: string]: unknown;
60
  } & (
61
    | { status: "completed"; [k: string]: unknown }
62
    | { status?: "queued" | "in_progress"; [k: string]: unknown }
63
  )
64
) {
65
  const url = new URL(
66
    `https://api.github.com/repos/${owner}/${repo}/check-runs`
67
  );
68

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