def add_labels_to_pr(repo: GithubRepository, pull_id: int, *labels: str) -> None: """Add lables to a pull request. References: https://developer.github.com/v3/issues/labels/#add-labels-to-an-issue Args: repo: The github repo where the pull request lives. pull_id: The id of the pull request. *labels: The labels to add to the pull request. Raises: RuntimeError: If the request to add labels returned anything other than success. """ url = "https://api.github.com/repos/{}/{}/issues/{}/labels".format( repo.organization, repo.name, pull_id ) response = repo.post(url, json=list(labels)) if response.status_code != 200: raise RuntimeError( 'Add labels failed. Code: {}. Content: {!r}.'.format( response.status_code, response.content ) )
def add_comment(repo: GithubRepository, pull_id: int, text: str) -> None: """Add a comment to a pull request. References: https://developer.github.com/v3/issues/comments/#create-a-comment Arg: rep: The github repo whose pull request should have a comment added to. pull_id: The id of the pull request to comment on. text: The text of the comment. Raises: RuntimeError: If the request does not return status 201 (created). """ url = "https://api.github.com/repos/{}/{}/issues/{}/comments".format( repo.organization, repo.name, pull_id ) data = {'body': text} response = repo.post(url, json=data) if response.status_code != 201: raise RuntimeError( 'Add comment failed. Code: {}. Content: {!r}.'.format( response.status_code, response.content ) )
def add_labels_to_pr(repo: GithubRepository, pull_id: int, *labels: str) -> None: """ References: https://developer.github.com/v3/issues/labels/#add-labels-to-an-issue """ url = "https://api.github.com/repos/{}/{}/issues/{}/labels".format( repo.organization, repo.name, pull_id) response = repo.post(url, json=list(labels)) if response.status_code != 200: raise RuntimeError( 'Add labels failed. Code: {}. Content: {!r}.'.format( response.status_code, response.content))
def add_comment(repo: GithubRepository, pull_id: int, text: str) -> None: """ References: https://developer.github.com/v3/issues/comments/#create-a-comment """ url = "https://api.github.com/repos/{}/{}/issues/{}/comments".format( repo.organization, repo.name, pull_id) data = {'body': text} response = repo.post(url, json=data) if response.status_code != 201: raise RuntimeError( 'Add comment failed. Code: {}. Content: {!r}.'.format( response.status_code, response.content))