示例#1
0
    def test_load_changes(self):
        gh = self.get_mock_client(fixture_data)
        subject = Processor(gh, 1, '123abc', './tests')
        subject.load_changes()

        eq_(1, len(subject._changes), 'File count is wrong')
        assert isinstance(subject._changes, DiffCollection)
示例#2
0
    def test_run_tools__no_changes(self):
        pull = self.get_pull_request()
        repo = Mock()

        config = build_review_config('', app_config)
        subject = Processor(repo, pull, './tests', config)
        subject.run_tools()
示例#3
0
    def test_run_tools__execute_fixers(self):
        pull = self.get_pull_request()
        repo = Mock()

        self.tool_stub.factory.return_value = sentinel.tools

        self.fixer_stub.create_context.return_value = sentinel.context
        self.fixer_stub.run_fixers.return_value = sentinel.diff

        config = build_review_config(fixer_ini, app_config)
        subject = Processor(repo, pull, './tests', config)
        subject.load_changes()
        subject.run_tools()

        file_path = 'View/Helper/AssetCompressHelper.php'
        self.fixer_stub.create_context.assert_called_with(
            config,
            './tests',
            repo,
            pull
        )
        self.fixer_stub.run_fixers.assert_called_with(
            sentinel.tools,
            './tests',
            [file_path]
        )
        self.fixer_stub.apply_fixer_diff.assert_called_with(
            subject._changes,
            sentinel.diff,
            sentinel.context
        )
        self.tool_stub.run.assert_called()
示例#4
0
    def test_load_changes(self):
        gh = self.get_mock_client(fixture_data)
        subject = Processor(gh, 1, '123abc', './tests')
        subject.load_changes()

        eq_(1, len(subject._changes), 'File count is wrong')
        assert isinstance(subject._changes, DiffCollection)
示例#5
0
 def test_run_tools(self, tool_stub):
     stub = Mock()
     subject = Processor(None, 1, '123abc', './tests')
     subject._changes = Mock()
     subject.run_tools(stub)
     assert tool_stub.run.called, 'Should have ran'
     assert subject._changes.get_files.called, 'Should have been called'
     assert stub.ignore_patterns.called
示例#6
0
 def test_run_tools(self, tool_stub):
     stub = Mock()
     subject = Processor(None, 1, '123abc', './tests')
     subject._changes = Mock()
     subject.run_tools(stub)
     assert tool_stub.run.called, 'Should have ran'
     assert subject._changes.get_files.called, 'Should have been called'
     assert stub.ignore_patterns.called
示例#7
0
    def test_load_changes(self):
        pull = self.get_pull_request()
        repo = Mock()

        subject = Processor(repo, pull, './tests', app_config)
        subject.load_changes()

        eq_(1, len(subject._changes), 'File count is wrong')
        assert isinstance(subject._changes, DiffCollection)
示例#8
0
    def test_load_changes(self):
        pull = self.get_pull_request(fixture_data)
        repo = Mock()

        subject = Processor(repo, pull, './tests')
        subject.load_changes()

        eq_(1, len(subject._changes), 'File count is wrong')
        assert isinstance(subject._changes, DiffCollection)
示例#9
0
    def test_run_tools(self, tool_stub):
        gh = self.get_mock_client(load_fixture('commits.json'))

        stub_config = Mock()
        subject = Processor(gh, 1, '123abc', './tests')
        subject._changes = Mock()
        subject.run_tools(stub_config)
        assert tool_stub.run.called, 'Should have ran'
        assert subject._changes.get_files.called, 'Should have been called'
        assert stub_config.ignore_patterns.called
示例#10
0
    def test_run_tools(self, tool_stub):
        gh = self.get_mock_client(load_fixture('commits.json'))

        stub_config = Mock()
        subject = Processor(gh, 1, '123abc', './tests')
        subject._changes = Mock()
        subject.run_tools(stub_config)
        assert tool_stub.run.called, 'Should have ran'
        assert subject._changes.get_files.called, 'Should have been called'
        assert stub_config.ignore_patterns.called
