github-readme-stats icon indicating copy to clipboard operation
github-readme-stats copied to clipboard

[Feature Request] Add organization stats

Open franky47 opened this issue 5 years ago • 154 comments

Most of my open-source work is moved to dedicated organizations (47ng, FortySevenEffects, Chiffre), for scoping and to avoid cluttering my personal repos.

I'd be happy to contribute a feature to include aggregated organization stats.

API ideas:

![Anurag's github stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&orgs=acme,evilcorp,fsociety)

franky47 avatar Jul 09 '20 11:07 franky47

@franky47 great idea! okay i will look into it. and try to add org support. meanwhile you can also contribute if you want.

anuraghazra avatar Jul 09 '20 11:07 anuraghazra

I did that in my fork on AWS Lambda. For the pin.js I did:

      query: `
        fragment RepoInfo on Repository {
          name
          owner {
            login
          }
const renderRepoCard = (repo) => {
  const owner = repo.owner.login;
<text x="50" y="38" class="header"><a class="header" href="https://github.com/${owner}/${name}">${name}</a></text>

You can see too that I added an <a> link to the repo name too.

metaskills avatar Jul 11 '20 19:07 metaskills

Will it actually show the stats including all the Orgs?

anuraghazra avatar Jul 11 '20 19:07 anuraghazra

@metaskills Also yes that link would work but will it work in github readmes? Hmmm i dont think soo because it is served as image not as raw html elements. 🤔

anuraghazra avatar Jul 11 '20 19:07 anuraghazra

Oh yea... good point. Without a in your markdown, you can click it (views svg) then click it again. But easier to put the links in your markdown I suspect.

metaskills avatar Jul 11 '20 20:07 metaskills

Yes just wrapping the markdown image inside a link is a good way.

anuraghazra avatar Jul 11 '20 20:07 anuraghazra

I really hope to have this function, which can count my stars in the organization!

FairyEver avatar Jul 22 '20 05:07 FairyEver

my stars value is 0, can help check?

https://github-readme-stats.vercel.app/api/?username=deancn

deancn avatar Jul 24 '20 04:07 deancn

Hi @deancn, it is because we currently only support stars from repositories you are the owner of. Since many people want this as an enhancement I'm sure we'll be able to implement this soon.

terror avatar Jul 24 '20 04:07 terror

@terror got it, thanks.

deancn avatar Jul 24 '20 04:07 deancn

Assuming you might be a member of some huge organization (npm, babel, rust). It might make sense to add a filter on top of it to prevent certain organizations from being included. Better than that would be an allowlist that only includes organizations that you explicitly declare: https://github-readme-stats.vercel.app/api/?username=SirWindfield?orgs=zors-engine,Spotifyd

mainrs avatar Jul 24 '20 17:07 mainrs

How long this feature could be used?

daolou avatar Jul 29 '20 06:07 daolou

any news on this?

RubenMateus avatar Aug 02 '20 21:08 RubenMateus

Any update on this?

ngoldack avatar Aug 22 '20 10:08 ngoldack

@anuraghazra I tried it in go and it worked like a charm to count those stars:

package main

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
)

type Org struct {
	Name string `json:"login"`
}

type Repo struct {
	Name  string `json:"full_name"`
	Stars int    `json:"stargazers_count"`
}

func main() {
	url := "https://api.github.com/users/mattetti/orgs"

	resp, err := http.Get(url)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}

	var stars int

	var orgs []Org
	json.Unmarshal(body, &orgs)
	for _, v := range orgs {

		url = fmt.Sprintf("https://api.github.com/orgs/%s/repos", v.Name)

		resp, err = http.Get(url)
		if err != nil {
			panic(err)
		}
		defer resp.Body.Close()
		body, err = ioutil.ReadAll(resp.Body)
		if err != nil {
			panic(err)
		}

		var repos []Repo
		json.Unmarshal(body, &repos)

		for _, v := range repos {
			fmt.Println(v.Name, v.Stars)
			stars += v.Stars
		}
	}
	fmt.Println("-----------------------")
	fmt.Println("### Total stars:", stars)
}

It's quite simple: you just get all org names from the api endpoint /users/${USERNAME}/orgs and then get all each repo from each org from the endpoint /orgs/${ORGNAME}/repos. Just count those stars together and you have it. But since I don't have the expierence in javascript I won't be able to implement this.

ngoldack avatar Sep 02 '20 07:09 ngoldack

@ngoldack

this api /users/${USERNAME}/orgs seemingly inaccurate for example https://api.github.com/users/Mr-jiangzhiguo/orgs get [], but in fact, it has 3 public orgs image

daolou avatar Sep 02 '20 08:09 daolou

@Mr-jiangzhiguo, strangely when I go to your Github profile, I also can't see your organizations. I tried mine (curl https://api.github.com/users/mre/orgs) and it works. 🤔

mre avatar Sep 02 '20 09:09 mre

@Mr-jiangzhiguo, strangely when I go to your Github profile, I also can't see your organizations. I tried mine (curl https://api.github.com/users/mre/orgs) and it works. 🤔

I got it, settings is private image

daolou avatar Sep 02 '20 09:09 daolou

It's quite simple: you just get all org names from the api endpoint /users/${USERNAME}/orgs and then get all each repo from each org from the endpoint /orgs/${ORGNAME}/repos. Just count those stars together and you have it. But since I don't have the expierence in javascript I won't be able to implement this.

Yeah logic isn't an issue here. we can of course get the data and manipulate it as per our needs.

BUT! The issue is that vercel serverless execution time is only 10sec and it's not enough to fetch all those data & then manipulate it, serverless function would time out long before we even get to fetching all org data.

and then get all each repo from each org

And this is also very expensive because the organization can have many repos and we have to fetch all of them and accumulate the star count.

anuraghazra avatar Sep 02 '20 09:09 anuraghazra

@anuraghazra some kind of lightweight cache could be a solution 🤔

dzikoysk avatar Sep 02 '20 09:09 dzikoysk

@anuraghazra or concurrency.

Another problem would be the rate limiting with too much orgs/repos

ngoldack avatar Sep 02 '20 11:09 ngoldack

some kind of lightweight cache could be a solution thinking

We already have caching, it's not the issue since the initial data wont even load because vercel would timeout.

anuraghazra avatar Sep 06 '20 12:09 anuraghazra

the same demands

zhangyuang avatar Sep 17 '20 13:09 zhangyuang

eager to have this.

changkun avatar Sep 25 '20 17:09 changkun

Patiently waiting for an exciting update.

conquerv0 avatar Oct 15 '20 07:10 conquerv0

I would prefer to use a whitelist for that, that would also make it more straight forward and light (probably?)

For example: https://github-readme-stats.vercel.app/api?username=MrTroble&?orgs=Troblecodings&show_icons=true&theme=radical

This would go through the repos of Troblecodings and would account for all stars in those. This shouldn't take to long should it?

MrTroble avatar Oct 28 '20 20:10 MrTroble

Still relevant.

Zethson avatar Dec 06 '20 16:12 Zethson

Just bought @anuraghazra a coffee in the name of this issue (and as a general "thank you" for making this wonderful piece of software). Maybe if more people chip in we can convince him to get this done before he gets a heart attack from all the caffeine. 😅

wleoncio avatar Apr 20 '21 07:04 wleoncio

Just bought @anuraghazra a coffee in the name of this issue (and as a general "thank you" for making this wonderful piece of software). Maybe if more people chip in we can convince him to get this done before he gets a heart attack from all the caffeine. 😅

😄 haha thank you for coffee.

Well yeah probably only viable way to get this issue done is to change the fetching system, like instead of fetching on the fly with serverless functions, we can create a github action to fetch the data, this way serverless functions won't timeout and we can fetch more data looping over all the organizations.

anuraghazra avatar Apr 29 '21 09:04 anuraghazra

What is the status of this Feature?

kaaax0815 avatar May 17 '21 10:05 kaaax0815