wrap-git
Version:
Wraps GitHub profile and provides summarized details about repos, commits and language coverages for a given profile.
27 lines (26 loc) • 967 B
JavaScript
import { sortReposByStars } from "../utils/sort.js";
import { getAllRepos } from "../api/repos.js";
const calcTotalStars = (repos) => {
let stars = 0;
repos.forEach((repo) => {
stars = stars + repo.stargazers_count;
});
return stars;
};
export const repoSummarizer = async (username, token) => {
const repos = await getAllRepos(username, token);
const userRepos = repos.filter((repo) => repo.owner === username);
const publicRepos = userRepos.filter((repo) => repo.visibility === "public");
const sortedRepos = sortReposByStars(userRepos);
const totalRepos = sortedRepos.length;
const starsEarned = calcTotalStars(userRepos);
const topStarredRepos = totalRepos > 5 ? sortedRepos.slice(0, 6) : sortedRepos;
return {
allRepos: userRepos,
totalRepos,
starsEarned,
topStarredRepos,
orgRepos: repos.length - userRepos.length,
publicRepos: publicRepos.length
};
};