コード例 #1
0
ファイル: jobs.py プロジェクト: bac/jenkins-github-lander
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
コード例 #2
0
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
コード例 #3
0
    def test_pull_request_kicked(self):
        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('juju', 'project', 'jujugui', None)
        resp = pull_request_kicked(pull_request, 'http://jenkins/job/1', info)
        comment = resp['body']
        self.assertIn(github.MERGE_SCHEDULED, comment)