in functions/src/report.ts [51:114]
export async function GetWeeklyReport(org: string) {
const snapshotsRef = database().ref("snapshots/github");
// Grab the most recent daily snapshot
const recentEntrySnapshot = await snapshotsRef
.limitToLast(1)
.once("child_added");
const recentEntry = (await recentEntrySnapshot.val()) as snapshot.Org;
// Count repos
const totalPublicRepos = recentEntry.public_repos;
const publicReposInSnapshot = CountReposWithFilter(
recentEntry,
(repo: snapshot.Repo) => {
return !repo.private;
}
);
if (totalPublicRepos != publicReposInSnapshot) {
log.warn(
`API says ${totalPublicRepos} but there are ${publicReposInSnapshot} in snapshot.`
);
} else {
log.debug(`Total public repos: ${totalPublicRepos}`);
}
// Repos with highest and lowest SAM scores
const topSAMs = GetHighestSam(recentEntry);
const bottomSAMs = GetLowestSam(recentEntry);
// Repos with most stars and most open issues
const topStars = GetTopStars(recentEntry);
const topIssues = GetTopIssues(recentEntry);
// Counting open PRs and Issues (total0)
const totalOpenPullRequests = GetTotalOpenPullRequests(recentEntry);
const totalOpenIssues = GetTotalOpenIssues(recentEntry);
// Issues with no comments at all
const totalOpenIssuesWithNoComments = GetTotalOpenIssuesWithNoComments(
recentEntry
);
// Total stars for the org and total SAM score for the org
const totalStars = GetTotalStars(recentEntry);
const totalSAM = GetTotalSamScore(recentEntry);
// Issues per repo
const averageIssuesPerRepo = Math.floor(totalOpenIssues / totalPublicRepos);
return {
topSAMs,
bottomSAMs,
topStars,
topIssues,
totalOpenIssues,
totalOpenIssuesWithNoComments,
totalOpenPullRequests,
totalPublicRepos,
totalStars,
totalSAM,
averageIssuesPerRepo
};
}