mirror of
https://github.com/Aviortheking/codestats-readme.git
synced 2025-04-22 10:42:08 +00:00
* feat: template option added husky added for same commit disable console in test \ logger utils added env checked for log modified git ignore * changed are done as per the suggesstion * changed style and font * text color dynamic * fix border and using .bagde class as common * simplified the badge svg code through a common method * chore: updated css & fixed tests Co-authored-by: anuraghazra <hazru.anurag@gmail.com>
81 lines
1.7 KiB
JavaScript
81 lines
1.7 KiB
JavaScript
const { request } = require("./utils");
|
|
const retryer = require("./retryer");
|
|
|
|
const fetcher = (variables, token) => {
|
|
return request(
|
|
{
|
|
query: `
|
|
fragment RepoInfo on Repository {
|
|
name
|
|
nameWithOwner
|
|
isPrivate
|
|
isArchived
|
|
isTemplate
|
|
stargazers {
|
|
totalCount
|
|
}
|
|
description
|
|
primaryLanguage {
|
|
color
|
|
id
|
|
name
|
|
}
|
|
forkCount
|
|
}
|
|
query getRepo($login: String!, $repo: String!) {
|
|
user(login: $login) {
|
|
repository(name: $repo) {
|
|
...RepoInfo
|
|
}
|
|
}
|
|
organization(login: $login) {
|
|
repository(name: $repo) {
|
|
...RepoInfo
|
|
}
|
|
}
|
|
}
|
|
`,
|
|
variables,
|
|
},
|
|
{
|
|
Authorization: `bearer ${token}`,
|
|
}
|
|
);
|
|
};
|
|
|
|
async function fetchRepo(username, reponame) {
|
|
if (!username || !reponame) {
|
|
throw new Error("Invalid username or reponame");
|
|
}
|
|
|
|
let res = await retryer(fetcher, { login: username, repo: reponame });
|
|
|
|
const data = res.data.data;
|
|
|
|
if (!data.user && !data.organization) {
|
|
throw new Error("Not found");
|
|
}
|
|
|
|
const isUser = data.organization === null && data.user;
|
|
const isOrg = data.user === null && data.organization;
|
|
|
|
if (isUser) {
|
|
if (!data.user.repository || data.user.repository.isPrivate) {
|
|
throw new Error("User Repository Not found");
|
|
}
|
|
return data.user.repository;
|
|
}
|
|
|
|
if (isOrg) {
|
|
if (
|
|
!data.organization.repository ||
|
|
data.organization.repository.isPrivate
|
|
) {
|
|
throw new Error("Organization Repository Not found");
|
|
}
|
|
return data.organization.repository;
|
|
}
|
|
}
|
|
|
|
module.exports = fetchRepo;
|