From 3162163463db1cbb25464ee98597e36f7539cbfa Mon Sep 17 00:00:00 2001 From: jonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com> Date: Mon, 10 Jul 2023 10:26:09 -0400 Subject: [PATCH 1/2] [cifuzz][sarif] Make directory before writing file (#10673) --- infra/cifuzz/sarif_utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/infra/cifuzz/sarif_utils.py b/infra/cifuzz/sarif_utils.py index 885b2a22abe8..93e891b45111 100644 --- a/infra/cifuzz/sarif_utils.py +++ b/infra/cifuzz/sarif_utils.py @@ -240,5 +240,7 @@ def get_sarif_data(stacktrace, target_path): def write_stacktrace_to_sarif(stacktrace, target_path, workspace): """Writes a description of the crash in stacktrace to a SARIF file.""" data = get_sarif_data(stacktrace, target_path) + if not os.path.exists(workspace.sarif): + os.makedirs(self.workspace.sarif) with open(os.path.join(workspace.sarif, 'results.sarif'), 'w') as file_handle: file_handle.write(json.dumps(data)) From c4e1361220ddf2abab7355ba9e36efbacff52ebc Mon Sep 17 00:00:00 2001 From: Holly Gong <39108850+hogo6002@users.noreply.github.com> Date: Tue, 11 Jul 2023 00:30:47 +1000 Subject: [PATCH 2/2] Add past contributors for pr helper (#10664) --- infra/pr_helper.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/infra/pr_helper.py b/infra/pr_helper.py index 871d08ed8fd6..b0de91390519 100644 --- a/infra/pr_helper.py +++ b/infra/pr_helper.py @@ -31,6 +31,7 @@ BASE_URL = f'{API_URL}/repos/{OWNER}/{REPO}' BRANCH = 'master' CRITICALITY_SCORE_PATH = '/home/runner/go/bin/criticality_score' +COMMITS_LIMIT = 50 # Only process the most recent 50 commits. def get_criticality_score(repo_url): @@ -118,10 +119,15 @@ def main(): # Checks the previous commits. commit_sha = github.has_author_modified_project(project_path) if commit_sha is None: + history_message = '' + contributors = github.get_past_contributors(project_path) + if contributors: + history_message = 'The past contributors are: ' + history_message += ', '.join(contributors) message += ( f'{pr_author} is a new contributor to ' f'[{project_path}]({project_url}). The PR must be approved by known ' - 'contributors before it can be merged.
') + f'contributors before it can be merged. {history_message}
') is_ready_for_merge = False continue @@ -223,6 +229,34 @@ def get_pull_request_number(self, commit): return None return pr_response.json()[0]['number'] + def get_past_contributors(self, project_path): + """Returns a list of past contributors of a certain project.""" + commits_response = requests.get(f'{BASE_URL}/commits?path={project_path}', + headers=self._headers) + + if not commits_response.ok: + return [] + commits = commits_response.json() + contributors: dict[str, bool] = {} + for i, commit in enumerate(commits): + if i >= COMMITS_LIMIT: + break + + login = commit['author']['login'] + verified = commit['commit']['verification']['verified'] + if login not in contributors: + contributors[login] = verified + if verified: + # Override previous verification bit. + contributors[login] = True + + all_contributors = [] + for login, verified in contributors.items(): + login_verify = login if verified else f'{login} (unverified)' + all_contributors.append(login_verify) + + return all_contributors + def is_author_internal_member(self): """Returns if the author is an internal member.""" response = requests.get(f'{BASE_URL}/contents/infra/MAINTAINERS.csv',