示例#11
0
    def test_load_changes(self):
        pull = self.get_pull_request()
        repo = Mock()

        config = build_review_config('', app_config)
        subject = Processor(repo, pull, './tests', config)
        subject.load_changes()

        self.assertEqual(1, len(subject._changes), 'File count is wrong')
        assert isinstance(subject._changes, DiffCollection)
示例#12
0
    def test_load_changes(self, http):
        gh = Github()
        response = Response()
        response._content = fixture_data
        http.return_value = response

        subject = Processor(gh, 1, '123abc', './tests')
        subject.load_changes()

        eq_(1, len(subject._changes), 'File count is wrong')
        assert isinstance(subject._changes, DiffCollection)
示例#13
0
    def test_run_tools(self, tool_stub):
        pull = self.get_pull_request(load_fixture('commits.json'))
        repo = Mock()

        stub_config = Mock()
        subject = Processor(repo, pull, './tests')
        subject._changes = Mock()
        subject.run_tools(stub_config)
        assert tool_stub.run.called, 'Should have ran'
        assert subject._changes.get_files.called, 'Should have been called'
        assert stub_config.ignore_patterns.called
示例#14
0
    def test_load_changes(self, http):
        gh = Github()
        response = Response()
        response._content = fixture_data
        http.return_value = response

        subject = Processor(gh, 1, '123abc', './tests')
        subject.load_changes()

        eq_(1, len(subject._changes), 'File count is wrong')
        assert isinstance(subject._changes, DiffCollection)
示例#15
0
    def test_run_tools(self, tool_stub):
        pull = self.get_pull_request(load_fixture('commits.json'))
        repo = Mock()

        stub_config = Mock()
        subject = Processor(repo, pull, './tests')
        subject._changes = Mock()
        subject.run_tools(stub_config)
        assert tool_stub.run.called, 'Should have ran'
        assert subject._changes.get_files.called, 'Should have been called'
        assert stub_config.ignore_patterns.called
示例#16
0
    def test_run_tools(self, tool_stub, http):
        response = Response()
        response._content = load_fixture('commits.json')
        http.return_value = response

        stub = Mock()
        subject = Processor(http, 1, '123abc', './tests')
        subject._changes = Mock()
        subject.run_tools(stub)
        assert tool_stub.run.called, 'Should have ran'
        assert subject._changes.get_files.called, 'Should have been called'
        assert stub.ignore_patterns.called
示例#17
0
    def test_publish(self):
        subject = Processor(None, 1, '123abc', './tests')
        subject._problems = Mock()
        subject._review = Mock()

        subject.publish()
        self.assertTrue(
            subject._problems.limit_to_changes.called,
            'Problems should be filtered.')
        self.assertTrue(
            subject._review.publish.called,
            'Review should be published.')
示例#18
0
    def test_run_tools(self, tool_stub, http):
        response = Response()
        response._content = load_fixture('commits.json')
        http.return_value = response

        stub = Mock()
        subject = Processor(http, 1, '123abc', './tests')
        subject._changes = Mock()
        subject.run_tools(stub)
        assert tool_stub.run.called, 'Should have ran'
        assert subject._changes.get_files.called, 'Should have been called'
        assert stub.ignore_patterns.called
示例#19
0
    def test_publish(self):
        subject = Processor(None, 1, '123abc', './tests', {'SUMMARY_THRESHOLD': 50})
        subject._problems = Mock()
        subject._review = Mock()

        subject.publish()
        self.assertTrue(
            subject._problems.limit_to_changes.called,
            'Problems should be filtered.')
        self.assertTrue(
            subject._review.publish.called,
            'Review should be published.')
        subject._review.publish.assert_called_with(
            subject._problems, '123abc', 50)
示例#20
0
def process_pull_request(user, repo, number, lintrc):
    """
    Starts processing a pull request and running the various
    lint tools against it.
    """
    log.info('Starting to process lint for %s/%s/%s', user, repo, number)
    log.debug("lintrc contents '%s'", lintrc)
    review_config = ReviewConfig(lintrc)

    if len(review_config.linters()) == 0:
        log.info('No configured linters, skipping processing.')
        return

    gh = github.get_client(config, user, repo)
    try:
        log.info('Loading pull request data from github.')
        pull_request = gh.pull_requests.get(number)
        head_repo = pull_request.head['repo']['git_url']
        pr_head = pull_request.head['sha']

        # Clone/Update repository
        target_path = git.get_repo_path(user, repo, number, config)
        git.clone_or_update(head_repo, target_path, pr_head)

        processor = Processor(gh, number, pr_head, target_path, config)
        processor.load_changes()
        processor.run_tools(review_config)
        processor.publish()

        log.info('Completed lint processing for %s/%s/%s' %
                 (user, repo, number))
    except BaseException, e:
        log.exception(e)
