feat: added "exclude_repo" option to Top Langs (#493)

* 🚀 Added "exclude_repo" option to Top Langs

* chore: code style update

Co-authored-by: Anurag <hazru.anurag@gmail.com>
This commit is contained in:
Bas950
2020-09-27 09:09:44 +02:00
committed by GitHub
parent 3443b37904
commit d4e2a1b395
3 changed files with 33 additions and 2 deletions
+18 -1
View File
@@ -11,6 +11,7 @@ const fetcher = (variables, token) => {
# fetch only owner repos & not forks
repositories(ownerAffiliations: OWNER, isFork: false, first: 100) {
nodes {
name
languages(first: 10, orderBy: {field: SIZE, direction: DESC}) {
edges {
size
@@ -33,7 +34,7 @@ const fetcher = (variables, token) => {
);
};
async function fetchTopLanguages(username, langsCount = 5) {
async function fetchTopLanguages(username, langsCount = 5, exclude_repo = []) {
if (!username) throw Error("Invalid username");
langsCount = clampValue(parseInt(langsCount), 1, 10);
@@ -46,6 +47,22 @@ async function fetchTopLanguages(username, langsCount = 5) {
}
let repoNodes = res.data.data.user.repositories.nodes;
let repoToHide = {};
// populate repoToHide map for quick lookup
// while filtering out
if (exclude_repo) {
exclude_repo.forEach((repoName) => {
repoToHide[repoName] = true;
});
}
// filter out repositories to be hidden
repoNodes = repoNodes
.sort((a, b) => b.size - a.size)
.filter((name) => {
return !repoToHide[name.name];
});
repoNodes = repoNodes
.filter((node) => {