Created
August 6, 2022 07:27
-
-
Save fvilante/6a2ebc2c9f21047f874780a333b6d1e4 to your computer and use it in GitHub Desktop.
Get the estimated size (in number of lines) of a given GitHub repository
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// to be used with deno run-time | |
// the first argument must be the repo name | |
// example: deno run --allow-net .\github_repolines.js microsoft/typescript | |
async function countGithub(repo) { | |
const repoAddress = `https://github.com/${repo}`; | |
const repoApi = `https://api.github.com/repos/${repo}` + `/stats/contributors`; | |
const response = await fetch(repoApi); | |
const contributors = await response.json(); | |
const lineCounts = contributors.map(contributor => ( | |
contributor.weeks.reduce((lineCount, week) => lineCount + week.a - week.d, 0) | |
)); | |
const lines = lineCounts.reduce((lineTotal, lineCount) => lineTotal + lineCount); | |
console.table({ | |
repository: repo, | |
address: repoAddress, | |
api: repoApi, | |
linesOfCode: lines, | |
}); | |
} | |
countGithub(Deno.args[0]); // or count anything you like |
Inspirated in this stackoverflow question.
I'm not sure if the computated number of lines includes or excludes doc files for examples, etc.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you have deno installed, just copy and paste line below in your terminal:
(Works on Windows, Mac and Linux).
The words after ".js" represents the repo organization and name respectivelly, and separeted by a slash.