示例#21
0
def process_pull_request(self, user, repo_name, number, lintrc):
    """
    Starts processing a pull request and running the various
    lint tools against it.
    """
    log.info('Starting to process lint for %s/%s/%s', user, repo_name, number)
    log.debug("lintrc contents '%s'", lintrc)
    review_config = build_review_config(lintrc, deepcopy(config))

    if len(review_config.linters()) == 0:
        log.info('No configured linters, skipping processing.')
        return

    try:
        log.info(
            'Loading pull request data from github. user=%s '
            'repo=%s number=%s', user, repo_name, number)
        repo = GithubRepository(config, user, repo_name)
        pull_request = repo.pull_request(number)

        clone_url = pull_request.clone_url

        pr_head = pull_request.head
        target_branch = pull_request.target_branch

        if target_branch in review_config.ignore_branches():
            log.info('Pull request into ignored branch %s, skipping review.',
                     target_branch)
            return

        repo.create_status(pr_head, 'pending', 'Lintreview processing')

        # Clone/Update repository
        target_path = git.get_repo_path(user, repo_name, number, config)
        git.clone_or_update(config, clone_url, target_path, pr_head)

        processor = Processor(repo, pull_request, target_path, review_config)
        processor.load_changes()
        processor.run_tools()
        processor.publish()

        log.info('Completed lint processing for %s/%s/%s' %
                 (user, repo_name, number))

    except Exception as e:
        log.exception(e)
    except TimeoutError as e:
        log.exception(e)
        raise self.retry(
            countdown=5,  # Pause for 5 seconds to clear things out
            max_retries=2,  # only give it one more shot
        )
    finally:
        try:
            git.destroy(target_path)
            log.info('Cleaned up pull request %s/%s/%s', user, repo_name,
                     number)
        except Exception as e:
            log.exception(e)
示例#22
0
    def test_publish(self):
        gh = self.get_mock_client(load_fixture('commits.json'))

        subject = Processor(gh, 1, '123abc', './tests', {'SUMMARY_THRESHOLD': 50})
        subject._problems = Mock()
        subject._review = Mock()

        subject.publish()
        self.assertTrue(
            subject._problems.limit_to_changes.called,
            'Problems should be filtered.')
        self.assertTrue(
            subject._review.publish.called,
            'Review should be published.')
        subject._review.publish.assert_called_with(
            subject._problems, '123abc', 50)
示例#23
0
    def test_publish(self):
        pull = self.get_pull_request()
        repo = Mock()

        config = build_review_config(fixer_ini, app_config)
        subject = Processor(repo, pull, './tests', config)
        subject.problems = Mock()
        subject._review = Mock()

        subject.publish()
        self.assertTrue(subject.problems.limit_to_changes.called,
                        'Problems should be filtered.')
        self.assertTrue(subject._review.publish_review.called,
                        'Review should be published.')
        subject._review.publish_review.assert_called_with(
            subject.problems,
            pull.head)
示例#24
0
    def test_run_tools__ignore_patterns(self):
        pull = self.get_pull_request()
        repo = Mock()

        config = build_review_config(fixer_ini, app_config)
        config.ignore_patterns = lambda: [
            'View/Helper/*']

        subject = Processor(repo, pull, './tests', config)
        subject.load_changes()
        subject.run_tools()

        self.tool_stub.run.assert_called_with(
            ANY,
            [],
            ANY
        )
