Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"GitHub repo file count" counts not all files #8784

Open
cn0047 opened this issue Jan 6, 2023 · 1 comment
Open

"GitHub repo file count" counts not all files #8784

cn0047 opened this issue Jan 6, 2023 · 1 comment
Labels
question Support questions, usage questions, unconfirmed bugs, discussions, ideas service-badge New or updated service badge

Comments

@cn0047
Copy link

cn0047 commented Jan 6, 2023

Are you experiencing an issue with...

shields.io

🐞 Description

Repo cn007b/stash has many directories and each directory holds many files,
but GitHub repo file count from https://shields.io/category/size returns only 4, here: GitHub cn007b/stash repo file count
which is definitely incorrect, for example only this directory has 14 files.

🔗 Link to the badge

https://img.shields.io/github/directory-file-count/cn007b/stash

💡 Possible Solution

Probably GitHub repo file count should iterate over all files over all directories recursively,
it might be expensive in terms of processing time,
probably some sort of caching must be introduced,
but it would be nice to have this insights, IMHO.

@cn0047 cn0047 added the question Support questions, usage questions, unconfirmed bugs, discussions, ideas label Jan 6, 2023
@chris48s
Copy link
Member

chris48s commented Jan 7, 2023

I think the existing example is a bit misleading in the way it is labelled.
https://img.shields.io/github/directory-file-count/cn007b/stash is a (non-recursive) count of files (and directories) in the root of https://github.com/cn007b/stash which is not totally clear from the docs/example.

At the moment this badge shows non-recursive counts but it looks like we probably could provide recursive counts in a performant way at least at the repo level. For example

https://api.github.com/repos/badges/shields/git/trees/master?recursive=true
https://api.github.com/repos/cn007b/stash/git/trees/master?recursive=true

return a response pretty quickly even given the large number of files, although there are some notes on limitations at https://docs.github.com/en/rest/git/trees?apiVersion=2022-11-28#get-a-tree

The downside of the tree API is that it doesn't allow filtering by directory so we couldn't do recursive counts for a subdir by the looks of it.

@calebcartwright - you reviewed the original PR where this badge was added (albeit some time ago), do you have any thoughts on the design decisions behind this one?

@chris48s chris48s added the service-badge New or updated service badge label Jan 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Support questions, usage questions, unconfirmed bugs, discussions, ideas service-badge New or updated service badge
Projects
None yet
Development

No branches or pull requests

2 participants