Skip to content

Commit

Permalink
Make GH_ACCESS_TOKEN optional
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmbmb committed Jun 13, 2024
1 parent e172323 commit f3cf028
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions docs/scripts/gen_popular_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import os
from datetime import datetime
from typing import List, Union

import pandas as pd
import requests
Expand All @@ -23,19 +24,33 @@
REPOSITORY = "argilla-io/distilabel"
DATA_PATH = "sections/community/popular_issues.md"

GITHUB_ACCESS_TOKEN = os.environ[
"GH_ACCESS_TOKEN"
] # public_repo and read:org scopes are required
GITHUB_ACCESS_TOKEN = os.getenv("GH_ACCESS_TOKEN")


def fetch_issues_from_github_repository(repository: str, auth_token: Union[str, None] = None) -> pd.DataFrame:
if auth_token is None:
return pd.DataFrame({
"Issue": [],
"State": [],
"Created at": [],
"Closed at": [],
"Last update": [],
"Labels": [],
"Milestone": [],
"Reactions": [],
"Comments": [],
"URL": [],
"Repository": [],
"Author": [],
})


def fetch_data_from_github(repository, auth_token):
headers = {
"Authorization": f"token {auth_token}",
"Accept": "application/vnd.github.v3+json",
}
issues_data = []

print(f"Fetching issues from {repository}...")
print(f"Fetching issues from '{repository}'...")
with requests.Session() as session:
session.headers.update(headers)

Expand Down Expand Up @@ -71,7 +86,10 @@ def fetch_data_from_github(repository, auth_token):
return pd.DataFrame(issues_data)


def get_org_members(auth_token):
def get_org_members(auth_token: Union[str, None] = None) -> List[str]:
if auth_token is None:
return []

headers = {
"Authorization": f"token {auth_token}",
"Accept": "application/vnd.github.v3+json",
Expand All @@ -95,7 +113,7 @@ def get_org_members(auth_token):


with mkdocs_gen_files.open(DATA_PATH, "w") as f:
df = fetch_data_from_github(REPOSITORY, GITHUB_ACCESS_TOKEN)
df = fetch_issues_from_github_repository(REPOSITORY, GITHUB_ACCESS_TOKEN)

open_issues = df.loc[df["State"] == "open"]
engagement_df = (
Expand Down

0 comments on commit f3cf028

Please sign in to comment.