Open alberthaff opened 6 years ago
Thanks for the suggestion. Our data for the GitHub badges comes from their API. I don't think GitHub surface this information via an API endpoint yet, do they?
Yes, you are right. Unfortunately, their API doesn't seem to have an endpoint to retrieve the dependency graph.
Is there another service that could provide this? For example, we use https://libraries.io/ for bower. Would they have a relevant endpoint?
If the project is a package indexed by libraries.io, the project-dependencies, project-dependents (these are both about other packages that your package depends on, or is dependent on) and the dependent-repositories endpoint (which is about repositories that depend on your package) are all relevant in this problem domain but won't produce the same numbers as the GH dependency graph. See https://github.com/librariesio/libraries.io/issues/2005
This came up again in #1858, where @sindresorhus pointed out there is a GraphQL endpoint for the dependency graph: https://developer.github.com/changes/2018-04-24-preview-dependency-graph-and-vulnerability-hooks/
However:
That endpoint doesn't seem to provide access to the dependents number, only the dependencies number.
IIRC scraping github violates their ToS so I'm not sure the best way forward here.
As @chris48s points out above, Libraries.io has a different number available, but it doesn't match Github. I added a badge for that in #1895.
If anyone is interested in working on this, there is now a GithubAuthV4Service
base class for working with the Github GraphQL API. https://github.com/badges/shields/blob/master/services/github/github-forks.service.js is an example of another badge that uses it.
I haven't tried it, but does this GraphQL object provide the data needed? https://docs.github.com/en/graphql/reference/objects#dependencygraphmanifest
GitHub is now displaying the number of dependents on the front page of a repo as "Used by", which will make more people want a badge for it:
Yes. As noted in the link 2 posts up ( https://developer.github.com/changes/2018-04-24-preview-dependency-graph-and-vulnerability-hooks/ ), dependencyGraphManifests
would be the right query if anyone wants to work on this. Interestingly, 4 years on that query still requires passing a preview header to enable it: application/vnd.github.hawkgirl-preview+json
refs https://docs.github.com/en/graphql/overview/schema-previews#access-to-a-repositories-dependency-graph-preview
It seems both the REST and GraphQL APIs don't expose the dependents (Used-by) yet. So I've created a small temporary wrapper in case someone's else wants to use it https://github.com/mrf345/gh-used-by
It would be great to have a shield displaying stats from GitHub's dependency graph (dependent repos / packages):
https://github.com/badges/shields/network/dependents