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

[Feature] Detect private repositories in Top Languages card #174

Closed
Nathan13888 opened this issue Jul 24, 2020 · 23 comments
Closed

[Feature] Detect private repositories in Top Languages card #174

Nathan13888 opened this issue Jul 24, 2020 · 23 comments
Labels
stale Issue is marked as stale.

Comments

@Nathan13888
Copy link

Is your feature request related to a problem? Please describe.
Top Languages Cards do not display anything about private repositories even when using a self-deployed Vercel instance.

Since the majority of my repositories are private and any public repositories are either forks or don't have any particular "Language" being used, the Top Languages Card appears to be blank (view my profile for details).

Describe the solution you'd like
Include private repositories when generating the Top Languages card.

Describe alternatives you've considered
No other than not using this feature.

@FabioRosado Do you have any ideas?

@anuraghazra
Copy link
Owner

Hmm i see, so you have 3 public repos 2 of them are forked and 1 is a profile readme thats why languages are not shown.

So in case of private repos,
I don't think we can access any private repos, so we cannot calculate languages from private repos.
Also note that i'm not too good at security or privacy terms of github, that's why i'm avoiding showing any private info which is not directly given to an unauthenticated user through github's API, I accepted the implementation of count_private because github api allows it directly with user's consent.

Yes you can deploy on your own vercel instance and fork/modify the code to show your private repo languages.

@FabioRosado
Copy link
Contributor

Hello @Nathan13888 What you are asking will not be possible with @anuraghazra hosted version, this is because the graphql query will check the Repository object and will count the languages if a repository is not a fork (Line 11 of fetchTopLanguage).

The only way for you to get the languages on your private repos count towards your stats would be to host the project yourself - this is because when you use your own API key you will have access to all your private data anyway.

Also note that the languages counter will check if a repository is not a fork so it will only count repos that were created by you and not a fork from another project. We could count all the repos instead but that will just make @anuraghazra hit the api limits quicker I believe.

I guess as a work around you could fork this repo, change the query on fetchTopLanguages to turn the Line 11 of fetchTopLanguage to true and should start count the languages of your forked projects.

Hope this helps 😄 👍

@anuraghazra
Copy link
Owner

@FabioRosado

We could count all the repos instead but that will just make @anuraghazra hit the api limits quicker I believe.

