Skip to content

Instantly share code, notes, and snippets.

@palnabarun
Last active September 9, 2019 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save palnabarun/45c9b40743295b5250cef67f7154301f to your computer and use it in GitHub Desktop.
Save palnabarun/45c9b40743295b5250cef67f7154301f to your computer and use it in GitHub Desktop.
ContribSummitNA2019

Goals

  • given an username, say whether the user is an owner in any repo in the kubernetes organizations
  • the username should not be marked as an owner if the user shows up only in kubernetes-sigs/contributot-playground's OWNERS files

Method

From cs.k8s.io, it is seen that we can get the OWNER stats for an user from this URL:

https://cs.k8s.io/api/v1/search?stats=fosho&repos=*&rng=%3A20&q=<username>&i=fosho&files=OWNERS

This gives us a response of the format:

{
  "Results": {
    "Matches": {
      ...
    }
  },
  "Stats": {
    "FilesOpened": <a number>,
    "Duration: NN
  }
}

We can see if an user is an owner by looking at the value of .Stats.FileOpened above. For owners, it is non-zero.

But, there is a small caveat, we also want exclude users who are owners in kubernetes-sigs/contributor-playground. For counting the number of appearances, we can query https://cs.k8s.io/api/v1/search?stats=fosho&repos=kubernetes-sigs%2Fcontributor-playground&rng=%3A20&q=<username>&i=fosho&files=OWNERS

So, we can safely say that a user can tagged as an OWNER if the number of OWNER files the username appears in ALL repositories from the first query is more than the number of OWNER files the username appears in kubernetes-sigs/contributor-playground.

An example is shown below:

GitHub All Appearances Playground Apperances All count Playground count Owner
mrbobbytables https://cs.k8s.io/api/v1/search?stats=fosho&repos=*&rng=%3A20&q=mrbobbytables&i=fosho&files=OWNERS https://cs.k8s.io/api/v1/search?stats=fosho&repos=kubernetes-sigs%2Fcontributor-playground&rng=%3A20&q=mrbobbytables&files=OWNERS&i=fosho 16 0 Yes
palnabarun https://cs.k8s.io/api/v1/search?stats=fosho&repos=*&rng=%3A20&q=palnabarun&i=fosho&files=OWNERS https://cs.k8s.io/api/v1/search?stats=fosho&repos=kubernetes-sigs%2Fcontributor-playground&rng=%3A20&q=palnabarun&files=OWNERS&i=fosho 0 0 No

Implementation

In order to fetch JSON data from URL's, we use the Google App Script from here

To get the appearance count, the formula used is:

=VALUE(ImportJSON(<all_url>, "/Stats/FileOpened", "noHeaders"))

The final formula to determine if the user is an OWNER becomes:

=IF(VALUE(ImportJSON(<all_url>, "/Stats/FilesOpened", "noHeaders")) > VALUE(ImportJSON(<playground_url>, "/Stats/FilesOpened", "noHeaders")), "Yes", "No")

where:

all_url:
https://cs.k8s.io/api/v1/search?stats=fosho&repos=*&rng=%3A20&q=mrbobbytables&i=fosho&files=OWNERS

playground_url:
https://cs.k8s.io/api/v1/search?stats=fosho&repos=kubernetes-sigs%2Fcontributor-playground&rng=%3A20&q=mrbobbytables&files=OWNERS&i=fosho

The above URL's can be templated with the username's in each row.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment