Skip to content

Commit 55492fd

Browse files
authored
Merge pull request #169 from plone/erral-weblate-checks
ignore weblate, 2nd round
2 parents e64f3a8 + b5313c9 commit 55492fd

File tree

2 files changed

+62
-21
lines changed

2 files changed

+62
-21
lines changed

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## (unreleased)
44

5-
- _nothing_
5+
- Ignore weblate user on contributing agreement check (2nd change) [erral, fredvd]_
66

77
## 1.2.9 (2025-03-31)
88

src/mr.roboto/src/mr/roboto/subscriber.py

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@
8181
# when their PRs get merged
8282
IGNORE_PR_AUTHORS = ("pre-commit-ci[bot]",)
8383

84+
IGNORE_WEBLATE = {
85+
# Repo Ignored individual user checks
86+
"volto": ["weblate"]
87+
}
88+
8489

8590
class PullRequestSubscriber:
8691
def __init__(self, event):
@@ -183,32 +188,68 @@ def get_json_commits(self):
183188

184189
return json_data
185190

191+
def is_weblate(self, commit_info):
192+
"""check whether this commit info belongs to a user
193+
that we have to ignore.
194+
195+
When checking weblate commits, we often found this kind of info
196+
197+
{
198+
...
199+
"author": null,
200+
"committer": {"login": "weblate", ...},
201+
...
202+
},
203+
204+
This is because weblate is in itself a git repository and this JSON
205+
is produced by GitHub.
206+
207+
Sometimes some weblate addons have not a corresponding user on GitHub
208+
so the `author` value comes as `null`.
209+
210+
In such cases our check (see `check_membership`) does not work, because
211+
we check for both `author` and `committer`.
212+
213+
This is a shortcut, to check whether the committer login is something we
214+
previously know, and if so we ignore it.
215+
216+
"""
217+
if self.repo_name in IGNORE_WEBLATE:
218+
if (
219+
commit_info.get("committer", {}).get("login", "")
220+
in IGNORE_WEBLATE[self.repo_name]
221+
):
222+
return True
223+
224+
return False
225+
186226
def check_membership(self, json_data):
187227
plone_org = self.github.get_organization("plone")
188228
unknown = []
189229
members = []
190230
not_foundation = []
191231
for commit_info in json_data:
192-
for user in ("committer", "author"):
193-
try:
194-
login = commit_info[user]["login"]
195-
except TypeError:
196-
self.log(f"commit does not have {user} user info")
197-
unknown.append(commit_info["commit"]["author"]["name"])
198-
continue
199-
200-
if login in IGNORE_USER_NO_AGREEMENT:
201-
continue
202-
203-
# avoid looking up users twice
204-
if login in members or login in not_foundation:
205-
continue
206-
207-
g_user = self.github.get_user(login)
208-
if plone_org.has_in_members(g_user):
209-
members.append(login)
210-
else:
211-
not_foundation.append(login)
232+
if not self.is_weblate(commit_info):
233+
for user in ("committer", "author"):
234+
try:
235+
login = commit_info[user]["login"]
236+
except TypeError:
237+
self.log(f"commit does not have {user} user info")
238+
unknown.append(commit_info["commit"]["author"]["name"])
239+
continue
240+
241+
if login in IGNORE_USER_NO_AGREEMENT:
242+
continue
243+
244+
# avoid looking up users twice
245+
if login in members or login in not_foundation:
246+
continue
247+
248+
g_user = self.github.get_user(login)
249+
if plone_org.has_in_members(g_user):
250+
members.append(login)
251+
else:
252+
not_foundation.append(login)
212253

213254
return not_foundation, unknown
214255

0 commit comments

Comments
 (0)