File tree Expand file tree Collapse file tree
templates/boilerplate/src/util/api Expand file tree Collapse file tree Original file line number Diff line number Diff 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+
2637const 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
3548export 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+
3961export type GithubProject = {
4062 id : number ;
4163 name : string ;
You can’t perform that action at this time.
0 commit comments