From 59ce9969be9abf25ea2f79cfcb86b455c606cfbe Mon Sep 17 00:00:00 2001 From: Holly Gong Date: Tue, 1 Aug 2023 18:42:28 +1000 Subject: [PATCH 1/6] Filter out maintainers from known contributors. --- .github/workflows/pr_helper.yml | 2 +- infra/pr_helper.py | 28 +++++++++++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/.github/workflows/pr_helper.yml b/.github/workflows/pr_helper.yml index 65740d916d87..a567bd25dffb 100644 --- a/.github/workflows/pr_helper.yml +++ b/.github/workflows/pr_helper.yml @@ -1,6 +1,6 @@ name: PR helper on: - pull_request_target: + pull_request: types: [opened, reopened] branches: - master diff --git a/infra/pr_helper.py b/infra/pr_helper.py index b0de91390519..64344e8f40b3 100644 --- a/infra/pr_helper.py +++ b/infra/pr_helper.py @@ -76,8 +76,9 @@ def main(): # Bypasses PRs of the internal members. if github.is_author_internal_member(): - save_env(None, None, True) - return + # save_env(None, None, True) + # return + print('debug, disable internal check') message = '' is_ready_for_merge = True @@ -149,6 +150,7 @@ def main(): class GithubHandler: """Github requests handler.""" + maintainers = set() def __init__(self): self._pr_author = os.environ['PRAUTHOR'] @@ -252,24 +254,32 @@ def get_past_contributors(self, project_path): all_contributors = [] for login, verified in contributors.items(): + if login in self.maintainers: + continue 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.""" + def get_maintainers(self): + """Get a list of internal members.""" + if not self.maintainers: + return self.maintainers + response = requests.get(f'{BASE_URL}/contents/infra/MAINTAINERS.csv', headers=self._headers) if not response.ok: return False - maintainers = base64.b64decode(response.json()['content']).decode('UTF-8') - for line in maintainers.split(os.linesep): - if self._pr_author == line.split(',')[2]: - return True + self.maintainers = base64.b64decode( + response.json()['content']).decode('UTF-8') + for line in self.maintainers.split(os.linesep): + self.maintainers.add(line.split(',')[2]) + return self.maintainers - return False + def is_author_internal_member(self): + """Returns if the author is an internal member.""" + return self._pr_author in self.get_maintainers() def has_author_modified_project(self, project_path): """Checks if the author has modified this project before.""" From aefd0494b19f4b05955871ff1b00c15944928d7b Mon Sep 17 00:00:00 2001 From: Holly Gong Date: Tue, 1 Aug 2023 18:47:46 +1000 Subject: [PATCH 2/6] Add test project --- projects/cpython3/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/cpython3/build.sh b/projects/cpython3/build.sh index 022c851feec2..da00d4468137 100644 --- a/projects/cpython3/build.sh +++ b/projects/cpython3/build.sh @@ -15,7 +15,7 @@ # ################################################################################ -# Ignore memory leaks from python scripts invoked in the build +# Ignore memory leaks from python scripts invoked in the build add comment export ASAN_OPTIONS="detect_leaks=0" export MSAN_OPTIONS="halt_on_error=0:exitcode=0:report_umrs=0" From 7bc8b35b5fd051d0e722470d4af2e21289c8648c Mon Sep 17 00:00:00 2001 From: Holly Gong Date: Tue, 1 Aug 2023 18:55:56 +1000 Subject: [PATCH 3/6] add log --- infra/pr_helper.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/infra/pr_helper.py b/infra/pr_helper.py index 64344e8f40b3..502324449fcf 100644 --- a/infra/pr_helper.py +++ b/infra/pr_helper.py @@ -150,7 +150,6 @@ def main(): class GithubHandler: """Github requests handler.""" - maintainers = set() def __init__(self): self._pr_author = os.environ['PRAUTHOR'] @@ -160,6 +159,7 @@ def __init__(self): 'Authorization': f'Bearer {self._token}', 'X-GitHub-Api-Version': '2022-11-28' } + self._maintainers = set() os.environ['GITHUB_AUTH_TOKEN'] = self._token def get_pr_author(self): @@ -246,6 +246,10 @@ def get_past_contributors(self, project_path): login = commit['author']['login'] verified = commit['commit']['verification']['verified'] + print(f'login: {login} maintainers: {self._maintainers}') + if login in self._maintainers: + print(f'filter out {login}') + continue if login not in contributors: contributors[login] = verified if verified: @@ -254,8 +258,6 @@ def get_past_contributors(self, project_path): all_contributors = [] for login, verified in contributors.items(): - if login in self.maintainers: - continue login_verify = login if verified else f'{login} (unverified)' all_contributors.append(login_verify) @@ -263,19 +265,22 @@ def get_past_contributors(self, project_path): def get_maintainers(self): """Get a list of internal members.""" - if not self.maintainers: - return self.maintainers + if not self._maintainers: + print(f'not maintainers: {self._maintainers}') + + return self._maintainers response = requests.get(f'{BASE_URL}/contents/infra/MAINTAINERS.csv', headers=self._headers) if not response.ok: return False - self.maintainers = base64.b64decode( + self._maintainers = base64.b64decode( response.json()['content']).decode('UTF-8') - for line in self.maintainers.split(os.linesep): - self.maintainers.add(line.split(',')[2]) - return self.maintainers + for line in self._maintainers.split(os.linesep): + self._maintainers.add(line.split(',')[2]) + print(f'maintainers: {self._maintainers}') + return self._maintainers def is_author_internal_member(self): """Returns if the author is an internal member.""" From 57d2417ba92cae16da9833d1b6bf5c8871f23ac9 Mon Sep 17 00:00:00 2001 From: Holly Gong Date: Tue, 1 Aug 2023 18:59:24 +1000 Subject: [PATCH 4/6] fix logic --- infra/pr_helper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infra/pr_helper.py b/infra/pr_helper.py index 502324449fcf..c4027c0b1342 100644 --- a/infra/pr_helper.py +++ b/infra/pr_helper.py @@ -265,8 +265,8 @@ def get_past_contributors(self, project_path): def get_maintainers(self): """Get a list of internal members.""" - if not self._maintainers: - print(f'not maintainers: {self._maintainers}') + if self._maintainers: + print(f'if maintainers: {self._maintainers}') return self._maintainers From 18f8ec9e04cb3c6711a72b3eaee0bdf86b756eee Mon Sep 17 00:00:00 2001 From: Holly Gong Date: Wed, 2 Aug 2023 14:03:01 +1000 Subject: [PATCH 5/6] fix bug --- infra/pr_helper.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/infra/pr_helper.py b/infra/pr_helper.py index c4027c0b1342..10e904754d30 100644 --- a/infra/pr_helper.py +++ b/infra/pr_helper.py @@ -267,7 +267,6 @@ def get_maintainers(self): """Get a list of internal members.""" if self._maintainers: print(f'if maintainers: {self._maintainers}') - return self._maintainers response = requests.get(f'{BASE_URL}/contents/infra/MAINTAINERS.csv', @@ -275,9 +274,9 @@ def get_maintainers(self): if not response.ok: return False - self._maintainers = base64.b64decode( + maintainers_file = base64.b64decode( response.json()['content']).decode('UTF-8') - for line in self._maintainers.split(os.linesep): + for line in maintainers_file.split(os.linesep): self._maintainers.add(line.split(',')[2]) print(f'maintainers: {self._maintainers}') return self._maintainers From edcdc3efc1aaf5c78df401120bd446663e38d4c2 Mon Sep 17 00:00:00 2001 From: Holly Gong Date: Wed, 2 Aug 2023 14:08:03 +1000 Subject: [PATCH 6/6] Remove debug print --- infra/pr_helper.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/infra/pr_helper.py b/infra/pr_helper.py index 10e904754d30..4aa63ed25473 100644 --- a/infra/pr_helper.py +++ b/infra/pr_helper.py @@ -246,9 +246,7 @@ def get_past_contributors(self, project_path): login = commit['author']['login'] verified = commit['commit']['verification']['verified'] - print(f'login: {login} maintainers: {self._maintainers}') if login in self._maintainers: - print(f'filter out {login}') continue if login not in contributors: contributors[login] = verified @@ -266,7 +264,6 @@ def get_past_contributors(self, project_path): def get_maintainers(self): """Get a list of internal members.""" if self._maintainers: - print(f'if maintainers: {self._maintainers}') return self._maintainers response = requests.get(f'{BASE_URL}/contents/infra/MAINTAINERS.csv', @@ -278,7 +275,6 @@ def get_maintainers(self): response.json()['content']).decode('UTF-8') for line in maintainers_file.split(os.linesep): self._maintainers.add(line.split(',')[2]) - print(f'maintainers: {self._maintainers}') return self._maintainers def is_author_internal_member(self):