in asfyaml/feature/github/collaborators.py [0:0]
def collaborators(self: ASFGitHubFeature):
# Collaborator list for triage rights
collabs = self.yaml.get("collaborators", [])
old_collabs = set()
new_collabs = set(collabs)
if collabs and self.repository.is_private:
raise Exception("You cannot set outside collaborators for private repositories.")
if len(new_collabs) > constants.MAX_COLLABORATORS:
raise Exception(
f"You can only have a maximum of {constants.MAX_COLLABORATORS} external triage collaborators, please contact vp-infra@apache.org to request an exception."
)
for user in collabs:
if not re.match(r"^[A-Za-z\d](?:[-A-Za-z\d]|-(?=[A-Za-z\d])){0,38}$", user):
raise Exception("Username %s in collaborator list is not a valid GitHub ID!" % user)
collab_file = os.path.join(self.repository.path, "github_collaborators.txt")
if os.path.exists(collab_file):
old_collabs = set([x.strip() for x in open(collab_file) if x.strip()])
if new_collabs != old_collabs:
print("Updating collaborator list for GitHub")
to_remove = old_collabs - new_collabs
to_add = new_collabs - old_collabs
for user in to_remove:
print("Removing GitHub triage access for %s" % user)
if not self.noop("collaborators"):
self.ghrepo.remove_from_collaborators(user)
for user in to_add:
print("Adding GitHub triage access for %s" % user)
if not self.noop("collaborators"):
self.ghrepo.add_to_collaborators(user, permission="triage")
with open(collab_file, "w") as f:
f.write("\n".join(collabs))
f.close()