def remove_label_from_pr(repo: GithubRepository, pull_id: int, label: str) -> bool: """Removes a label from a pull request. References: https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue Args: repo: The github repo for the pull request. pull_id: The id for the pull request. label: The label to remove. Raises: RuntimeError: If the request does not return status 200 (success). Returns: True if the label existed and was deleted. False if the label did not exist. """ url = "https://api.github.com/repos/{}/{}/issues/{}/labels/{}".format( repo.organization, repo.name, pull_id, label) response = repo.delete(url) if response.status_code == 404: payload = json.JSONDecoder().decode(response.content.decode()) if payload['message'] == 'Label does not exist': return False if response.status_code == 200: # Removed the label. return True raise RuntimeError('Label remove failed. Code: {}. Content: {!r}.'.format( response.status_code, response.content))
def delete_comment(repo: GithubRepository, comment_id: int) -> None: """ References: https://developer.github.com/v3/issues/comments/#delete-a-comment """ url = "https://api.github.com/repos/{}/{}/issues/comments/{}".format( repo.organization, repo.name, comment_id) response = repo.delete(url) if response.status_code != 204: raise RuntimeError( 'Comment delete failed. Code: {}. Content: {!r}.'.format( response.status_code, response.content))
def delete_comment(repo: GithubRepository, comment_id: int) -> None: """Delete a comment. References: https://developer.github.com/v3/issues/comments/#delete-a-comment Args: repo: The github repo where the comment lives. comment_id: The id of the comment to delete. Raises: RuntimeError: If the request does not return status 204 (no content). """ url = "https://api.github.com/repos/{}/{}/issues/comments/{}".format( repo.organization, repo.name, comment_id) response = repo.delete(url) if response.status_code != 204: raise RuntimeError( 'Comment delete failed. Code: {}. Content: {!r}.'.format( response.status_code, response.content))
def remove_label_from_pr(repo: GithubRepository, pull_id: int, label: str) -> bool: """ References: https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue """ url = "https://api.github.com/repos/{}/{}/issues/{}/labels/{}".format( repo.organization, repo.name, pull_id, label) response = repo.delete(url) if response.status_code == 404: payload = json.JSONDecoder().decode(response.content.decode()) if payload['message'] == 'Label does not exist': return False if response.status_code == 200: # Removed the label. return True raise RuntimeError('Label remove failed. Code: {}. Content: {!r}.'.format( response.status_code, response.content))