Actually we have multiple Personal Access Token Fallbacks (see #58) so it's unlikely that we will hit the rate limit, the main issue is performance, fetching all the repos will take time and since github api paginates the response to 100 repos we actually have to do multiple requests to get all the repos and that would take some time and it runs on free tier of vercel so the serverless function will fail after 10 seconds, i know 10 seconds sounds too much but surprisingly enough it's not, this is the reason why the #15 is pending.

will count the languages if a repository is not a fork (Line 11 of fetchTopLanguage).

Yes we skip over forks, because forks are not the right metric imo, because a user can fork as many as big repos they want and if we count that in the stats will be too biased.

@FabioRosado
Copy link
Contributor

Didn't know about that but that's a great way to do things! Also I do agree that we should skip forks, this was mostly to try and help @Nathan13888 question/request haha

@anuraghazra
Copy link
Owner

@FabioRosado Yup! 👍

@Nathan13888 I think the best approach is to fork and modify the code on your end, let me know if that solves your query and we can close this for now.

@MirayXS
Copy link

MirayXS commented Jul 24, 2020

The only way for you to get the languages on your private repos count towards your stats would be to host the project yourself - this is because when you use your own API key you will have access to all your private data anyway.
@FabioRosado

My hosted project

This project

Shows the same value. So it doesn't count private repos.

@MirayXS
Copy link

MirayXS commented Jul 24, 2020

If it counted private repos, i would've had a high javascript % as i work on javascript private projects

@Nathan13888
Copy link
Author

I've actually tried hosting my own vercel instance already but it doesn't work still. @anuraghazra

So the solution from the previous feature request that @FabioRosado suggested doesn't seem to work here.

Could there potentially have been some sort of secret API or setup that allows for this to work?

@Nathan13888
Copy link
Author

I've added a self-deployed/hosted version of the repository for reference on my profile picture.

@anuraghazra
Copy link
Owner

@Nathan13888 @MirayXS as I said, you have to modify the code so that it also counts private repos, it does not just magically work just by using your own PAT.

Yes you can deploy on your own vercel instance and fork/modify the code to show your private repo languages.

@MirayXS
Copy link

MirayXS commented Jul 25, 2020

I already have a fork and hosted instance. What code and lines I have to modify ?

@anuraghazra
Copy link
Owner

@MirayXS setting isFork: true should work

repositories(isFork: false, first: 100) {

@yikerman
Copy link

yikerman commented Jul 25, 2020

I already have a fork and hosted instance. What code and lines I have to modify ?

@anuraghazra If everything is as that easy... It'll be a huge project to clone those repos and count.

@anuraghazra
Copy link
Owner

anuraghazra commented Jul 25, 2020

I already have a fork and hosted instance. What code and lines I have to modify ?

@anuraghazra If everything is as that easy... It'll be a huge project to clone those repos and count.

#174 (comment)
#174 (comment)

It'll be a huge project to clone those repos and count.

It's not about huge projects or cloning repo in order to fetch & calculate the data. all is done from Github GraphQL API

@yikerman
Copy link

yikerman commented Jul 25, 2020

It's not about huge projects or cloning repo in order to fetch calculate the data. all is done from Github GraphQL API

I haven't done anything like this before. 😨 You mean this one? https://docs.github.com/en/graphql

@anuraghazra
Copy link
Owner

It's not about huge projects or cloning repo in order to fetch calculate the data. all is done from Github GraphQL API

I haven't done anything like this before.

Everything is magic then 😉

You can explore the API here:

Also check out the code please:

const fetcher = (variables, token) => {
return request(
{
query: `
query userInfo($login: String!) {
user(login: $login) {
repositories(isFork: false, first: 100) {
nodes {
languages(first: 1) {
edges {
size
node {
color
name
}
}
}
}
}
}
}
`,
variables,

@MirayXS
Copy link

MirayXS commented Jul 25, 2020

       repositories(isFork: false, first: 100) {

i want to only count private

@odyvangelis
Copy link

You can explore the API here:

https://developer.github.com/v4/explorer/

trying

viewer {    
    repositories(isFork: false, first: 100) {
      nodes {
        name
     }
   }
}

on api explorer shows private repos fine without needing the isFork value to be true.

When trying the languages query in the API Explorer I did have to change the language(first:1) to (first:10) to get details on more languages, havent looked at the rest of the source code to see if it would make any difference in this issue though.

In any case the language tracker does not seem to work the same way.

As a sidenote i have this weird difference while deploying on my own (1st pic is from your api, second from mine)

image

@anuraghazra
Copy link
Owner

@odieone44

As a sidenote i have this weird difference while deploying on my own (1st pic is from your api, second from mine)

Probably because your instance is using your own PAT so it's also fetching all the private contributions and stats.

@yikerman
Copy link

yikerman commented Jul 25, 2020

@anuraghazra If everything is as that easy... It'll be a huge project to clone those repos and count.

@anuraghazra OMG. I was meant to post these things under #168 ... Found this just now...

But I do not know GraphQL API.

@MirayXS
Copy link

MirayXS commented Jul 25, 2020

       repositories(isFork: false, first: 100) {

i want to only count private repositories, this only counts forked repositories

@RegsonDR
Copy link

RegsonDR commented Sep 7, 2020

After you host an instance (with the latest code), you need to create an access token which has the "repo" scope. This will include your private repositories in the calculation. You don't need to change any code. @MirayXS

Try the following in https://developer.github.com/v4/explorer/ to see which repositories & languages will be used in the calculation.

{
  user(login: "<YOUR USERNAME>") {
    repositories(ownerAffiliations: OWNER, isFork: false, first: 100) {
      nodes {
        name
        languages(first: 10, orderBy: {field: SIZE, direction: DESC}) {
          edges {
            size
            node {
              color
              name
            }
          }
        }
      }
    }
  }
}

You can also modify the query (src/fetchers/top-languages-fetcher.js) to exclude a certain type of repositories, for example, to exclude archived ones you would use "isArchived: false", the same way the forked repositories are currently excluded.

@stale
Copy link

stale bot commented Dec 6, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Issue is marked as stale. label Dec 6, 2020
@stale stale bot closed this as completed Dec 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Issue is marked as stale.
Projects
None yet
Development

No branches or pull requests

7 participants