-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoctokit.ts
43 lines (38 loc) · 1.16 KB
/
octokit.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
import { Octokit } from '@octokit/rest';
import { GetResponseTypeFromEndpointMethod } from '@octokit/types';
const octokitClient = new Octokit({
userAgent: 'steezplusplus',
auth: process.env.GIT_PAT,
log: process.env.NODE_ENV === 'development' ? console : undefined,
});
type GetReposResponseType = GetResponseTypeFromEndpointMethod<
typeof octokitClient.repos.listForAuthenticatedUser
>;
export async function getRepos() {
try {
const response: GetReposResponseType = await octokitClient.rest.repos.listForAuthenticatedUser({
visibility: 'public',
affiliation: 'owner',
sort: 'updated',
per_page: 9,
page: 0,
});
const filteredData = response.data.map((repo) => {
return {
id: repo.id,
name: repo.name,
description: repo.description,
language: repo.language,
topics: repo.topics,
numStargazers: repo.stargazers_count,
numWatchers: repo.watchers_count,
numForks: repo.forks_count,
githubUrl: repo.html_url,
pushedAt: repo.pushed_at,
};
});
return filteredData;
} catch (error) {
console.error('[GET_REPOS]:', error);
}
}