[llvm] [GitHub] Add workflow to check author's commit access on new PRs (PR #123593)
David Spickett via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 20 05:43:51 PST 2025
================
@@ -290,6 +290,32 @@ def run(self) -> bool:
return True
+class CheckCommitAccess:
+ def __init__(self, token: str, repo: str, pr_number: int, author: str):
+ self.repo = github.Github(token).get_repo(repo)
+ self.pr = self.repo.get_issue(pr_number).as_pull_request()
+ self.author = author
+
+ def can_merge(self, user: str) -> bool:
+ try:
+ return self.repo.get_collaborator_permission(user) in ["admin", "write"]
----------------
DavidSpickett wrote:
I did not know about this, however I don't think we can use it here.https://pygithub.readthedocs.io/en/stable/github_objects/Repository.html?highlight=get_collaborator_permission#github.Repository.Repository.get_collaborators returns a list of all collaborators in the form of https://pygithub.readthedocs.io/en/stable/github_objects/NamedUser.html#github.NamedUser.NamedUser, which doesn't have a way to get to the permissions.
I see existing code on GitHub mainly using `get_collaborators` to get a list of usernames, then passing those one by one to `get_collaborator_permission`. I presume in workflows that cover the whole project not just one PR, here we just have them to check.
https://github.com/llvm/llvm-project/pull/123593
More information about the llvm-commits
mailing list