Get a list of contributors from a repo

Get contributors’ list using GitHub API and pandas
GitHub
Author

Zeel B Patel

Published

May 17, 2022

Open In Colab

import pandas as pd

Config

owner = "probml"
repo = "pyprobml"

Get all contributors to a repo

contributors = pd.read_json(f"https://api.github.com/repos/{owner}/{repo}/contributors?per_page=100")
contributors = contributors.set_index("login")
print(f"Number of contributors: {len(contributors.index.unique())}")
contributors.head(2)
Number of contributors: 47
id node_id avatar_url gravatar_id url html_url followers_url following_url gists_url starred_url subscriptions_url organizations_url repos_url events_url received_events_url type site_admin contributions
login
murphyk 4632336 MDQ6VXNlcjQ2MzIzMzY= https://avatars.githubusercontent.com/u/463233... https://api.github.com/users/murphyk https://github.com/murphyk https://api.github.com/users/murphyk/followers https://api.github.com/users/murphyk/following... https://api.github.com/users/murphyk/gists{/gi... https://api.github.com/users/murphyk/starred{/... https://api.github.com/users/murphyk/subscript... https://api.github.com/users/murphyk/orgs https://api.github.com/users/murphyk/repos https://api.github.com/users/murphyk/events{/p... https://api.github.com/users/murphyk/received_... User False 1777
Neoanarika 5188337 MDQ6VXNlcjUxODgzMzc= https://avatars.githubusercontent.com/u/518833... https://api.github.com/users/Neoanarika https://github.com/Neoanarika https://api.github.com/users/Neoanarika/followers https://api.github.com/users/Neoanarika/follow... https://api.github.com/users/Neoanarika/gists{... https://api.github.com/users/Neoanarika/starre... https://api.github.com/users/Neoanarika/subscr... https://api.github.com/users/Neoanarika/orgs https://api.github.com/users/Neoanarika/repos https://api.github.com/users/Neoanarika/events... https://api.github.com/users/Neoanarika/receiv... User False 184

Fetch all PRs from a repo

page_range = range(1, 6)
get_pr_df = lambda page: pd.read_json(f"https://api.github.com/repos/probml/pyprobml/pulls?state=all&per_page=100&page={page}")
pull_requests = pd.concat(map(get_pr_df, page_range))
print(f"Number of PRs: {len(pull_requests)}")
pull_requests.head(2)
Number of PRs: 497
url id node_id html_url diff_url patch_url issue_url number state locked ... review_comments_url review_comment_url comments_url statuses_url head base _links author_association auto_merge active_lock_reason
0 https://api.github.com/repos/probml/pyprobml/p... 938329819 PR_kwDOA-3vB8437cbb https://github.com/probml/pyprobml/pull/841 https://github.com/probml/pyprobml/pull/841.diff https://github.com/probml/pyprobml/pull/841.patch https://api.github.com/repos/probml/pyprobml/i... 841 closed False ... https://api.github.com/repos/probml/pyprobml/p... https://api.github.com/repos/probml/pyprobml/p... https://api.github.com/repos/probml/pyprobml/i... https://api.github.com/repos/probml/pyprobml/s... {'label': 'karm-patel:posrprocessing', 'ref': ... {'label': 'probml:master', 'ref': 'master', 's... {'self': {'href': 'https://api.github.com/repo... CONTRIBUTOR NaN NaN
1 https://api.github.com/repos/probml/pyprobml/p... 938317389 PR_kwDOA-3vB8437ZZN https://github.com/probml/pyprobml/pull/840 https://github.com/probml/pyprobml/pull/840.diff https://github.com/probml/pyprobml/pull/840.patch https://api.github.com/repos/probml/pyprobml/i... 840 closed False ... https://api.github.com/repos/probml/pyprobml/p... https://api.github.com/repos/probml/pyprobml/p... https://api.github.com/repos/probml/pyprobml/i... https://api.github.com/repos/probml/pyprobml/s... {'label': 'karm-patel:master', 'ref': 'master'... {'label': 'probml:master', 'ref': 'master', 's... {'self': {'href': 'https://api.github.com/repo... CONTRIBUTOR NaN NaN

2 rows × 36 columns

Get a list of contributors sorted by count of PRs

pull_requests['login'] = pull_requests['user'].apply(lambda x: x["login"])
sorted_by_pr_count = pull_requests.groupby("login").agg({'url': len}).sort_values(by='url', ascending=False)
sorted_by_pr_count.rename(columns={'url': 'Number of PRs'}, inplace=True)
sorted_by_pr_count.head(5)
Number of PRs
login
Drishttii 79
gerdm 55
karalleyna 43
always-newbie161 29
karm-patel 29

Create a dashboard

def get_href_user(user):
  username, profile_link = user.split("|")
  return f"[{username}]({profile_link})"

