Getting a Repository Owner
Overview
A major use case for the GraphQL section of the toolkit, is to get a point of contact for a given repository. This can be done using the github_graphql_interface() class.
Prerequisites
-
The GitHub organisation must have verified domain emails. Please see this GitHub Doc.
-
The repository must contain a CODEOWNERS file at either the root of the repository, within a
.githubfolder at the root of the repository or within a/docsfolder at the root of the repository. -
The CODEOWNERS file can contain a mixture of GitHub Teams and Usernames. Emails within a CODEOWNERS file are ignored.
-
The GitHub Team within the CODEOWNERS file must have a member with the maintainer role. This person is identified as a repository owner from the team.
Python Example
The following code snippet does the following:
-
Get all variables from the environment.
-
Create a GitHub Access Token to make API requests.
-
Create an instance of the GraphQL interface.
-
Run
get_repository_email_list()to get a list of CODEOWNER emails for that repository.
import github_api_toolkit as gat
from os import getenv
github_org = getenv("GITHUB_ORG")
pem_contents = getenv("SECRET")
github_app_id = getenv("APP_ID")
github_repo = getenv("GITHUB_REPO")
token = gat.get_token_as_installation(github_org, pem_contents, github_app_id)
api = gat.github_graphql_interface(token[0])
emails = api.get_repository_email_list(github_org, github_repo)
print(emails)