-
-
Notifications
You must be signed in to change notification settings - Fork 92
/
Repository.tsx
96 lines (89 loc) · 2.61 KB
/
Repository.tsx
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { GithubEntity, createGithubResource, GithubGqlEndpoint } from './Base';
export class Repository extends GithubEntity {
readonly name: string = '';
readonly fullName: string = '';
readonly private: boolean = false;
readonly description: string = '';
readonly fork: boolean = false;
readonly homepage: string = '';
readonly language: string | null = null;
readonly forksCount: number = 0;
readonly stargazersCount: number = 0;
readonly watchersCount: number = 0;
readonly size: number = 0;
readonly defaultBranch: string = 'master';
readonly openIssuesCount: number = 0;
readonly isTemplate: boolean = false;
readonly topics: string[] = [];
readonly hasIssues: boolean = false;
readonly hasProjects: boolean = false;
readonly hasWiki: boolean = false;
readonly hasPages: boolean = false;
readonly hasDownloads: boolean = false;
readonly archived: boolean = false;
readonly disabled: boolean = false;
readonly visibility: 'public' | 'private' = 'public';
readonly pushedAt: Date = new Date(0);
readonly createdAt: Date = new Date(0);
readonly updatedAt: Date = new Date(0);
readonly templateRepository: null = null;
readonly owner: { login: string } = { login: '' };
static schema = {
pushedAt: Date,
createdAt: Date,
updatedAt: Date,
};
pk() {
return [this.owner.login, this.name].join(',');
}
// for the inheritance
static get key() {
return 'Repository';
}
}
export class GqlRepository extends Repository {
static process(input: any, parent: any, key: string | undefined) {
// conform gql api to rest
if ('stargazerCount' in input) {
return {
...input,
stargazersCount: input.stargazerCount,
fork: input.isFork,
forksCount: input.forkCount,
private: input.isPrivate,
};
}
return input;
}
}
const base = createGithubResource('/repos/:owner/:repo' as const, Repository);
export const RepositoryResource = {
...base,
getByUser: base.getList.extend({
urlRoot: '/users/:login/repos' as const,
body: undefined,
}),
getByPinned: GithubGqlEndpoint.query(
(v: { login: string }) => `query getByPinned($login: String!) {
user(login: $login) {
pinnedItems(first: 6, types: REPOSITORY) {
nodes {
... on Repository {
name
owner { login }
id
description
createdAt
stargazerCount
isFork
forkCount
isPrivate
}
}
}
}
}`,
{ user: { pinnedItems: { nodes: [GqlRepository] } } },
),
};
export default RepositoryResource;