:clipboard: Description
It would be great to have a badge that just counts all lines of code (no markdown, or so obviously) and shows that number to the user.
service: GitHub
shows: "101|LOC" or "42|LOC"
:link: Data
GitHub, don't know the details here
:microphone: Motivation
That is useful for projects that aim to be minimal/small, or artistic stuff that does something in exactly 42 lines of code or any other "special number".
Hi @rugk interesting idea! I think for this to feasible, Shields would need to be able to retrieve this information from some API/endpoint (not attempt to calculate it ourselves).
If someone wants to try to dig in to what services are available that provide this information we can certainly look into adding this!
Possibly worth investigating as a solution: https://github.com/jolav/codetabs and https://codetabs.com/count-loc/count-loc-online.html in particular
I also just realized this _may_ be a duplicate of #390 馃槃
Aha! This one is a little more coherent :)
We briefly discussed this here. There didn't seem to be a clean and reliable way to get the number of lines of code in a GitHub repository.
Yeah, even the codetabs service I linked above has a pretty restrictive max number of queries per hour that would make it unusable for Shields.
I'm thinking the best way folks could get this today would be Badges from other services, for example SonarCloud has a LOC badge and I'm sure other analysis services provide similar info.
If folks _really_ want to get this data directly from a GitHub repo (with no other service involved), then perhaps using the new Endpoint badge with a little custom code could do the trick?
FYI: "tokei" can count LoC and prepared badge API, but there is not json API...
You may be able to use it by parsing information yourself from returning svg.
https://github.com/Aaronepower/tokei#badges
[]() will shows
$ curl https://tokei.rs/b1/github/badges/shields
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="70" height="20">
<linearGradient id="smooth" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
<stop offset="1" stop-opacity=".1"/>
</linearGradient>
<mask id="round">
<rect width="70" height="20" rx="3" fill="#fff"/>
</mask>
<g mask="url(#round)">
<rect width="28" height="20" fill="#555"/>
<rect x="28" width="42" height="20" fill="#007ec6"/>
<rect width="70" height="20" fill="url(#smooth)"/>
</g>
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
<text x="14" y="15" fill="#010101" fill-opacity=".3">LoC</text>
<text x="14" y="14">LoC</text>
<text x="49" y="15" fill="#010101" fill-opacity=".3">73.6K</text>
<text x="49" y="14">73.6K</text>
</g>
</svg>
I also want to display this information in the Readme, but I would like to display it in Shields' flat-square style.
Created issue for requesting a JSON web API: https://github.com/Aaronepower/tokei/issues/310
If the information is available as an SVG, you could write a badge using the BaseSvgScrapingService class. There are various examples of other badges that do this:
https://github.com/badges/shields/search?q=BaseSvgScrapingService&type=Code
https://github.com/Aaronepower/tokei_rs/issues/8 has been solved 馃帀:
I have now implemented this in tokei.rs if you change your Accept HTTP header to
application/jsonyou will receive JSON data.
I would like to show the line count of a specific file. Is that possible as well?
Line count under a specific folder would be nice so the badge can show product LOC and test LOC.
@jnm2 Yeah the badge is showing 106.1K for my repo (even though there's only 16.5K under src). It's rather misleading!
Have you seen this: https://sloc.xyz/github/<user>/<repo>? I found it but there is still no way to use a custom badge style (comes with the defualt style)
Sounds like there are a couple endpoints that provide the data in a way Shields can consume and provide badges for.
We've got a great tutorial if anyone is interested in implementing this in Shields!
Most helpful comment
Have you seen this:
https://sloc.xyz/github/<user>/<repo>? I found it but there is still no way to use a custom badge style (comes with the defualt style)