From 777f2af4c375129741e90d4ff3db08ee55468d3e Mon Sep 17 00:00:00 2001 From: Will Russell Date: Mon, 4 Mar 2024 17:52:57 +0000 Subject: [PATCH] Collect commits using API as well as CLI --- git_metrics.py | 11 ++++++----- orientation_metrics.py | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/git_metrics.py b/git_metrics.py index 3541009..faf98d2 100644 --- a/git_metrics.py +++ b/git_metrics.py @@ -34,11 +34,10 @@ def __init__(self, term): self.scope = ['https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/drive'] self.credentials = ServiceAccountCredentials.from_json_keyfile_name("gs_credentials.json", self.scope) self.client = gspread.authorize(self.credentials) - self.sheet = self.client.open_by_url("https://docs.google.com/spreadsheets/d/12quNi2TYuRK40woals-ABPT5NcsmhBmC_dHNU9rX1Do") self.activities_data_sh = self.sheet.worksheet("activities_data") - self.utc = pytz.utc + self.utc = pytz.utc dates_sh = self.sheet.worksheet('Fellowship Terms') for row in dates_sh.get_all_records(): @@ -46,14 +45,12 @@ def __init__(self, term): start_date = str(row['Start_Date__c']).split('-') end_date = str(row['End_Date__c']).split('-') - self.program_date_start_year = int(start_date[0]) self.program_date_end_year = int(end_date[0]) self.program_date_start_month = int(start_date[1]) self.program_date_end_month = int(end_date[1]) self.program_date_start_day = int(start_date[2]) self.program_date_end_day = int(end_date[2]) - self.batch_start = datetime.datetime(self.program_date_start_year, self.program_date_start_month, self.program_date_start_day) self.batch_end = datetime.datetime(self.program_date_end_year, self.program_date_end_month, self.program_date_end_day) @@ -69,7 +66,6 @@ def collect_data(self): if len(fellow_projects['urls']) < 1: print(f"No URLs for {self.fellows[fellow]['project']}. Skipping") continue - # Getting PRs/Issues issues_response = self.make_gh_request(self.ISSUES_URL, self.fellows[fellow]['github_username']) @@ -89,6 +85,11 @@ def collect_data(self): if len(row) > 0: self.project_data.append(row) + # Run commit check again using API for commits not collected using email. Using GitHub username to collect onwards + commits_response = self.make_gh_request(self.COMMITS_URL, self.fellows[fellow]['github_username']) + if commits_response != None and "items" in commits_response: + self.find_commits(commits_response, fellow_projects['urls'], fellow) + # Getting Issues for url in fellow_projects['urls']: if "https://github" in url: diff --git a/orientation_metrics.py b/orientation_metrics.py index bb16415..251f3cb 100644 --- a/orientation_metrics.py +++ b/orientation_metrics.py @@ -93,6 +93,27 @@ def collect_data(self): "Null", "Null"]) + # Get commits via API to fill in any blanks + commits_response = self.make_gh_request(self.COMMITS_URL, self.fellows[fellow]['github_username']) + if commits_response != None and "items" in commits_response: + for item in commits_response['items']: + url = item['repository']['html_url'] + if url in self.projects: + if self.check_no_duplicates(url, item['sha']): + print(f"Adding to db - {url}") + self.project_data.append([fellow, + self.fellows[fellow]['term'], + self.fellows[fellow]['pod'], + self.fellows[fellow]['github_username'], + item['sha'], + url, + "Commit", + item['commit']['message'], + "Null", + helpers.standardize_datetime(issue['created_at'], "Commit"), + "Null", + "Null"]) + # Issues for url in self.projects[project]['urls']: if "https://github" in url: