-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.ts
52 lines (46 loc) · 1.07 KB
/
github.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
export async function getRepo(name: string): Promise<any> {
const user = name.split('/')[0]
const repo = name.split('/')[1]
const response = await fetch('https://api.github.com/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${import.meta.env.GITHUB_TOKEN}`
},
body: JSON.stringify({
query: CHANGELOG_QUERY,
variables: { user, repo }
})
})
if (!response.ok) {
console.error(response)
}
const json = await response.json()
if (json.errors) {
console.error(json.errors)
}
const repoInfo = json?.data?.user?.repository
return repoInfo
}
export const CHANGELOG_QUERY = /* GraphQL */ `
query GitHubRepo($user: String!, $repo: String!) {
user(login: $user) {
repository(name: $repo) {
name
description
forkCount
stargazerCount
url
owner {
login
}
object(expression: "main:CHANGELOG.md") {
id
... on Blob {
text
}
}
}
}
}
`