-def validate_maintainers(repo, github_token):
- # type: (str, str) -> None
- '''Ensure all maintainers are assignable on a GitHub repo'''
- next_link_re = re.compile(r'<([^>]+)>; rel="next"')
-
- # Load the list of assignable people in the GitHub repo
- assignable = [] # type: typing.List[str]
- url = 'https://api.github.com/repos/' \
- + '%s/collaborators?per_page=100' % repo # type: typing.Optional[str]
- while url is not None:
- response = urllib2.urlopen(urllib2.Request(url, headers={
- 'Authorization': 'token ' + github_token,
- # Properly load nested teams.
- 'Accept': 'application/vnd.github.hellcat-preview+json',
- }))
- assignable.extend(user['login'] for user in load_json_from_response(response))
- # Load the next page if available
- url = None
- link_header = response.headers.get('Link')
- if link_header:
- matches = next_link_re.match(link_header)
- if matches is not None:
- url = matches.group(1)
-
- errors = False
- for tool, maintainers in MAINTAINERS.items():
- for maintainer in maintainers:
- if maintainer not in assignable:
- errors = True
- print(
- "error: %s maintainer @%s is not assignable in the %s repo"
- % (tool, maintainer, repo),
- )
-
- if errors:
- print()
- print(" To be assignable, a person needs to be explicitly listed as a")
- print(" collaborator in the repository settings. The simple way to")
- print(" fix this is to ask someone with 'admin' privileges on the repo")
- print(" to add the person or whole team as a collaborator with 'read'")
- print(" privileges. Those privileges don't grant any extra permissions")
- print(" so it's safe to apply them.")
- print()
- print("The build will fail due to this.")
- exit(1)
-