示例#25
0
def process_pull_request(user, repo, number, lintrc):
    """
    Starts processing a pull request and running the various
    lint tools against it.
    """
    log.info('Starting to process lint for %s/%s/%s', user, repo, number)
    log.debug("lintrc contents '%s'", lintrc)
    review_config = ReviewConfig(lintrc)

    if len(review_config.linters()) == 0:
        log.info('No configured linters, skipping processing.')
        return

    gh = github.get_client(config, user, repo)
    try:
        log.info('Loading pull request data from github.')
        pull_request = gh.pull_requests.get(number)
        head_repo = pull_request.head['repo']['clone_url']
        private_repo = pull_request.head['repo']['private']
        pr_head = pull_request.head['sha']

        # Clone/Update repository
        target_path = git.get_repo_path(user, repo, number, config)
        git.clone_or_update(config, head_repo, target_path, pr_head,
                            private_repo)

        processor = Processor(gh, number, pr_head, target_path, config)
        processor.load_changes()
        processor.run_tools(review_config)
        processor.publish()

        log.info('Completed lint processing for %s/%s/%s' % (
            user, repo, number))
    except BaseException, e:
        log.exception(e)
示例#26
0
    def test_run_tools__execute_fixers_fail(self):
        pull = self.get_pull_request()
        repo = Mock()

        self.tool_stub.factory.return_value = sentinel.tools

        self.fixer_stub.create_context.return_value = sentinel.context
        self.fixer_stub.run_fixers.side_effect = RuntimeError

        config = build_review_config(fixer_ini, app_config)
        subject = Processor(repo, pull, './tests', config)
        subject.load_changes()
        subject.run_tools()

        self.fixer_stub.create_context.assert_called()
        self.fixer_stub.run_fixers.assert_called()
        self.fixer_stub.apply_fixer_diff.assert_not_called()
        self.fixer_stub.rollback_changes.assert_called()
        self.tool_stub.run_assert_called()
示例#27
0
def process_pull_request(self, user, repo_name, number, lintrc):
    """
    Starts processing a pull request and running the various
    lint tools against it.
    """
    log.info('Starting to process lint for %s/%s/%s', user, repo_name, number)
    log.debug("lintrc contents '%s'", lintrc)
    review_config = build_review_config(lintrc, deepcopy(config))

    if len(review_config.linters()) == 0:
        log.info('No configured linters, skipping processing.')
        return

    try:
        log.info('Loading pull request data from github. user=%s '
                 'repo=%s number=%s', user, repo_name, number)
        repo = GithubRepository(config, user, repo_name)
        pull_request = repo.pull_request(number)

        clone_url = pull_request.clone_url

        pr_head = pull_request.head
        target_branch = pull_request.target_branch

        if target_branch in review_config.ignore_branches():
            log.info('Pull request into ignored branch %s, skipping review.',
                     target_branch)
            return

        repo.create_status(pr_head, 'pending', 'Lintreview processing')

        # Clone/Update repository
        target_path = git.get_repo_path(user, repo_name, number, config)
        git.clone_or_update(config, clone_url, target_path, pr_head)

        processor = Processor(repo, pull_request, target_path, review_config)
        processor.load_changes()
        processor.run_tools()
        processor.publish()

        log.info('Completed lint processing for %s/%s/%s' % (
            user, repo_name, number))

    except Exception as e:
        log.exception(e)
    except TimeoutError as e:
        log.exception(e)
        raise self.retry(
            countdown=5,  # Pause for 5 seconds to clear things out
            max_retries=2,  # only give it one more shot
        )
    finally:
        try:
            git.destroy(target_path)
            log.info('Cleaned up pull request %s/%s/%s',
                     user, repo_name, number)
        except Exception as e:
            log.exception(e)
