|
81 | 81 | # when their PRs get merged |
82 | 82 | IGNORE_PR_AUTHORS = ("pre-commit-ci[bot]",) |
83 | 83 |
|
| 84 | +IGNORE_WEBLATE = { |
| 85 | + # Repo Ignored individual user checks |
| 86 | + "volto": ["weblate"] |
| 87 | +} |
| 88 | + |
84 | 89 |
|
85 | 90 | class PullRequestSubscriber: |
86 | 91 | def __init__(self, event): |
@@ -183,32 +188,68 @@ def get_json_commits(self): |
183 | 188 |
|
184 | 189 | return json_data |
185 | 190 |
|
| 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 | + |
186 | 226 | def check_membership(self, json_data): |
187 | 227 | plone_org = self.github.get_organization("plone") |
188 | 228 | unknown = [] |
189 | 229 | members = [] |
190 | 230 | not_foundation = [] |
191 | 231 | 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) |
212 | 253 |
|
213 | 254 | return not_foundation, unknown |
214 | 255 |
|
|
0 commit comments