mirror of
https://github.com/Aviortheking/codestats-readme.git
synced 2025-04-22 10:42:08 +00:00
fix: filter out private repos
filtering out private repos just in case, otherwise if a user somehow found out the name of any of the PAT owner's private - (considering they created the PAT with private repo access) repos's name then they could see the repo in github extra pins.
This commit is contained in:
parent
6fedd69f86
commit
1c0332352a
@ -8,6 +8,7 @@ const fetcher = (variables, token) => {
|
|||||||
fragment RepoInfo on Repository {
|
fragment RepoInfo on Repository {
|
||||||
name
|
name
|
||||||
nameWithOwner
|
nameWithOwner
|
||||||
|
isPrivate
|
||||||
stargazers {
|
stargazers {
|
||||||
totalCount
|
totalCount
|
||||||
}
|
}
|
||||||
@ -53,15 +54,21 @@ async function fetchRepo(username, reponame) {
|
|||||||
throw new Error("Not found");
|
throw new Error("Not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.organization === null && data.user) {
|
const isUser = data.organization === null && data.user;
|
||||||
if (!data.user.repository) {
|
const isOrg = data.user === null && data.organization;
|
||||||
|
|
||||||
|
if (isUser) {
|
||||||
|
if (!data.user.repository || data.user.repository.isPrivate) {
|
||||||
throw new Error("User Repository Not found");
|
throw new Error("User Repository Not found");
|
||||||
}
|
}
|
||||||
return data.user.repository;
|
return data.user.repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.user === null && data.organization) {
|
if (isOrg) {
|
||||||
if (!data.organization.repository) {
|
if (
|
||||||
|
!data.organization.repository ||
|
||||||
|
data.organization.repository.isPrivate
|
||||||
|
) {
|
||||||
throw new Error("Organization Repository Not found");
|
throw new Error("Organization Repository Not found");
|
||||||
}
|
}
|
||||||
return data.organization.repository;
|
return data.organization.repository;
|
||||||
|
@ -80,4 +80,17 @@ describe("Test fetchRepo", () => {
|
|||||||
"Not found"
|
"Not found"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should throw error if repository is private", async () => {
|
||||||
|
mock.onPost("https://api.github.com/graphql").reply(200, {
|
||||||
|
data: {
|
||||||
|
user: { repository: { ...data_repo, isPrivate: true } },
|
||||||
|
organization: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(fetchRepo("anuraghazra", "convoychat")).rejects.toThrow(
|
||||||
|
"User Repository Not found"
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user