示例#28
0
def process_pull_request(user, repo_name, number, lintrc):
    """
    Starts processing a pull request and running the various
    lint tools against it.
    """
    log.info('Starting to process lint for %s/%s/%s', user, repo_name, number)
    log.debug("lintrc contents '%s'", lintrc)
    review_config = build_review_config(lintrc, config)

    if len(review_config.linters()) == 0:
        log.info('No configured linters, skipping processing.')
        return

    try:
        log.info('Loading pull request data from github. user=%s '
                 'repo=%s number=%s', user, repo_name, number)
        repo = GithubRepository(config, user, repo_name)
        pull_request = repo.pull_request(number)

        clone_url = pull_request.clone_url

        pr_head = pull_request.head
        target_branch = pull_request.target_branch

        if target_branch in review_config.ignore_branches():
            log.info('Pull request into ignored branch %s, skipping review.',
                     target_branch)
            return

        status = config.get('PULLREQUEST_STATUS', True)
        if status:
            repo.create_status(pr_head, 'pending', 'Lintreview processing...')

        # Clone/Update repository
        target_path = git.get_repo_path(user, repo_name, number, config)
        git.clone_or_update(config, clone_url, target_path, pr_head)

        processor = Processor(repo, pull_request,
                              target_path, config)
        processor.load_changes()
        processor.run_tools(review_config)
        processor.publish()

        log.info('Completed lint processing for %s/%s/%s' % (
            user, repo, number))

        git.destroy(target_path)
        log.info('Cleaned up pull request %s/%s/%s', user, repo, number)
    except BaseException as e:
        log.exception(e)
示例#29
0
    def test_run_tools__execute_fixers(self, fixer_stub, tool_stub):
        pull = self.get_pull_request()
        repo = Mock()

        tool_stub.factory.return_value = sentinel.tools

        fixer_stub.create_context.return_value = sentinel.context
        fixer_stub.run_fixers.return_value = sentinel.diff

        config = build_review_config(fixer_ini, app_config)
        subject = Processor(repo, pull, './tests', config)
        subject.load_changes()
        subject.run_tools()

        file_path = 'View/Helper/AssetCompressHelper.php'
        fixer_stub.create_context.assert_called_with(
            config,
            './tests',
            repo,
            pull)
        fixer_stub.run_fixers.assert_called_with(
            sentinel.tools,
            './tests',
            [file_path])
        fixer_stub.apply_fixer_diff.assert_called_with(
            subject._changes,
            sentinel.diff,
            sentinel.context)
        assert tool_stub.run.called, 'Should have ran'
示例#30
0
    def _test_run_tools_fixer_error_scenario(self, error):
        pull = self.get_pull_request()
        repo = Mock()

        self.tool_stub.factory.return_value = sentinel.tools

        self.fixer_stub.create_context.return_value = sentinel.context
        self.fixer_stub.apply_fixer_diff.side_effect = error

        config = build_review_config(fixer_ini, app_config)
        subject = Processor(repo, pull, './tests', config)
        subject.load_changes()
        subject.run_tools()

        self.fixer_stub.create_context.assert_called()
        self.fixer_stub.run_fixers.assert_called()
        self.tool_stub.run.assert_called()
        self.fixer_stub.rollback_changes.assert_called_with(
            './tests', pull.head)
        assert 1 == len(subject.problems), 'strategy error adds pull comment'
        assert 0 == subject.problems.error_count(
        ), 'fixer failure should be info level'
        assert 'Unable to apply fixers. ' + str(error) == subject.problems.all(
        )[0].body
        assert 1 == len(subject.problems), 'strategy error adds pull comment'
示例#31
0
    def _test_run_tools_fixer_error_scenario(self, error):
        pull = self.get_pull_request()
        repo = Mock()

        self.tool_stub.factory.return_value = sentinel.tools

        self.fixer_stub.create_context.return_value = sentinel.context
        self.fixer_stub.apply_fixer_diff.side_effect = error

        config = build_review_config(fixer_ini, app_config)
        subject = Processor(repo, pull, './tests', config)
        subject.load_changes()
        subject.run_tools()

        self.fixer_stub.create_context.assert_called()
        self.fixer_stub.run_fixers.assert_called()
        self.tool_stub.run.assert_called()
        self.fixer_stub.rollback_changes.assert_not_called()
        assert 1 == len(subject.problems), 'strategy error adds pull comment'
        assert 0 == subject.problems.error_count(), 'fixer failure should be info level'
        assert 'Unable to apply fixers. ' + str(error) == subject.problems.all()[0].body
        assert 1 == len(subject.problems), 'strategy error adds pull comment'
