Skip to content

Commit c39e3c4

Browse files
authored
Modify to use GitHub API in the generated app (#76)
This PR updates the boilerplate App to fetch GitHub repository data from the GitHub API instead of using thoughtbot internal API (https://thoughtbot-projects-api-68b03dc59059.herokuapp.com/api/projects). Changes: - Replaced the API endpoint with the official GitHub API (https://api.github.com/orgs/thoughtbot/repos) - Added proper response transformation to map GitHub API fields to the expected project format This provides more reliable GitHub repository information in the generated Belt apps.
1 parent 8f830af commit c39e3c4

2 files changed

Lines changed: 41 additions & 21 deletions

File tree

templates/boilerplate/src/__tests__/App.integration.test.tsx

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { screen, userEvent } from '@testing-library/react-native';
22

33
import mock from 'src/test/mock';
44
import { renderApplication } from 'src/test/render';
5-
import { GithubProjectsResponse } from 'src/util/api/api';
5+
import type { GithubRepo } from 'src/util/api/api';
66

77
// Testing philosophy:
88
// - Tests that render the entire application with `renderApplication` go in the
@@ -37,22 +37,20 @@ test('renders app, can navigate between screens', async () => {
3737
// Pass this mock to `render` or `renderApplication` to register it with MSW.
3838
// Recommended to place these mocks in a central location like `src/test/mocks`
3939
function mockGitHubProjects() {
40-
return mock.get<GithubProjectsResponse, null>(
41-
'https://thoughtbot-projects-api-68b03dc59059.herokuapp.com/api/projects',
40+
return mock.get<GithubRepo[], null>(
41+
'https://api.github.com/orgs/thoughtbot/repos',
4242
{
43-
response: {
44-
projects: [
45-
{
46-
id: 635980144,
47-
name: 'belt',
48-
description:
49-
'Belt is a CLI for starting a new React Native Expo app and will even keep your pants secure as you continue development.',
50-
url: 'https://github.com/thoughtbot/belt',
51-
stars: 8,
52-
forks: 0,
53-
},
54-
],
55-
},
43+
response: [
44+
{
45+
id: 635980144,
46+
name: 'belt',
47+
description:
48+
'Belt is a CLI for starting a new React Native Expo app and will even keep your pants secure as you continue development.',
49+
html_url: 'https://github.com/thoughtbot/belt',
50+
stargazers_count: 8,
51+
forks_count: 0,
52+
},
53+
],
5654
},
5755
);
5856
}

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+
export 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)