create repo array on fetch

This commit is contained in:
Ruidy Nemausat 2020-05-20 17:12:56 +02:00
parent 8cb35be1d1
commit b7f1489281
3 changed files with 27 additions and 11 deletions

View file

@ -32,7 +32,6 @@ import Experience from '../types/Experience';
import {getTimePeriod} from '../types/TimePeriod'; import {getTimePeriod} from '../types/TimePeriod';
import Education from '../types/Education'; import Education from '../types/Education';
import Repo from '../types/Repo'; import Repo from '../types/Repo';
import asyncGetRepos from '../services/github';
interface IProps { interface IProps {
dev: IDev; dev: IDev;
@ -47,8 +46,6 @@ const Profile: FC<IProps> = ({dev}) => {
return <NotFound />; return <NotFound />;
} }
asyncGetRepos();
/** return the icon corresponding to the social name */ /** return the icon corresponding to the social name */
const renderSocialIcon = (name: string): IconDefinition => { const renderSocialIcon = (name: string): IconDefinition => {
switch (name) { switch (name) {
@ -195,7 +192,7 @@ const Profile: FC<IProps> = ({dev}) => {
<div className="repo bg-white my-1 p-1"> <div className="repo bg-white my-1 p-1">
<div> <div>
<h4> <h4>
<a href={r.link}>{r.name}</a> <a href={r.url}>{r.name}</a>
</h4> </h4>
<p>{r.description}</p> <p>{r.description}</p>
</div> </div>

View file

@ -1,5 +1,6 @@
// Github // Github
import {Octokit} from '@octokit/rest'; import {Octokit} from '@octokit/rest';
import Repo from '../../types/Repo';
/** official GitHub wrapper library */ /** official GitHub wrapper library */
const octokit = new Octokit({ const octokit = new Octokit({
@ -7,10 +8,28 @@ const octokit = new Octokit({
userAgent: 'devBook v1', userAgent: 'devBook v1',
}); });
export default async () => { /**
const {data: repos} = await octokit.repos.listForAuthenticatedUser({ * fetch one user github repos and create a
owner: 'rjNemo', * @param owner githubusername
}); * @returns a Repo array or undefined
*/
console.log(repos); 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;

View file

@ -1,7 +1,7 @@
interface Repo { interface Repo {
name: string; name: string;
description: string; description: string;
link: string; url: string;
stars: number; stars: number;
watchers: number; watchers: number;
forks: number; forks: number;