示例#32
0
def process_pull_request(user, repo, number, lintrc):
    """
    Starts processing a pull request and running the various
    lint tools against it.
    """
    log.info('Starting to process lint for %s/%s/%s', user, repo, number)
    log.debug("lintrc contents '%s'", lintrc)
    review_config = build_review_config(lintrc, config)

    if len(review_config.linters()) == 0:
        log.info('No configured linters, skipping processing.')
        return

    try:
        log.info(
            'Loading pull request data from github. user=%s '
            'repo=%s number=%s', user, repo, number)
        gh = github.get_repository(config, user, repo)
        pull_request = gh.pull_request(number)

        pr_dict = pull_request.as_dict()
        head_repo = pr_dict['head']['repo']['clone_url']
        private_repo = pr_dict['head']['repo']['private']
        pr_head = pr_dict['head']['sha']

        target_branch = pr_dict['base']['ref']
        if target_branch in review_config.ignore_branches():
            log.info(
                'Pull request into ignored branch %s, skipping processing.' %
                target_branch)
            return

        # Clone/Update repository
        target_path = git.get_repo_path(user, repo, number, config)
        git.clone_or_update(config, head_repo, target_path, pr_head,
                            private_repo)

        processor = Processor(gh, number, pr_head, target_path, config)
        processor.load_changes()
        processor.run_tools(review_config)
        processor.publish()

        log.info('Completed lint processing for %s/%s/%s' %
                 (user, repo, number))
    except BaseException as e:
        log.exception(e)
示例#33
0
    def test_publish(self):
        subject = Processor(None, 1, '123abc', './tests')
        subject._problems = Mock()
        subject._review = Mock()

        subject.publish()
        self.assertTrue(subject._problems.limit_to_changes.called,
                        'Problems should be filtered.')
        self.assertTrue(subject._review.publish.called,
                        'Review should be published.')
示例#34
0
    def test_run_tools__ignore_patterns(self, fixer_stub, tool_stub):
        pull = self.get_pull_request()
        repo = Mock()

        config = build_review_config(fixer_ini, app_config)
        config.ignore_patterns = lambda: ['View/Helper/*']

        subject = Processor(repo, pull, './tests', config)
        subject.load_changes()
        subject.run_tools()
        tool_stub.run.assert_called_with(ANY, [], ANY)
示例#35
0
def process_pull_request(user, repo_name, number, lintrc):
    """
    Starts processing a pull request and running the various
    lint tools against it.
    """
    log.info('Starting to process lint for %s/%s/%s', user, repo_name, number)
    log.debug("lintrc contents '%s'", lintrc)
    review_config = build_review_config(lintrc, config)

    if len(review_config.linters()) == 0:
        log.info('No configured linters, skipping processing.')
        return

    try:
        log.info('Loading pull request data from github. user=%s '
                 'repo=%s number=%s', user, repo_name, number)
        repo = GithubRepository(config, user, repo_name)
        pull_request = repo.pull_request(number)

        head_repo = pull_request.clone_url

        private_repo = pull_request.is_private
        pr_head = pull_request.head
        target_branch = pull_request.target_branch

        if target_branch in review_config.ignore_branches():
            log.info('Pull request into ignored branch %s, skipping processing.' %
                     target_branch)
            return

        status = config.get('PULLREQUEST_STATUS', True)
        if status:
            repo.create_status(pr_head, 'pending', 'Lintreview processing...')

        # Clone/Update repository
        target_path = git.get_repo_path(user, repo_name, number, config)
        git.clone_or_update(config, head_repo, target_path, pr_head,
                            private_repo)

        processor = Processor(repo, pull_request,
                              target_path, config)
        processor.load_changes()
        processor.run_tools(review_config)
        processor.publish()

        log.info('Completed lint processing for %s/%s/%s' % (
            user, repo, number))
    except BaseException, e:
        log.exception(e)
示例#36
0
    def test_publish(self):
        subject = Processor(None, 1, '123abc', './tests',
                            {'SUMMARY_THRESHOLD': 50})
        subject._problems = Mock()
        subject._review = Mock()

        subject.publish()
        self.assertTrue(subject._problems.limit_to_changes.called,
                        'Problems should be filtered.')
        self.assertTrue(subject._review.publish.called,
                        'Review should be published.')
        subject._review.publish.assert_called_with(subject._problems, '123abc',
                                                   50)
