Repository: anuraghazra/github-readme-stats
Pull request #2736 (2023-05-19 08:26:18)

feat: remove 'include_private'
As explained in #2517 the 'include_private' flag is confusing and doesn't work as expected. This commit therefore removes this flag.

# TODOs

- [x] remove conflicts.
- [x] Update [FAQ](https://github.com/anuraghazra/github-readme-stats/discussions/1770#how-to-count-private-stats).

vercel[bot]: [vc]: #hAYbFS0DT6pflttgCRrDLXNvqnPyQxbvtMEmjObUCXQ=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJnaXRodWItcmVhZG1lLXN0YXRzIiwiaW5zcGVjdG9yVXJsIjoiaHR0cHM6Ly92ZXJjZWwuY29tL2dpdGh1Yi1yZWFkbWUtc3RhdHMtdGVhbS9naXRodWItcmVhZG1lLXN0YXRzL0d5QTVUc25GR1J3S2pSdVZNZFJvVkNOeDR2VGgiLCJuZXh0Q29tbWl0U3RhdHVzIjoiUEVORElORyJ9XX0=
**The latest updates on your projects**. Learn more about [Vercel for Git ↗︎](https://vercel.link/github-learn-more)

| Name | Status | Preview | Updated (UTC) |
| :--- | :----- | :------ | :------ |
| **github-readme-stats** | 🔄 Building ([Inspect](https://vercel.com/github-readme-stats-team/github-readme-stats/GyA5TsnFGRwKjRuVMdRoVCNx4vTh)) |  | May 19, 2023 8:26am |


rickstaa: @qwerty541 @anuraghazra told me he will add you as a collaborator when he finds the time. I was curious to know what you think about this change?
rickstaa: 


> > @anuraghazra told me he will add you as a collaborator when he finds the time.
> 
> Nice
> 
> > I was curious to know what you think about this change?
> 
> I fully agree that the `count_private` parameter has behavior that confuse users and support the course to change how it works. But it is important to consider that a large number of users still want to be able to add their private contributions to the statistics card, and I am one of them. As far as I understand, this pull request is a preparation step for adding the optional ability to display the value of the total contributions, including private ones, on the statistics card. If I understood everything correctly, then I support this change.
> 
> I can also add that I think it's good practice for a pull request to contain changes related to only one small task. If I were you, I would format the readme file in a separate pull request so that changes are not confusing.

@qwerty541 This pull request was meant to remove the `count_private` flag all together, as we don't have permissions to view a user's private commits. Users that want to include private commits therefore have to [deploy their own Vercel instance](https://github.com/anuraghazra/github-readme-stats#deploy-on-your-own). However, You are welcome to create a pull request that shows contributions instead of commits (see https://github.com/anuraghazra/github-readme-stats/issues/2517#issuecomment-1554195386) 👍🏻.
francois-rozet: My take is that we can either remove "count_private" altogether or display contributions instead of commits. Note that "contributed to" can also be replaced by "repositories" to avoid confusions (while still counting the repositories that were contributed to).
rickstaa: > I also think displaying contributions instead of commits would be better as some users mainly have private contribs. However this will generate a lot of questions from users. Note that "contributed to" can also be replaced by "repositories" to avoid confusions (while still counting the repositories that were contributed to).

@francois-rozet Thanks for your feedback 💪🏻!

Users can already show private commits by deploying their own Vercel instance. However, as stated above, I agree that giving users the ability to also show contributions using the `show_contribs` and `include_private_contribs` flags while removing the `include_private` flag will be great 🚀! If anybody wants to take this one, feel free to create a pull request.
francois-rozet: Would `show_contribs` replace the commit field or add a new field? Also, we should directly count the private contributions instead of adding a flag `include_private_contribs`. I don't think anyone would choose to no count them if they are set as public in their GitHub profile.
rickstaa: > Would `show_contribs` replace the commit field or add a new field? Also, we should directly count the private contributions instead of adding a flag `include_private_contribs`. I don't think anyone would choose to not count them if they are set as public in their GitHub profile.

Ideally, I think it would be an extra statistics people can enable. People can then disable the commits if they like, using the `hide` flag. It could be added in a `extra_stats` array together with, for example, https://github.com/anuraghazra/github-readme-stats/pull/1404 and the number of answered discussions. I agree that the `include_private_contribs` flag is not needed 😅!


francois-rozet: I am not familiar with that part of the API (adding a new field to the card), but I can do the "backend" part if needed.
qwerty541: > > > @anuraghazra told me he will add you as a collaborator when he finds the time.
> > 
> > 
> > Nice
> > > I was curious to know what you think about this change?
> > 
> > 
> > I fully agree that the `count_private` parameter has behavior that confuse users and support the course to change how it works. But it is important to consider that a large number of users still want to be able to add their private contributions to the statistics card, and I am one of them. As far as I understand, this pull request is a preparation step for adding the optional ability to display the value of the total contributions, including private ones, on the statistics card. If I understood everything correctly, then I support this change.
> > I can also add that I think it's good practice for a pull request to contain changes related to only one small task. If I were you, I would format the readme file in a separate pull request so that changes are not confusing.
> 
> @qwerty541 This pull request was meant to remove the `count_private` flag all together, as we don't have permissions to view a user's private commits. Users that want to include private commits therefore have to [deploy their own Vercel instance](https://github.com/anuraghazra/github-readme-stats#deploy-on-your-own). However, You are welcome to create a pull request that shows contributions instead of commits (see [#2517 (comment)](https://github.com/anuraghazra/github-readme-stats/issues/2517#issuecomment-1554195386)) 👍🏻.

I looked a little deeper and realized that the main problem with the `count_private` parameter is not that its behavior is not obvious to users, but that because of it, when using your own vercel instance, the statistics card shows false information.  When using your own vercel instance, the statistics card already shows all private contributions, and the `count_private` parameter adds redundant commits that are already taken into account there. Now I fully agree that this parameter should be removed.
rickstaa: > > > > @anuraghazra told me he will add you as a collaborator when he finds the time.
> > > 
> > > 
> > > Nice
> > > > I was curious to know what you think about this change?
> > > 
> > > 
> > > I fully agree that the `count_private` parameter has behavior that confuse users and support the course to change how it works. But it is important to consider that a large number of users still want to be able to add their private contributions to the statistics card, and I am one of them. As far as I understand, this pull request is a preparation step for adding the optional ability to display the value of the total contributions, including private ones, on the statistics card. If I understood everything correctly, then I support this change.
> > > I can also add that I think it's good practice for a pull request to contain changes related to only one small task. If I were you, I would format the readme file in a separate pull request so that changes are not confusing.
> > 
> > 
> > @qwerty541 This pull request was meant to remove the `count_private` flag all together, as we don't have permissions to view a user's private commits. Users that want to include private commits therefore have to [deploy their own Vercel instance](https://github.com/anuraghazra/github-readme-stats#deploy-on-your-own). However, You are welcome to create a pull request that shows contributions instead of commits (see [#2517 (comment)](https://github.com/anuraghazra/github-readme-stats/issues/2517#issuecomment-1554195386)) 👍🏻.
> 
> I looked a little deeper and realized that the main problem with the `count_private` parameter is not that its behavior is not obvious to users, but that because of it, when using your own vercel instance, the statistics card shows false information. When using your own vercel instance, the statistics card already shows all private contributions, and the `count_private` parameter adds redundant commits that are already taken into account there. Now I fully agree that this parameter should be removed.

Great! I will merge this pull request when I get a review from @anuraghazra or @Zo-Bro-23 👍🏻.
qwerty541: Hey, @rickstaa! You need to resolve conflicts before merging.
rickstaa: > Hey, @rickstaa! You need to resolve conflicts before merging.

Of course! Sorry, here you go 😄.

Patch:
diff --git a/api/index.js b/api/index.js
index 29ff87f..21448f9 100644
--- a/api/index.js
+++ b/api/index.js
@@ -19,7 +19,6 @@ export default async (req, res) => {
     card_width,
     hide_rank,
     show_icons,
-    count_private,
     include_all_commits,
     line_height,
     title_color,
@@ -52,7 +51,6 @@ export default async (req, res) => {
   try {
     const stats = await fetchStats(
       username,
-      parseBoolean(count_private),
       parseBoolean(include_all_commits),
       parseArray(exclude_repo),
     );
diff --git a/readme.md b/readme.md
index e50d4fc..8e1a09f 100644
--- a/readme.md
+++ b/readme.md
@@ -111,7 +111,7 @@ Change the `?username=` value to your GitHub username.
 ```
 
 > **Warning**
-> By default, the stats card shows contributions only from public repositories. To show your private contributions, you should [deploy your own instance](#deploy-on-your-own) using your own GitHub API token, allowing you to see your private data.
+> By default, the stats card only shows statistics like stars, commits and pull requests from public repositories. To show private statistics on the stats card, you should [deploy your own instance](#deploy-on-your-own) using your own GitHub API token.
 
 > **Note**
 > Available ranks are S+ (top 1%), S (top 25%), A++ (top 45%), A+ (top 60%), and B+ (everyone). The values are calculated by using the [cumulative distribution function](https://en.wikipedia.org/wiki/Cumulative_distribution_function) using commits, contributions, issues, stars, pull requests, followers, and owned repositories. The implementation can be investigated at [src/calculateRank.js](./src/calculateRank.js).
@@ -276,7 +276,6 @@ You can provide multiple comma-separated values in the bg_color option to render
 -   `rank_icon` - Shows alternative rank icon (i.e. `github` or `default`). Default: `default`.
 -   `show_icons` - _(boolean)_. Default: `false`.
 -   `include_all_commits` - Count total commits instead of just the current year commits _(boolean)_. Default: `false`.
--   `count_private` - Count private contributions _(boolean)_. Default: `false`.
 -   `line_height` - Sets the line height between text _(number)_. Default: `25`.
 -   `exclude_repo` - Exclude stars from specified repositories _(Comma-separated values)_. Default: `[] (blank array)`.
 -   `custom_title` - Sets a custom title for the card. Default:  `<username> GitHub Stats`.
@@ -352,6 +351,9 @@ Use [show_owner](#customization) variable to include the repo's owner username
 
 The top languages card shows a GitHub user's most frequently used top language.
 
+> **Warning**
+> By default, the language card shows language results only from public repositories. To include languages used in private repositories, you should [deploy your own instance](#deploy-on-your-own) using your own GitHub API token.
+
 > **Note**
 > Top Languages does not indicate the user's skill level or anything like that; it's a GitHub metric to determine which languages have the most code on GitHub. It is a new feature of github-readme-stats.
 
diff --git a/src/fetchers/stats-fetcher.js b/src/fetchers/stats-fetcher.js
index 8fecffa..9ae23df 100644
--- a/src/fetchers/stats-fetcher.js
+++ b/src/fetchers/stats-fetcher.js
@@ -173,13 +173,11 @@ const totalCommitsFetcher = async (username) => {
  * Fetch stats for a given username.
  *
  * @param {string} username GitHub username.
- * @param {boolean} count_private Include private contributions.
  * @param {boolean} include_all_commits Include all commits.
  * @returns {Promise<import("./types").StatsData>} Stats data.
  */
 const fetchStats = async (
   username,
-  count_private = false,
   include_all_commits = false,
   exclude_repo = [],
 ) => {
@@ -229,12 +227,6 @@ const fetchStats = async (
     stats.totalCommits = user.contributionsCollection.totalCommitContributions;
   }
 
-  // if count_private, add private contributions to totalCommits.
-  if (count_private) {
-    stats.totalCommits +=
-      user.contributionsCollection.restrictedContributionsCount;
-  }
-
   stats.totalPRs = user.pullRequests.totalCount;
   stats.totalIssues = user.openIssues.totalCount + user.closedIssues.totalCount;
   stats.contributedTo = user.repositoriesContributedTo.totalCount;


Test patch:
diff --git a/tests/fetchStats.test.js b/tests/fetchStats.test.js
index 3b27e8a..5466f66 100644
--- a/tests/fetchStats.test.js
+++ b/tests/fetchStats.test.js
@@ -166,7 +166,7 @@ describe("Test fetchStats", () => {
       .onGet("https://api.github.com/search/commits?q=author:anuraghazra")
       .reply(200, { total_count: 1000 });
 
-    let stats = await fetchStats("anuraghazra", false, true);
+    let stats = await fetchStats("anuraghazra", true);
     const rank = calculateRank({
       all_commits: true,
       commits: 1000,
@@ -193,7 +193,7 @@ describe("Test fetchStats", () => {
       .onGet("https://api.github.com/search/commits?q=author:anuraghazra")
       .reply(200, { total_count: 1000 });
 
-    let stats = await fetchStats("anuraghazra", false, true, ["test-repo-1"]);
+    let stats = await fetchStats("anuraghazra", true, ["test-repo-1"]);
     const rank = calculateRank({
       all_commits: true,
       commits: 1000,