0

Star Repository

by
Published today

Star a repository as the authenticated user.

Script github Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 1 hour ago
1
//native
2

3
/**
4
 * Star Repository
5
 * Star a repository as the authenticated user.
6
 */
7
export async function main(auth: RT.Github, owner: string, repo: string) {
8
  const response = await fetch(
9
    `https://api.github.com/user/starred/${owner}/${repo}`,
10
    {
11
      method: "PUT",
12
      headers: {
13
        Authorization: `Bearer ${auth.token}`,
14
        Accept: "application/vnd.github+json",
15
        "X-GitHub-Api-Version": "2022-11-28",
16
      },
17
    }
18
  )
19

20
  if (!response.ok) {
21
    throw new Error(`${response.status} ${await response.text()}`)
22
  }
23

24
  return { success: true }
25
}
26