dashboard = pd.DataFrame(index=sorted_by_pr_count.index)
dashboard["Avatar"] = contributors.avatar_url.apply(lambda url: f'<img width="25" alt="image" src="{url}">')
dashboard["Contributor"] = (contributors.index +"|"+ contributors['html_url']).apply(get_href_user)
dashboard["Number of PRs"] = sorted_by_pr_count["Number of PRs"]
print(dashboard.dropna().T.to_markdown())
|               | Drishttii                                                                               | gerdm                                                                                  | karalleyna                                                                              | always-newbie161                                                                        | karm-patel                                                                              | Duane321                                                                                | Nirzu97                                                                                 | patel-zeel                                                                              | animesh-007                                                                             | ashishpapanai                                                                           | shivaditya-meduri                                                                       | Neoanarika                                                                             | andrewnc                                                                               | nappaillav                                                                              | Abdelrahman350                                                                          | mjsML                                                                                  | jdf22                                                                                  | kzymgch                                                                                 | nalzok                                                                                  | nitish1295                                                                              | Garvit9000c                                                                             | AnkitaKumariJain14                                                                      | rohit-khoiwal-30                                                                        | shobro                                                                                  | raymondyeh07                                                                           | khanshehjad                                                                             | alenm10                                                                                 | firatoncel                                                                             | AnandShegde                                                                             | Aadesh-1404                                                                             | nealmcb                                                                               | nipunbatra                                                                           | petercerno                                                                             | posgnu                                                                                  | mvervuurt                                                                              | hieuza                                                                                 | Prahitha                                                                                | TripleTop                                                                               | UmarJ                                                                                   | Vishal987595                                                                            | a-fakhri                                                                                | adamnemecek                                                                           | galv                                                                                   | jlh2018                                                                                 | krasserm                                                                              | yuanx749                                                                                |
|:--------------|:----------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------|:-------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------|
| Avatar        | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/35187749?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/4108759?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/36455180?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/66471669?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/59387624?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/19956442?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/28842790?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/59758528?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/53366877?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/52123364?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/77324692?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/5188337?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/7716402?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/43855961?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/47902062?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/7131192?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/1637094?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/10054419?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/13443062?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/21181046?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/68856476?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/62535006?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/87682045?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/54628243?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/5696982?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/31896767?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/42214173?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/9141211?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/79975787?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/68186100?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/119472?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/60985?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/1649209?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/30136201?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/6399881?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/1021144?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/44160152?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/48208522?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/34779641?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/97757583?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/65111198?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/182415?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/4767568?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/40842099?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/202907?v=4"> | <img width="25" alt="image" src="https://avatars.githubusercontent.com/u/47032563?v=4"> |
| Contributor   | [Drishttii](https://github.com/Drishttii)                                               | [gerdm](https://github.com/gerdm)                                                      | [karalleyna](https://github.com/karalleyna)                                             | [always-newbie161](https://github.com/always-newbie161)                                 | [karm-patel](https://github.com/karm-patel)                                             | [Duane321](https://github.com/Duane321)                                                 | [Nirzu97](https://github.com/Nirzu97)                                                   | [patel-zeel](https://github.com/patel-zeel)                                             | [animesh-007](https://github.com/animesh-007)                                           | [ashishpapanai](https://github.com/ashishpapanai)                                       | [shivaditya-meduri](https://github.com/shivaditya-meduri)                               | [Neoanarika](https://github.com/Neoanarika)                                            | [andrewnc](https://github.com/andrewnc)                                                | [nappaillav](https://github.com/nappaillav)                                             | [Abdelrahman350](https://github.com/Abdelrahman350)                                     | [mjsML](https://github.com/mjsML)                                                      | [jdf22](https://github.com/jdf22)                                                      | [kzymgch](https://github.com/kzymgch)                                                   | [nalzok](https://github.com/nalzok)                                                     | [nitish1295](https://github.com/nitish1295)                                             | [Garvit9000c](https://github.com/Garvit9000c)                                           | [AnkitaKumariJain14](https://github.com/AnkitaKumariJain14)                             | [rohit-khoiwal-30](https://github.com/rohit-khoiwal-30)                                 | [shobro](https://github.com/shobro)                                                     | [raymondyeh07](https://github.com/raymondyeh07)                                        | [khanshehjad](https://github.com/khanshehjad)                                           | [alenm10](https://github.com/alenm10)                                                   | [firatoncel](https://github.com/firatoncel)                                            | [AnandShegde](https://github.com/AnandShegde)                                           | [Aadesh-1404](https://github.com/Aadesh-1404)                                           | [nealmcb](https://github.com/nealmcb)                                                 | [nipunbatra](https://github.com/nipunbatra)                                          | [petercerno](https://github.com/petercerno)                                            | [posgnu](https://github.com/posgnu)                                                     | [mvervuurt](https://github.com/mvervuurt)                                              | [hieuza](https://github.com/hieuza)                                                    | [Prahitha](https://github.com/Prahitha)                                                 | [TripleTop](https://github.com/TripleTop)                                               | [UmarJ](https://github.com/UmarJ)                                                       | [Vishal987595](https://github.com/Vishal987595)                                         | [a-fakhri](https://github.com/a-fakhri)                                                 | [adamnemecek](https://github.com/adamnemecek)                                         | [galv](https://github.com/galv)                                                        | [jlh2018](https://github.com/jlh2018)                                                   | [krasserm](https://github.com/krasserm)                                               | [yuanx749](https://github.com/yuanx749)                                                 |
| Number of PRs | 79                                                                                      | 55                                                                                     | 43                                                                                      | 29                                                                                      | 29                                                                                      | 29                                                                                      | 25                                                                                      | 23                                                                                      | 18                                                                                      | 17                                                                                      | 16                                                                                      | 10                                                                                     | 10                                                                                     | 10                                                                                      | 8                                                                                       | 7                                                                                      | 7                                                                                      | 6                                                                                       | 6                                                                                       | 5                                                                                       | 4                                                                                       | 4                                                                                       | 3                                                                                       | 3                                                                                       | 2                                                                                      | 2                                                                                       | 2                                                                                       | 2                                                                                      | 2                                                                                       | 1                                                                                       | 1                                                                                     | 1                                                                                    | 1                                                                                      | 1                                                                                       | 1                                                                                      | 1                                                                                      | 1                                                                                       | 1                                                                                       | 1                                                                                       | 1                                                                                       | 1                                                                                       | 1                                                                                     | 1                                                                                      | 1                                                                                       | 1                                                                                     | 1                                                                                       |