anuraghazra / anuraghazra/github-readme-stats
Improvements at GraphQL queries
- Dominant language
- JavaScript
- Stars
- 79.8k
- Forks
- 37.7k
- PR merge metrics
- No merged PRs in 30d
Description
## Is your feature request related to a problem? Please describe.
I'll list 4 problems
1. At `stats-fetcher.js`, the [contributionCollection](https://github.com/anuraghazra/github-readme-stats/blob/7a096acf66121bf4e42d98a047b21aacbc8538bc/src/fetchers/stats-fetcher.js#L17) gather only last year information.
2. The [repositoriesContributedTo](https://github.com/anuraghazra/github-readme-stats/blob/7a096acf66121bf4e42d98a047b21aacbc8538bc/src/fetchers/stats-fetcher.js#L21). Only get the last year contributions.
3. There is an option at api `include_all_commits` that try to add commits from all time, but it's not work properly. Just when we clone and host by ourself.

4. If we aren't a collaborator or member of team, the stars doesn't count. Only for repositories where I'm the owner.
While `issues` and `pullRequests` count your entire history, `repositoriesContributedTo` and `repositories` not. So we have inaccurate data about how many repos contributed for. The options `count_private` and `include_all_commits` seems to fix these behaviors. But it's not getting all data for situations where contribution were made before last year.
## Describe the solution you'd like
I guess the problems listed above it's related to GraphQL query. We could get more precise information from `contributionsCollection` and solve the `include_all_commits`, stars, and keep a more realistic details from user.
Get data from all years from `contributionsCollection` we no longer need the option `include_all_commits` at API. It will be under control of user by change the option at Dashboard
.
We will have a precise information about repositories and commits including all years, like `issues` and `pullRequests`.
The `contributionsCollection` return a list of Repositories that user made a commit, `commitContributionsByRepository`. Its possible to count repos, private commits and public ones, stargazes and contributions from there.
It also solves the problem for those who is active maintaining a repo where they aren't part of team or direct collaborator. Like [dotnet/runtime](https://github.com/dotnet/runtime), in my personal example. Or this one:

**Additional context**
I've made some tests, and I figure out theses graphql queries:
First get the years that users have an activity at GitHub:
```graphql
query userInfo($login: String!) {
user(login: $login) {
contributionsCollection {
contributionYears
}
}
}
```
Get the results and build the second one:
```graphql
query userInfo($login: String!) {
user(login: $login) {
name
login
year_2021: contributionsCollection(from: "2021-01-01T00:00:00Z", to: "2022-01-01T00:00:00Z") {
totalCommitContributions
totalRepositoryContributions
restrictedContributionsCount
commitContributionsByRepository {
repository {
name
stargazers {
totalCount
}
}
}
}
year_2020: contributionsCollection(from: "2020-01-01T00:00:00Z", to: "2021-01-01T00:00:00Z") {
totalCommitContributions
totalRepositoryContributions
restrictedContributionsCount
commitContributionsByRepository {
repository {
name
stargazers {
totalCount
}
}
}
}
year_2019: contributionsCollection(from: "2019-01-01T00:00:00Z", to: "2020-01-01T00:00:00Z") {
totalCommitContributions
totalRepositoryContributions
restrictedContributionsCount
commitContributionsByRepository {
repository {
name
stargazers {
totalCount
}
}
}
}
year_2018: contributionsCollection(from: "2018-01-01T00:00:00Z", to: "2019-01-01T00:00:00Z") {
totalCommitContributions
totalRepositoryContributions
restrictedContributionsCount
commitContributionsByRepository {
repository {
name
stargazers {
totalCount
}
}
}
}
year_2017: contributionsCollection(from: "2017-01-01T00:00:00Z", to: "2018-01-01T00:00:00Z") {
totalCommitContributions
totalRepositoryContributions
restrictedContributionsCount
commitContributionsByRepository {
repository {
name
stargazers {
totalCount
}
}
}
}
year_2016: contributionsCollection(from: "2016-01-01T00:00:00Z", to: "2017-01-01T00:00:00Z") {
totalCommitContributions
totalRepositoryContributions
restrictedContributionsCount
commitContributionsByRepository {
repository {
name
stargazers {
totalCount
}
}
}
}
year_2015: contributionsCollection(from: "2015-01-01T00:00:00Z", to: "2016-01-01T00:00:00Z") {
totalCommitContributions
totalRepositoryContributions
restrictedContributionsCount
commitContributionsByRepository {
repository {
name
stargazers {
totalCount
}
}
}
}
year_2014: contributionsCollection(from: "2014-01-01T00:00:00Z", to: "2015-01-01T00:00:00Z") {
totalCommitContributions
totalRepositoryContributions
restrictedContributionsCount
commitContributionsByRepository {
repository {
name
stargazers {
totalCount
}
}
}
}
year_2013: contributionsCollection(from: "2013-01-01T00:00:00Z", to: "2014-01-01T00:00:00Z") {
totalCommitContributions
totalRepositoryContributions
restrictedContributionsCount
commitContributionsByRepository {
repository {
name
stargazers {
totalCount
}
}
}
}
pullRequests(first: 1) {
totalCount
}
issues(first: 1) {
totalCount
}
followers {
totalCount
}
}
}
```
Results of query:
Disabled private contribs:

Enabled private contribs:

Contributor guide
Assessment
This issue has not been assessed yet.