:clipboard: Description
GithubTotal stars and watchers of a user's all reposCurrently total stars badge is available for a specific repo only.
A badge for total stars count for all public repos of a specific user can be added to a users profile page.
Same can be done for total watchers as well.
For example if a user has 2 repos.
Repo1: stars: 2 watch: 20
Repo2: stars: 4: watch: 40
Then a badge should show Total Stars: 6 (2 + 4) and Total Watch: 60 (20 + 40)
:link: Data
Where can we get the data from?
Yes Github Rest API or GraphQL apiNoNASince a user may have lots of repository, it must be paginated. A max of 100 repos can be fetched in one go.
A graphql query to fetch repos of a user
{
user(login: "mtlynch") {
repositories(first: 100, ownerAffiliations: OWNER, isFork: false) {
totalCount
edges {
cursor
node {
name
stargazers {
totalCount
}
watchers {
totalCount
}
}
}
}
}
}
{
user(login: "mtlynch") {
repositories(first: 100, after: "Y3Vyc29yOnYyOpHOClW-bw==", ownerAffiliations: OWNER, isFork: false) {
totalCount
edges {
cursor
node {
name
stargazers {
totalCount
}
watchers {
totalCount
}
}
}
}
}
}
Please Note: cursor is used for pagination to fetch next set of records, for more info see here
An alternative REST APIs is also available.
:microphone: Motivation
Screenshot of my profile below
If it looks fine, then I can open PR for the same.
Hello @hemantsonu20,
Thanks for the suggestion, this sounds like a good idea to me. However, do you have a feel for the performance of this badge for a user with many public repositories?
@PyvesB Yes there will be a performance hit for users having multiple hundreds repository. But most users have less than 100 repo ( (although I don't have any data to prove it)) and It will be fetched in a single call.
I proposed graphql api where less data will travel over network and that's only optimization we can do from our side.
Is there any way, perhaps with the v3 API, to issue all the paginated calls in parallel? While I'd agree most users don't have thousands of repos, we're really talking about an owner here which could be an Organization (https://github.com/google/) or a user that does happen to have a higher count of repositories (https://github.com/isaacs/ https://github.com/sindresorhus/) and we wouldn't want to have to issue 4+ sequential API calls
@calebcartwright It could be possible if we fetch repo count first.
/users/{username} api returns public_repos count in given user / org account. Then we can fire additional call in parallel for each hundred repos varying page number. Say if account has 350 repos, Issue four parallel call with page 1 to page 4.
Using the graphQL API, could we:
Being able to sort by stars is probably the more useful of those two anyway.
Are you interested in working on a PR for this? There's a tutorial at https://github.com/badges/shields/blob/master/doc/TUTORIAL.md and you can look at other services which implement GithubAuthV4Service to get an idea of how to implement a badge that uses the github graphql api.
Yes, will be happy to work on it.
Will it be feasible to add a query param repoCount (default value 100), which can be further customized. Initially its values can be limited till 200 or any other value you suggest.
Opened pull request #5507. Applied a limit of 200 most starred repos.
We forgot to discuss about Total Watch. The problem is there is no option to sort based on watchers of repo.
I did a google search on how to use shield.io to display total count of stars and I stumbled upon this open issue.
I'm glad that this issue already addresses the problem I was trying to solve.
@hemantsonu20 please I would love to know if what you suggested has been implemented?
We forgot to discuss about
Total Watch. The problem is there is no option to sort based on watchers of repo.
I think it'd be best to go ahead close this given the completion of #5507 and that a similar type of badge for watchers would require separate discussion and implementation. If someone wants to push for a total watchers badge then that could be moved to a new issue.
@emmysteven - the best way to view the available badges we offer is by going to Shields.io and searching for a specific badge or service (via the text box at the very top of the landing page) and/or via browsing the categories and listings of badges.
The aforementioned badges for total stars for a user/organization was indeed implemented via the PR linked to and discussed in the preceding comments, and can also be found on the site:

Hello @calebcartwright,
Thank you for point me to the right direction.
Cheers!
Most helpful comment
Using the graphQL API, could we:
I think if we can do that I would be happy to say we only count your first 100 (or maybe even 200) most-starred repos to keep the number of requests reasonable.