anuraghazra / anuraghazra/github-readme-stats

Improvements at GraphQL queries

Offen
#1,043 6 Kommentare 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
enhancement stats-card
Vorherrschende Sprache
JavaScript
Sterne
79.8k
Forks
37.7k
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

## 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.
![image](https://user-images.githubusercontent.com/7241156/116852034-fb6e0600-abc9-11eb-83ed-7e897870422e.png)

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
![image](https://user-images.githubusercontent.com/7241156/116833604-95b15800-ab90-11eb-8670-e4630c37743f.png).

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:

![image](https://user-images.githubusercontent.com/7241156/116838516-06fb0600-aba5-11eb-9f17-0ce64d3583da.png)

**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:
![image](https://user-images.githubusercontent.com/7241156/116839005-f64b8f80-aba6-11eb-9978-12e5d4fe4cbb.png)

Enabled private contribs:
![image](https://user-images.githubusercontent.com/7241156/116839023-0bc0b980-aba7-11eb-97a7-4d2753996736.png)

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.