web/src/utils/fetch-repo-info.ts
63 lines · 1368 bytes
1import { fetchEnrich } from './fetch-enrich';
2
3const normalizeRepo = (github: string): string =>
4 github.replace(/^https?:\/\/github\.com\//, '').replace(/\/+$/, '');
5
6export const fetchGitHubStats = (
7 github: string,
8): Promise<GitHubStatsResponse | null> => {
9 const repo = normalizeRepo(github);
10 return fetchEnrich<GitHubStatsResponse>(
11 'GitHub Stats',
12 `/v1/enrich/github/${repo}`,
13 repo,
14 );
15};
16
17export interface GitHubStatsResponse {
18 info: {
19 ownerUsername: string;
20 ownerAvatar: string;
21 description: string;
22 url: string;
23 homepage: string;
24 language: string;
25 topics: string[];
26 license: string;
27 licenseName: string;
28 isFork: boolean;
29 isArchived: boolean;
30 forkParent: string;
31 createdAt: string;
32 updatedAt: string;
33 pushedAt: string;
34 size: number;
35 starCount: number;
36 forksCount: number;
37 watchersCount: number;
38 openIssues: number;
39 };
40 languages: {
41 [key: string]: number;
42 };
43 versions: Array<{
44 name: string;
45 commit: string;
46 zipball: string;
47 tarball: string;
48 }>;
49 contributors: Array<{
50 username: string;
51 avatar: string;
52 url: string;
53 contributions: number;
54 }>;
55 commits: Array<{
56 sha: string;
57 authorName: string;
58 authorDate: string;
59 message: string;
60 authorUsername: string;
61 authorAvatar: string;
62 }>;
63}