aboutsummaryrefslogtreecommitdiff
path: root/common/github
diff options
context:
space:
mode:
Diffstat (limited to 'common/github')
-rw-r--r--common/github/repoQuery.ts84
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
+}