Skip to content

Commit 388b9a1

Browse files
committed
Update boilerplate API to fetch GitHub repos
- Replace thoughtbot API endpoint with official GitHub API. - Add response transformation and type definitions
1 parent 8f830af commit 388b9a1

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

  • templates/boilerplate/src/util/api

templates/boilerplate/src/util/api/api.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,41 @@ async function makeRequest<TData>(options: Params): Promise<TData> {
2323
return response.data;
2424
}
2525

26+
function mapRepoToProject(repo: GithubRepo): GithubProject {
27+
return {
28+
id: repo.id,
29+
name: repo.name,
30+
description: repo.description,
31+
url: repo.html_url,
32+
stars: repo.stargazers_count,
33+
forks: repo.forks_count,
34+
};
35+
}
36+
2637
const api = {
27-
// TODO: sample, remove
28-
githubRepos: () =>
29-
makeRequest<GithubProjectsResponse>({
30-
url: 'https://thoughtbot-projects-api-68b03dc59059.herokuapp.com/api/projects',
31-
}),
38+
// Fetch thoughtbot's public repositories from GitHub API
39+
githubRepos: (): Promise<GithubProjectsResponse> =>
40+
makeRequest<GithubRepo[]>({
41+
url: 'https://api.github.com/orgs/thoughtbot/repos',
42+
}).then((repos) => ({
43+
projects: repos.map(mapRepoToProject),
44+
})),
3245
};
3346

3447
// TODO: sample data, remove
3548
export type GithubProjectsResponse = {
3649
projects: GithubProject[];
3750
};
3851

52+
type GithubRepo = {
53+
id: number;
54+
name: string;
55+
description: string | null;
56+
html_url: string;
57+
stargazers_count: number;
58+
forks_count: number;
59+
};
60+
3961
export type GithubProject = {
4062
id: number;
4163
name: string;

0 commit comments

Comments
 (0)