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

Consider only counting unique commits #2655

Open
mathbunnyru opened this issue Apr 27, 2023 · 8 comments
Open

Consider only counting unique commits #2655

mathbunnyru opened this issue Apr 27, 2023 · 8 comments
Labels
bug Something isn't working.

Comments

@mathbunnyru
Copy link

mathbunnyru commented Apr 27, 2023

Describe the bug

I maintain a repository https://github.com/jupyter/docker-stacks/, which has 848 my commits.
Unfortunately, some users, instead of forking this repository, create their own copy.
This makes github-readme-stats count commits in this repos as well.

https://github-readme-stats-eight-theta.vercel.app/api?username=mathbunnyru&show_icons=true&theme=solarized-light&include_all_commits=true

This chart shows 68.6k commits, which would be awesome, but it's approximately 40x-80x larger than the correct number.
If I search my commits I see all these duplicates: https://github.com/search?o=desc&s=committer-date&type=Commits&q=author%3Amathbunnyru&p=94

Expected behaviour

I expect github-readme-stats to parse the commits and only list the number of unique SHAs.
This way it would show the real number of commits.

Screenshots / Live demo link

Screenshot 2023-04-27 at 15 33 08

Screenshot 2023-04-27 at 15 33 22

Additional context

No response

@mathbunnyru mathbunnyru added the bug Something isn't working. label Apr 27, 2023
@rickstaa
Copy link
Collaborator

@mathbunnyru thanks for your bug report. I could reproduce the bug below. It is caused by the fact that we use the GitHub rest API for the total commits.

const fetchTotalCommits = (variables, token) => {
return axios({
method: "get",
url: `https://api.github.com/search/commits?q=author:${variables.login}`,
headers: {
"Content-Type": "application/json",
Accept: "application/vnd.github.cloak-preview",
Authorization: `token ${token}`,
},
});
};
try {
let res = await retryer(fetchTotalCommits, { login: username });
let total_count = res.data.total_count;
if (!!total_count && !isNaN(total_count)) {
return res.data.total_count;
}
} catch (err) {
logger.log(err);
}
// just return 0 if there is something wrong so that
// we don't break the whole app
return 0;
};

The behaviour is therefore as expected. You could create a pull request to improve the search query we use. We use the GitHub Rest API because of resource limitations in the GraphQL API (see https://docs.github.com/en/graphql/overview/resource-limitations). Fetching all commits through the GraphQL API, although more accurate, will result is in hitting the rate limiter faster. #1691 will fix this, but we cannot merge it into the main branch because of this. You can, however, already use that pull request on your own Vercel instance, since there you will likely not hit the GraphQL limits. We will likely release it under our new GitHub action (see #2179).

Reproduce

Mathbunnyru GitHub stats

[![Mathbunnyru GitHub stats](https://github-readme-stats.vercel.app/api?username=Mathbunnyru)](https://github.com/anuraghazra/github-readme-stats)

Mathbunnyru GitHub stats

[![Mathbunnyru GitHub stats](https://github-readme-stats.vercel.app/api?username=Mathbunnyru&include_all_commits=true)](https://github.com/anuraghazra/github-readme-stats)

@mathbunnyru
Copy link
Author

mathbunnyru commented Apr 28, 2023

Thank you! I think https://github-readme-stats-rongronggg9.vercel.app works well, and the number of commits is as expected.

@rickstaa
Copy link
Collaborator

rickstaa commented Apr 28, 2023

Thank you! I think https://github-readme-stats-rongronggg9.vercel.app works well, and the number of commits is as expected.

@mathbunnyru please don't use @Rongronggg9 Vercel instance as you will likely cause the GraphQL resource limits to be reached in the future when people follow your behaviour 😅(see https://docs.github.com/en/graphql/overview/resource-limitations). I would like to recommend you to create your own Vercel instance and merge #1691 into your main branch 🙏🏻(see https://github.com/anuraghazra/github-readme-stats#deploy-on-your-own).

@mathbunnyru
Copy link
Author

Ok, sorry @rickstaa, I will do what you suggest 😅

@rickstaa
Copy link
Collaborator

Ok, sorry @rickstaa, I will do what you suggest 😅

No problem, the GraphQL limit is a real bottleneck and not well explained in the README. That's why we want to switch to a GitHub action approach (see #2179).

@rickstaa rickstaa closed this as completed May 6, 2023
@mathbunnyru
Copy link
Author

@rickstaa I don't think this is fixed yet.

@rickstaa
Copy link
Collaborator

rickstaa commented May 6, 2023

@rickstaa I don't think this is fixed yet.

You're right, I have mistaken it with another issue related to the language results 👍🏻.

@rickstaa rickstaa reopened this May 6, 2023
@rickstaa
Copy link
Collaborator

rickstaa commented May 6, 2023

You can also show your support for https://github.com/orgs/community/discussions/35675 which would allow us to solve this for the Vercel version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working.
Projects
None yet
Development

No branches or pull requests

2 participants