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

Consider using ghapi #28

Open
matthewfeickert opened this issue Apr 8, 2022 · 1 comment
Open

Consider using ghapi #28

matthewfeickert opened this issue Apr 8, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@matthewfeickert
Copy link
Member

matthewfeickert commented Apr 8, 2022

As an alternative to PyGithub, https://github.com/fastai/ghapi provides nice pagination that could make it easier to work with and gives access to the full GitHub API. This should also allow for the ability to go and get the full star history of any project.

Example: This code gets all of the GitHub star times and dates for pyhf

import json

import matplotlib.dates as mdates
import matplotlib.pyplot as plt
import pandas as pd
from ghapi.all import GhApi, pages

with open(".secrets.json") as read_file:
    api = GhApi(token=json.load(read_file)["api_token"])

owner = "scikit-hep"
repo = "pyhf"
per_page = 30

api.activity.list_stargazers_for_repo(owner, repo, per_page=per_page)
n_pages = api.last_page()

all_pages = pages(
    api.activity.list_stargazers_for_repo,
    n_pages,
    owner,
    repo,
    per_page=per_page,
    headers={"Accept": "application/vnd.github.v3.star+json"},
)

data = [{"date": item["starred_at"], "count": 1} for page in all_pages for item in page]
df = pd.DataFrame(data)

df["date"] = pd.to_datetime(df["date"])
df = df.resample("W-Mon", on="date").sum().cumsum()
df["repo"] = repo

fig, ax = plt.subplots()

time_fmt = mdates.AutoDateLocator()
ax.xaxis.set_major_locator(time_fmt)

ax.plot(df.index, df["count"], label=repo)
ax.legend(loc="best", frameon=False)

ax.set_xlabel("Date", size=14)
ax.set_ylabel("Number of GitHub Stars", size=14)

fig.tight_layout()

file_types = ["png", "pdf", "svg"]
for extension in file_types:
    fig.savefig(f"ghapi_{repo}_star_history.{extension}", facecolor="white")

ghapi_pyhf_star_history

@matthewfeickert
Copy link
Member Author

Another thing that this would allow would be allowing for projects to have their timelines aligned which is quite interesting to visualize growth in comparison to other projects:

star-history-aligned-2022-06-21

Timeline by year Timeline aligned
star-history-2022-06-21 star-history-aligned-2022-06-21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant