mirror of
https://github.com/rjNemo/devbook_ts
synced 2026-06-06 02:36:39 +00:00
create repo array on fetch
This commit is contained in:
parent
8cb35be1d1
commit
b7f1489281
3 changed files with 27 additions and 11 deletions
|
|
@ -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<IProps> = ({dev}) => {
|
|||
return <NotFound />;
|
||||
}
|
||||
|
||||
asyncGetRepos();
|
||||
|
||||
/** return the icon corresponding to the social name */
|
||||
const renderSocialIcon = (name: string): IconDefinition => {
|
||||
switch (name) {
|
||||
|
|
@ -195,7 +192,7 @@ const Profile: FC<IProps> = ({dev}) => {
|
|||
<div className="repo bg-white my-1 p-1">
|
||||
<div>
|
||||
<h4>
|
||||
<a href={r.link}>{r.name}</a>
|
||||
<a href={r.url}>{r.name}</a>
|
||||
</h4>
|
||||
<p>{r.description}</p>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
interface Repo {
|
||||
name: string;
|
||||
description: string;
|
||||
link: string;
|
||||
url: string;
|
||||
stars: number;
|
||||
watchers: number;
|
||||
forks: number;
|
||||
|
|
|
|||
Loading…
Reference in a new issue