Skip to content

Commit

Permalink
change to season wide stats
Browse files Browse the repository at this point in the history
  • Loading branch information
gmguarino committed Jan 31, 2024
1 parent aab17dc commit 926b730
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 21 deletions.
14 changes: 7 additions & 7 deletions config/projects.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"season_12": [],
"test": [],
"offseason":[
{"github_org": "dataforgoodfr", "github_repo": "Bloom", "notion_page_id": "6402dd0a4a104694a5d095a896234b18"},
{"github_org": "dataforgoodfr", "github_repo": "CarbonBombs", "notion_page_id": "4ea70a69962b42ea87b98164dc242756"},
{"github_org": "dataforgoodfr", "github_repo": "CarbonBombsApp", "notion_page_id": "99a0233d2d444ba69a37f3936e13d471"}
]
"offseason": {
"notion_page_id": "73dfe37b0bbd4ff1915147eb55a0bcac",
"repos": [
{"github_org": "dataforgoodfr", "github_repo": "Bloom"},
{"github_org": "dataforgoodfr", "github_repo": "CarbonBombs"}
]
}
}
4 changes: 2 additions & 2 deletions github_repo/github_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class GithubGenericError(Exception):
"""

def __init__(self, response):
print(response.json())
message = f"Generic error was returned with status code: {response.status_code}."
super().__init__(message)

Expand Down Expand Up @@ -70,12 +71,11 @@ def get_total_contributors(self):
response = self.__get_request_generic(request_url)
return len(response.json())

def get_top_contributors(self, n=10):
def get_top_contributors(self):
request_url=f"https://api.github.com/repos/{self.github_owner}/{self.github_repo}/stats/contributors"
response = self.__get_request_generic(request_url)
data = response.json()
contributor_records = list(map(lambda d: {"Name": d["author"]["login"], "Commits": d["total"]}, data))
contributor_records = sorted(contributor_records, key=lambda d: d['Commits'], reverse=True)[:n]
return contributor_records

def __get_all_issues(self):
Expand Down
58 changes: 46 additions & 12 deletions update_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,27 @@ def initialize_overview_dashboard(args, parent_page_id):
return dashboard


def update_overview_dashboard(repo, dashboard):
def update_overview_dashboard(stats, dashboard):
# Updates with new values
dashboard.update_dashboard(commits=stats["n_commits"], pr=stats["open_prs"], contributors=stats["n_contributors"], open_issues=stats["open_issues"])


def get_overview_dashboard_stats(repo):
n_commits = repo.get_total_commits()
n_contributors = repo.get_total_contributors()
contributor_records = repo.get_top_contributors()
open_issues = repo.get_open_issues()
open_prs = repo.get_open_pull_requests()
# Updates with new values
dashboard.update_dashboard(commits=n_commits, pr=open_prs, contributors=n_contributors, open_issues=open_issues)
return dict(n_commits=n_commits, n_contributors=n_contributors, open_issues=open_issues, open_prs=open_prs)


def update_repo_stats(overview_stats, repo_stats):
for key in overview_stats:
if key in repo_stats:
repo_stats[key] = repo_stats[key] + overview_stats[key]
else:
repo_stats[key] = overview_stats[key]
return repo_stats


def initialize_contributor_dashboard(args, parent_page_id):
Expand All @@ -51,10 +64,23 @@ def initialize_contributor_dashboard(args, parent_page_id):
dashboard.create_dashboard(dashboard.parse_contributors(start_records, as_records=True))
return dashboard


def update_contributor_dashboard(repo, dashboard):
def get_contributor_dashboard_stats(repo):
contributor_records = repo.get_top_contributors()
# Updates with new values
return contributor_records

def update_contributor_stats(contributor_stats, records):
for record in records:
if record["Name"] in contributor_stats:
contributor_stats[record["Name"]] = contributor_stats[record["Name"]] + record["Commits"]
else:
contributor_stats[record["Name"]] = record["Commits"]
return contributor_stats

def update_contributor_dashboard(contributor_stats, dashboard, n=10):
contributor_records = [{"Name": key, "Commits": value} for key, value in contributor_stats.items()]
contributor_records = sorted(contributor_records, key=lambda d: d['Commits'], reverse=True)[:n]
# Updates with new values
dashboard.update_dashboard(dashboard.parse_contributors(contributor_records, as_records=False))


Expand All @@ -71,14 +97,22 @@ def update_contributor_dashboard(repo, dashboard):
config = get_config(args.config)

for project_group in config:
for project in config[project_group]:
print(project)
repo = GithubHandler(args.github_token, project["github_org"], project["github_repo"])
overview_dashboard = initialize_overview_dashboard(args, project["notion_page_id"])
update_overview_dashboard(repo, overview_dashboard)
contributor_stats = {}
repo_stats = {}
overview_dashboard = initialize_overview_dashboard(args, project_group["notion_page_id"])
contributor_dashboard = initialize_contributor_dashboard(args, project_group["notion_page_id"])

contributor_dashboard = initialize_contributor_dashboard(args, project["notion_page_id"])
update_contributor_dashboard(repo, contributor_dashboard)
for project in config[project_group]["repos"]:
repo = GithubHandler(args.github_token, project["github_org"], project["github_repo"])

overview_stats = get_overview_dashboard_stats(repo)
repo_stats = update_repo_stats(overview_stats, repo_stats)

contributors = get_contributor_dashboard_stats(repo)
contributor_stats = update_contributor_stats(contributor_stats, contributors)

update_overview_dashboard(repo_stats, overview_dashboard)
update_contributor_dashboard(contributor_stats, contributor_dashboard)



Expand Down

0 comments on commit 926b730

Please sign in to comment.