示例#37
0
文件: tasks.py 项目: pSub/lint-review
def process_pull_request(user, repo, number, lintrc):
    """
    Starts processing a pull request and running the various
    lint tools against it.
    """
    log.info('Starting to process lint for %s/%s/%s', user, repo, number)
    log.debug("lintrc contents '%s'", lintrc)
    lintrc_defaults = get_lintrc_defaults(config)
    review_config = ReviewConfig(lintrc, lintrc_defaults)

    if len(review_config.linters()) == 0:
        log.info('No configured linters, skipping processing.')
        return

    try:
        log.info('Loading pull request data from github. user=%s '
                 'repo=%s number=%s', user, repo, number)
        gh = github.get_repository(config, user, repo)
        pull_request = gh.pull_request(number)

        pr_dict = pull_request.as_dict()
        head_repo = pr_dict['head']['repo']['clone_url']
        private_repo = pr_dict['head']['repo']['private']
        pr_head = pr_dict['head']['sha']

        target_branch = pr_dict['base']['ref']
        if target_branch in review_config.ignore_branches():
            log.info('Pull request into ignored branch %s, skipping processing.' %
                     target_branch)
            return

        # Clone/Update repository
        target_path = git.get_repo_path(user, repo, number, config)
        git.clone_or_update(config, head_repo, target_path, pr_head,
                            private_repo)

        processor = Processor(gh, number, pr_head,
                              target_path, config)
        processor.load_changes()
        processor.run_tools(review_config)
        processor.publish()

        log.info('Completed lint processing for %s/%s/%s' % (
            user, repo, number))
    except BaseException, e:
        log.exception(e)
示例#38
0
    def test_publish(self):
        gh = self.get_mock_client(load_fixture('commits.json'))

        subject = Processor(gh, 1, '123abc', './tests',
                            {'SUMMARY_THRESHOLD': 50})
        subject._problems = Mock()
        subject._review = Mock()

        subject.publish()
        self.assertTrue(subject._problems.limit_to_changes.called,
                        'Problems should be filtered.')
        self.assertTrue(subject._review.publish.called,
                        'Review should be published.')
        subject._review.publish.assert_called_with(subject._problems, '123abc',
                                                   50)
示例#39
0
    def test_publish(self):
        pull = self.get_pull_request()
        repo = Mock()

        subject = Processor(repo, pull, './tests', app_config)
        subject.problems = Mock()
        subject._review = Mock()

        subject.publish()
        eq_(True, subject.problems.limit_to_changes.called,
            'Problems should be filtered.')
        eq_(True, subject._review.publish.called,
            'Review should be published.')
        subject._review.publish.assert_called_with(subject.problems, pull.head,
                                                   50)
示例#40
0
    def test_publish_checkrun(self):
        pull = self.get_pull_request()
        repo = Mock()

        config = build_review_config(fixer_ini, app_config)
        subject = Processor(repo, pull, './tests', config)
        subject.problems = Mock()
        subject._review = Mock()

        subject.publish(check_run_id=9)
        eq_(True, subject.problems.limit_to_changes.called,
            'Problems should be filtered.')
        eq_(True, subject._review.publish_checkrun.called,
            'Review should be published.')
        subject._review.publish_checkrun.assert_called_with(
            subject.problems, 9)
示例#41
0
    def test_run_tools__import_error(self):
        self.tool_patcher.stop()
        pull = self.get_pull_request()
        repo = Mock()

        ini = """
[tools]
linters = nope
"""
        config = build_review_config(ini, app_config)
        subject = Processor(repo, pull, './tests', config)
        subject.load_changes()
        subject.run_tools()
        self.tool_patcher.start()

        problems = subject.problems.all()

        assert len(problems) == 1
        assert 'could not load linters' in problems[0].body
示例#42
0
    def test_run_tools__execute_fixers_fail(self):
        pull = self.get_pull_request()
        repo = Mock()

        self.tool_stub.factory.return_value = sentinel.tools

        self.fixer_stub.create_context.return_value = sentinel.context
        self.fixer_stub.run_fixers.side_effect = RuntimeError

        config = build_review_config(fixer_ini, app_config)
        subject = Processor(repo, pull, './tests', config)
        subject.load_changes()
        subject.run_tools()

        self.fixer_stub.create_context.assert_called()
        self.fixer_stub.run_fixers.assert_called()
        self.fixer_stub.apply_fixer_diff.assert_not_called()
        self.fixer_stub.rollback_changes.assert_called()
        self.tool_stub.run_assert_called()
