diff --git a/src/pages/Profile.tsx b/src/pages/Profile.tsx index 9c71aa4..9dc58de 100644 --- a/src/pages/Profile.tsx +++ b/src/pages/Profile.tsx @@ -32,7 +32,6 @@ import Experience from '../types/Experience'; import {getTimePeriod} from '../types/TimePeriod'; import Education from '../types/Education'; import Repo from '../types/Repo'; -import asyncGetRepos from '../services/github'; interface IProps { dev: IDev; @@ -47,8 +46,6 @@ const Profile: FC = ({dev}) => { return ; } - asyncGetRepos(); - /** return the icon corresponding to the social name */ const renderSocialIcon = (name: string): IconDefinition => { switch (name) { @@ -195,7 +192,7 @@ const Profile: FC = ({dev}) => {

- {r.name} + {r.name}

{r.description}

diff --git a/src/services/github/index.ts b/src/services/github/index.ts index ff6712e..57e731a 100644 --- a/src/services/github/index.ts +++ b/src/services/github/index.ts @@ -1,5 +1,6 @@ // Github import {Octokit} from '@octokit/rest'; +import Repo from '../../types/Repo'; /** official GitHub wrapper library */ const octokit = new Octokit({ @@ -7,10 +8,28 @@ const octokit = new Octokit({ userAgent: 'devBook v1', }); -export default async () => { - const {data: repos} = await octokit.repos.listForAuthenticatedUser({ - owner: 'rjNemo', - }); - - console.log(repos); +/** + * fetch one user github repos and create a + * @param owner githubusername + * @returns a Repo array or undefined + */ +const getGithubRepos = async (owner: string) => { + try { + const {data: repos} = await octokit.repos.listForAuthenticatedUser({ + owner, + }); + const newRepo: Repo[] = repos.forEach((r: any) => ({ + url: r.url, + stars: r.stargazers_count, + forks: r.forks_count, + description: r.description, + name: r.name, + watchers: r.watchers_count, + })); + return newRepo; + } catch (err) { + console.error(err); + } }; + +export default getGithubRepos; diff --git a/src/types/Repo.ts b/src/types/Repo.ts index c423b13..d6acca0 100644 --- a/src/types/Repo.ts +++ b/src/types/Repo.ts @@ -1,7 +1,7 @@ interface Repo { name: string; description: string; - link: string; + url: string; stars: number; watchers: number; forks: number;