Skip to content

Instantly share code, notes, and snippets.

@TangoPJ
Last active August 21, 2022 09:56
Show Gist options
  • Save TangoPJ/28e29fa46b0b1327c155a1c4923dda80 to your computer and use it in GitHub Desktop.
Save TangoPJ/28e29fa46b0b1327c155a1c4923dda80 to your computer and use it in GitHub Desktop.
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