示例#43
0
    def test_run_tools__execute_fixers_fail(self, fixer_stub, tool_stub):
        pull = self.get_pull_request()
        repo = Mock()

        tool_stub.factory.return_value = sentinel.tools

        fixer_stub.create_context.return_value = sentinel.context
        fixer_stub.run_fixers.side_effect = RuntimeError

        config = build_review_config(fixer_ini, app_config)
        subject = Processor(repo, pull, './tests', config)
        subject.load_changes()
        subject.run_tools()

        assert fixer_stub.create_context.called
        assert fixer_stub.run_fixers.called
        eq_(False, fixer_stub.apply_fixer_diff.called)
        eq_(True, fixer_stub.rollback_changes.called,
            'Runtime error should trigger git reset.')
        assert tool_stub.run.called, 'Should have ran'
示例#44
0
    def _test_run_tools_fixer_error_scenario(self, error):
        pull = self.get_pull_request()
        repo = Mock()

        self.tool_stub.factory.return_value = sentinel.tools

        self.fixer_stub.create_context.return_value = sentinel.context
        self.fixer_stub.apply_fixer_diff.side_effect = error

        config = build_review_config(fixer_ini, app_config)
        subject = Processor(repo, pull, './tests', config)
        subject.load_changes()
        subject.run_tools()

        self.fixer_stub.create_context.assert_called()
        self.fixer_stub.run_fixers.assert_called()
        self.tool_stub.run.assert_called()
        self.fixer_stub.rollback_changes.assert_not_called()
        self.assertEqual(1, len(subject.problems),
                         'strategy error adds pull comment')
        self.assertEqual('Unable to apply fixers. ' + str(error),
                         subject.problems.all()[0].body)
示例#45
0
    def _test_run_tools_fixer_error_scenario(self, error, fixer_stub,
                                             tool_stub):
        pull = self.get_pull_request()
        repo = Mock()

        tool_stub.factory.return_value = sentinel.tools

        fixer_stub.create_context.return_value = sentinel.context
        fixer_stub.apply_fixer_diff.side_effect = error

        config = build_review_config(fixer_ini, app_config)
        subject = Processor(repo, pull, './tests', config)
        subject.load_changes()
        subject.run_tools()

        assert fixer_stub.create_context.called
        assert fixer_stub.run_fixers.called
        assert tool_stub.run.called, 'Should have ran'
        eq_(False, fixer_stub.rollback_changes.called,
            'No rollback on strategy failure')
        eq_(1, len(subject.problems), 'strategy error adds pull comment')
        eq_('Unable to apply fixers. ' + str(error),
            subject.problems.all()[0].body)
示例#46
0
    def test_run_tools__no_changes(self):
        pull = self.get_pull_request()
        repo = Mock()

        subject = Processor(repo, pull, './tests', app_config)
        subject.run_tools(None)
示例#47
0
 def test_run_tools__no_changes(self):
     subject = Processor(None, 1, '123abc', './tests')
     subject.run_tools(None)
示例#48
0
    def test_run_tools__no_changes(self):
        gh = self.get_mock_client(fixture_data)

        subject = Processor(gh, 1, '123abc', './tests')
        subject.run_tools(None)
示例#49
0
 def test_run_tools__no_changes(self):
     subject = Processor(None, 1, '123abc', './tests')
     subject.run_tools(None)
示例#50
0
    def test_run_tools__no_changes(self):
        gh = self.get_mock_client(fixture_data)

        subject = Processor(gh, 1, '123abc', './tests')
        subject.run_tools(None)
示例#51
0
    def test_run_tools__no_changes(self):
        pull = self.get_pull_request(fixture_data)
        repo = Mock()

        subject = Processor(repo, pull, './tests')
        subject.run_tools(None)
示例#52
0
    def test_run_tools__no_changes(self):
        pull = self.get_pull_request(fixture_data)
        repo = Mock()

        subject = Processor(repo, pull, './tests')
        subject.run_tools(None)