diff options
| author | Bobby <[email protected]> | 2022-11-30 23:16:07 -0500 |
|---|---|---|
| committer | Bobby <[email protected]> | 2022-11-30 23:16:07 -0500 |
| commit | daaa789068cebb5fdfcea6197ade6e663be46e0f (patch) | |
| tree | 1cd315851b779ac28fe622da332c3c16fe1c433c /common/github/repoQuery.ts | |
| download | tcssocialify-daaa789068cebb5fdfcea6197ade6e663be46e0f.tar.xz tcssocialify-daaa789068cebb5fdfcea6197ade6e663be46e0f.zip | |
socialify update
Diffstat (limited to 'common/github/repoQuery.ts')
| -rw-r--r-- | common/github/repoQuery.ts | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/common/github/repoQuery.ts b/common/github/repoQuery.ts new file mode 100644 index 0000000..aa713e9 --- /dev/null +++ b/common/github/repoQuery.ts @@ -0,0 +1,84 @@ +import { HOST_PREFIX } from '../helpers' + +export const getRepoDetails = async (owner: string, name: string) => { + const body = { + query: ` + query repoQuery($_owner: String!, $_name: String!) { + repository(owner: $_owner, name: $_name) { + forkCount + description + createdAt + name + stargazerCount + issues(states: OPEN) { + totalCount + } + languages(first: 2, orderBy: { field: SIZE, direction: DESC }) { + totalCount + nodes { + name + color + } + } + pullRequests(states: OPEN) { + totalCount + } + releases(last: 1) { + nodes { + tagName + } + } + owner { + login + } + } + } + `, + variables: { + _owner: owner, + _name: name + } + } + + const res = await fetch(`${HOST_PREFIX}/graphql`, { + method: 'POST', + headers: { + 'content-type': 'application/json' + }, + body: JSON.stringify(body) + }) + + const json = await res.json() + return json.data as RepoQueryResponse +} + +export type RepoQueryResponse = { + readonly repository: { + readonly forkCount: number + readonly description: string | null + readonly createdAt: unknown + readonly name: string + readonly stargazerCount: number + readonly issues: { + readonly totalCount: number + } + readonly languages: { + readonly totalCount: number + readonly nodes: ReadonlyArray<{ + readonly name: string + readonly color: string | null + } | null> | null + } | null + readonly pullRequests: { + readonly totalCount: number + } + readonly releases: { + readonly nodes: ReadonlyArray<{ + readonly tagName: string + } | null> | null + } + readonly owner: { + readonly login: string + } + } | null +} |
