def test_pull_request_build_failed(self): """Adds a comment to the pull request about the failure.""" new_comment = load_data('github-new-issue-comment.json') pulls = load_data('github-open-pulls.json', load_json=True) pull_request = pulls[0] responses.add( responses.POST, ( u'https://api.github.com/repos/CanonicalJS/juju-gui/issues/5/' u'comments' ), body=new_comment, status=201, content_type='application/json' ) info = GithubInfo('CanonicalJS', 'juju-gui', 'jujugui', '1234') result = pull_request_build_failed( pull_request, 'http://jenkins.com/job/gui/12', 'Failure message', info ) self.assertTrue('body' in result)
def mark_pull_request_build_failed(pr, build_number, failure_message, config): """The given pull request failed to build. Comment on the pull request to alert the devs of this issue. """ github_info = GithubInfo( config['github.owner'], config['github.project'], config['github.username'], config['github.token'], ) jenkins_info = JenkinsInfo( config['jenkins.merge.url'], config['jenkins.merge.job'], config['jenkins.merge.token'], ) pull_request = get_pull_request(pr, github_info) build_url = generate_build_url(build_number, jenkins_info) try: comment = pull_request_build_failed(pull_request, build_url, failure_message, github_info) return comment['url'] except GithubError as exc: return 'Failed to add comment: {0}'.format(exc)
def mark_pull_request_build_failed(pr, build_number, failure_message, config): """The given pull request failed to build. Comment on the pull request to alert the devs of this issue. """ github_info = GithubInfo( config['github.owner'], config['github.project'], config['github.username'], config['github.token'], ) jenkins_info = JenkinsInfo( config['jenkins.merge.url'], config['jenkins.merge.job'], config['jenkins.merge.token'], ) pull_request = get_pull_request(pr, github_info) build_url = generate_build_url(build_number, jenkins_info) try: comment = pull_request_build_failed( pull_request, build_url, failure_message, github_info ) return comment['url'] except GithubError as exc: return 'Failed to add comment: {0}'.format(exc)