Skip to content

Commit 75e4258

Browse files
authored
PR helper removes maintainers from known contributors. (#10773)
Details: #10758 (comment)
1 parent 777176b commit 75e4258

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

.github/workflows/pr_helper.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: PR helper
22
on:
33
pull_request_target:
4-
types: [opened, reopened]
4+
types: [opened]
55
branches:
66
- master
77
paths:

infra/pr_helper.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ def __init__(self):
158158
'Authorization': f'Bearer {self._token}',
159159
'X-GitHub-Api-Version': '2022-11-28'
160160
}
161+
self._maintainers = set()
161162
os.environ['GITHUB_AUTH_TOKEN'] = self._token
162163

163164
def get_pr_author(self):
@@ -244,6 +245,8 @@ def get_past_contributors(self, project_path):
244245

245246
login = commit['author']['login']
246247
verified = commit['commit']['verification']['verified']
248+
if login in self._maintainers:
249+
continue
247250
if login not in contributors:
248251
contributors[login] = verified
249252
if verified:
@@ -257,19 +260,25 @@ def get_past_contributors(self, project_path):
257260

258261
return all_contributors
259262

260-
def is_author_internal_member(self):
261-
"""Returns if the author is an internal member."""
263+
def get_maintainers(self):
264+
"""Get a list of internal members."""
265+
if self._maintainers:
266+
return self._maintainers
267+
262268
response = requests.get(f'{BASE_URL}/contents/infra/MAINTAINERS.csv',
263269
headers=self._headers)
264270
if not response.ok:
265-
return False
271+
return self._maintainers
266272

267-
maintainers = base64.b64decode(response.json()['content']).decode('UTF-8')
268-
for line in maintainers.split(os.linesep):
269-
if self._pr_author == line.split(',')[2]:
270-
return True
273+
maintainers_file = base64.b64decode(
274+
response.json()['content']).decode('UTF-8')
275+
for line in maintainers_file.split(os.linesep):
276+
self._maintainers.add(line.split(',')[2])
277+
return self._maintainers
271278

272-
return False
279+
def is_author_internal_member(self):
280+
"""Returns if the author is an internal member."""
281+
return self._pr_author in self.get_maintainers()
273282

274283
def has_author_modified_project(self, project_path):
275284
"""Checks if the author has modified this project before."""

0 commit comments

Comments
 (0)