def test_mergeable_pull_requests(self): pulls = load_data('github-open-pulls.json') orgs = load_data('github-user-orgs.json') comments = load_data('github-pull-request-comments.json') responses.add( responses.GET, 'https://api.github.com/users/mitechie/orgs', body=orgs, status=200, content_type='application/json' ) responses.add( responses.GET, 'https://api.github.com/repos/CanonicalJS/juju-gui/pulls', body=pulls, status=200, content_type='application/json' ) responses.add( responses.GET, ( u'https://api.github.com/repos/CanonicalJS/juju-gui/issues/5/' u'comments' ), body=comments, status=200, content_type='application/json' ) info = GithubInfo('CanonicalJS', 'juju-gui', 'jujugui', None) mergeable = mergeable_pull_requests('$$merge$$', info) self.assertEqual(1, len(mergeable)) self.assertEqual(5, mergeable[0]['number'])
def test_no_mergeable_pull_requests(self): pulls = load_data('github-open-pulls.json') responses.add( responses.GET, 'https://api.github.com/repos/juju/project/pulls', body=pulls, status=200, content_type='application/json' ) comments = load_data( 'github-pull-request-comments.json', load_json=True) # Remove the first comment since it's the trigger one. comments.pop(0) responses.add( responses.GET, ( u'https://api.github.com/repos/CanonicalJS/juju-gui/issues/5/' u'comments' ), body=json.dumps(comments), status=200, content_type='application/json' ) info = GithubInfo('juju', 'project', 'jujugui', None) mergeable = mergeable_pull_requests('$$merge$$', info) self.assertEqual(0, len(mergeable))
def trigger_mergable_commits(request): config = request.registry.settings mergable = mergeable_pull_requests( config['jenkins.merge.trigger'], GithubInfo( config['github.owner'], config['github.project'], config['github.username'], config['github.token'], ) ) if mergable: kicked = [] jenkins_info = JenkinsInfo( config['jenkins.merge.url'], config['jenkins.merge.job'], config['jenkins.merge.token'], ) for pr in mergable: kick_jenkins_merge(pr['number'], pr['head']['sha'], jenkins_info) kicked.append('Kicking pull request: {} at sha {}'.format( pr['number'], pr['head']['sha'] )) ret = "\n".join(kicked) else: ret = "No pull requests to merge." return Response(ret)
def kick_mergeable_pull_requests(config): """Check github for pull requests that include the merge command. If the merge command is found, the -merge job in jenkins is kicked to start running. :return kicked: The list of pull requests that were kicked. """ github_info = GithubInfo( config['github.owner'], config['github.project'], config['github.username'], config['github.token'], ) mergable = mergeable_pull_requests( config['jenkins.merge.trigger'], github_info, ) kicked = [] if mergable: jenkins_info = JenkinsInfo( config['jenkins.merge.url'], config['jenkins.merge.job'], config['jenkins.merge.token'], ) for pr in mergable: try: kick_jenkins_merge( pr['number'], pr['head']['sha'], jenkins_info) kicked.append('Kicking pull request: {} at sha {}'.format( pr['number'], pr['head']['sha'] )) # Notify the pull request that we've scheduled a build for it. jenkins_url = generate_job_url(jenkins_info) pull_request_kicked(pr, jenkins_url, github_info) except JenkinsError as exc: kicked.append( 'Failed to kick {0}. Failure message: {1}'.format( pr['number'], exc ) ) return kicked
def kick_mergeable_pull_requests(config): """Check github for pull requests that include the merge command. If the merge command is found, the -merge job in jenkins is kicked to start running. :return kicked: The list of pull requests that were kicked. """ github_info = GithubInfo( config['github.owner'], config['github.project'], config['github.username'], config['github.token'], ) mergable = mergeable_pull_requests( config['jenkins.merge.trigger'], github_info, ) kicked = [] if mergable: jenkins_info = JenkinsInfo( config['jenkins.merge.url'], config['jenkins.merge.job'], config['jenkins.merge.token'], ) for pr in mergable: try: kick_jenkins_merge(pr['number'], pr['head']['sha'], jenkins_info) kicked.append('Kicking pull request: {} at sha {}'.format( pr['number'], pr['head']['sha'])) # Notify the pull request that we've scheduled a build for it. jenkins_url = generate_job_url(jenkins_info) pull_request_kicked(pr, jenkins_url, github_info) except JenkinsError as exc: kicked.append( 'Failed to kick {0}. Failure message: {1}'.format( pr['number'], exc)) return kicked
def test_not_mergable_if_already_merging(self): pulls = load_data('github-open-pulls.json') orgs = load_data('github-user-orgs.json') comments = load_data( 'github-pull-request-comments.json', load_json=True) # Add the currently merging comment to the list of the pull request to # verify it does not mark this as a mergable pull request then. merging_comment = load_data( 'github-new-issue-comment.json', load_json=True) comments.append(merging_comment) responses.add( responses.GET, 'https://api.github.com/users/mitechie/orgs', body=orgs, status=200, content_type='application/json' ) responses.add( responses.GET, 'https://api.github.com/repos/CanonicalJS/juju-gui/pulls', body=pulls, status=200, content_type='application/json' ) responses.add( responses.GET, ( u'https://api.github.com/repos/CanonicalJS/juju-gui/issues/5/' u'comments' ), body=json.dumps(comments), status=200, content_type='application/json' ) info = GithubInfo('CanonicalJS', 'juju-gui', 'jujugui', None) mergeable = mergeable_pull_requests('$$merge$$', info) self.assertEqual(0, len(mergeable))
def test_not_mergeable_if_not_in_org(self): pulls = load_data('github-open-pulls.json') orgs = load_data('github-user-orgs.json', load_json=True) comments = load_data('github-pull-request-comments.json') # Remove the CanonicalJS group so that the user fails to be in the #org. orgs.pop(0) responses.add( responses.GET, 'https://api.github.com/users/mitechie/orgs', body=json.dumps(orgs), status=200, content_type='application/json' ) responses.add( responses.GET, 'https://api.github.com/repos/juju/project/pulls', body=pulls, status=200, content_type='application/json' ) responses.add( responses.GET, ( u'https://api.github.com/repos/CanonicalJS/juju-gui/issues/5/' u'comments' ), body=comments, status=200, content_type='application/json' ) info = GithubInfo('juju', 'project', 'jujugui', None) mergeable = mergeable_pull_requests('$$merge$$', info) self.assertEqual(0, len(mergeable))