Last active
August 21, 2022 09:56
-
-
Save TangoPJ/28e29fa46b0b1327c155a1c4923dda80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Octokit } from "@octokit/core"; | |
export const getInfoFromGit = async (urls) => { | |
const octokit = new Octokit({ | |
auth: process.env.NEXT_PUBLIC_GITHUB_TOKEN, | |
}) | |
const repositories = [] | |
for (const url of urls) { | |
try { | |
const { data: { name, description, forks, stargazers_count, html_url } } = await octokit.request(`GET /repos/${url.user}/${url.repository}`, { | |
owner: 'OWNER', | |
repo: 'REPO' | |
}) | |
repositories.push({ | |
name, | |
description, | |
forks, | |
stars: stargazers_count, | |
url: html_url | |
}) | |
} catch (error) { | |
console.log(error); | |
throw new Error(`Error: ${error}`) | |
} | |
} | |
return repositories | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment