Esempio n. 1
0
    def test_repository(self, github_mock):
        github_mock.get_repository.return_value = self.repo_model
        repo = GithubRepository(config, 'markstory', 'lint-test')

        eq_(self.repo_model, repo.repository())
        github_mock.get_repository.assert_called_with(config, 'markstory',
                                                      'lint-test')
Esempio n. 2
0
 def test_pull_request(self):
     model = self.repo_model
     model.pull_request = Mock(return_value=sentinel.pull_request)
     repo = GithubRepository(config, 'markstory', 'lint-test')
     repo.repository = lambda: self.repo_model
     pull = repo.pull_request(1)
     ok_(isinstance(pull, GithubPullRequest), 'Should be wrapped object')
Esempio n. 3
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)
Esempio n. 4
0
 def test_pull_request(self):
     model = self.repo_model
     model.pull_request = Mock(return_value=sentinel.pull_request)
     repo = GithubRepository(config, 'markstory', 'lint-test')
     repo.repository = lambda: self.repo_model
     pull = repo.pull_request(1)
     ok_(isinstance(pull, GithubPullRequest),
         'Should be wrapped object')
Esempio n. 5
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)
Esempio n. 6
0
    def test_ensure_label__missing(self):
        model = self.repo_model
        model.label = Mock(return_value=None)
        model.create_label = Mock()

        repo = GithubRepository(config, 'markstory', 'lint-test')
        repo.repository = lambda: self.repo_model
        repo.ensure_label('A label')
        model.create_label.assert_called_with(name='A label', color='bfe5bf')
Esempio n. 7
0
    def test_ensure_label__exists(self):
        model = self.repo_model
        model.create_label = Mock()
        model.label = Mock(return_value=True)

        repo = GithubRepository(config, 'markstory', 'lint-test')
        repo.repository = lambda: self.repo_model
        repo.ensure_label('A label')
        eq_(False, model.create_label.called)
Esempio n. 8
0
    def test_repository(self, github_mock):
        github_mock.get_repository.return_value = self.repo_model
        repo = GithubRepository(config, 'markstory', 'lint-test')

        eq_(self.repo_model, repo.repository())
        github_mock.get_repository.assert_called_with(
            config,
            'markstory',
            'lint-test')
Esempio n. 9
0
    def test_ensure_label__exists(self):
        model = self.repo_model
        model.create_label = Mock()
        model.label = Mock(return_value=True)

        repo = GithubRepository(config, 'markstory', 'lint-test')
        repo.repository = lambda: self.repo_model
        repo.ensure_label('A label')
        eq_(False, model.create_label.called)
Esempio n. 10
0
    def test_create_status(self):
        model = self.repo_model
        model.create_status = Mock()

        repo = GithubRepository(config, 'markstory', 'lint-test')
        repo.repository = lambda: self.repo_model
        repo.create_status('abc123', 'succeeded', 'all good')
        model.create_status.assert_called_with('abc123', 'succeeded', None,
                                               'all good', 'lintreview')
Esempio n. 11
0
    def test_ensure_label__missing(self):
        model = self.repo_model
        model.label = Mock(return_value=None)
        model.create_label = Mock()

        repo = GithubRepository(config, 'markstory', 'lint-test')
        repo.repository = lambda: self.repo_model
        repo.ensure_label('A label')
        model.create_label.assert_called_with(
            name='A label',
            color='bfe5bf')
Esempio n. 12
0
    def test_create_status(self):
        model = self.repo_model
        model.create_status = Mock()

        repo = GithubRepository(config, 'markstory', 'lint-test')
        repo.repository = lambda: self.repo_model
        repo.create_status('abc123', 'succeeded', 'all good')
        model.create_status.assert_called_with(
            'abc123',
            'succeeded',
            None,
            'all good',
            'lintreview')
Esempio n. 13
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)
Esempio n. 14
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)
Esempio n. 15
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

        # 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)
Esempio n. 16
0
    def test_update_checkrun(self):
        model = self.repo_model
        model._patch = Mock()
        model._json = Mock()

        repo = GithubRepository(config, 'markstory', 'lint-test')
        repo.repository = lambda: model
        review = {
            'conclusion': 'success',
            'output': {
                'title': 'No lint errors found',
                'summary': '',
                'annotations': [],
            }
        }
        repo.update_checkrun(99, review)
        model._patch.assert_called_with(
            'https://api.github.com/repos/markstory/lint-test/check-runs/99',
            data=json.dumps(review),
            headers={'Accept': 'application/vnd.github.antiope-preview+json'})
        assert model._json.called
Esempio n. 17
0
    def test_update_checkrun(self):
        model = self.repo_model
        model._patch = Mock()
        model._json = Mock()

        repo = GithubRepository(config, 'markstory', 'lint-test')
        repo.repository = lambda: model
        review = {
            'conclusion': 'success',
            'output': {
                'title': 'No lint errors found',
                'summary': '',
                'annotations': [],
            }
        }
        repo.update_checkrun(99, review)
        model._patch.assert_called_with(
            'https://api.github.com/repos/markstory/lint-test/check-runs/99',
            data=json.dumps(review),
            headers={'Accept': 'application/vnd.github.antiope-preview+json'})
        assert model._json.called
Esempio n. 18
0
    def test_create_checkrun(self):
        model = self.repo_model
        post_mock = Mock()
        json_mock = Mock()
        model._post = post_mock
        model._json = json_mock

        repo = GithubRepository(config, 'markstory', 'lint-test')
        repo.repository = lambda: model
        review = {
            'commit_sha': 'abc123',
            'conclusion': 'success',
            'output': {
                'title': 'No lint errors',
                'summary': '',
                'annotations': [],
            }
        }
        repo.create_checkrun(review)
        post_mock.assert_called_with(
            'https://api.github.com/repos/markstory/lint-test/check-runs',
            data=review,
            headers={'Accept': 'application/vnd.github.antiope-preview+json'})
        json_mock.assert_called()
Esempio n. 19
0
    def test_create_checkrun(self):
        model = self.repo_model
        post_mock = Mock()
        json_mock = Mock()
        model._post = post_mock
        model._json = json_mock

        repo = GithubRepository(config, 'markstory', 'lint-test')
        repo.repository = lambda: model
        review = {
            'commit_sha': 'abc123',
            'conclusion': 'success',
            'output': {
                'title': 'No lint errors',
                'summary': '',
                'annotations': [],
            }
        }
        repo.create_checkrun(review)
        post_mock.assert_called_with(
            'https://api.github.com/repos/markstory/lint-test/check-runs',
            data=review,
            headers={'Accept': 'application/vnd.github.antiope-preview+json'})
        json_mock.assert_called()
Esempio n. 20
0
    def test_create_checkrun(self):
        model = self.repo_model
        model._post = Mock()
        model._json = Mock()
        import pdb
        pdb.set_trace()

        repo = GithubRepository(config, 'markstory', 'lint-test')
        repo.repository = lambda: model
        review = {
            'commit_sha': 'abc123',
            'conclusion': 'success',
            'output': {
                'title': 'Style Review',
                'summary': '',
                'annotations': [],
            }
        }
        repo.create_checkrun(review)
        model._post.assert_called_with(
            'https://api.github.com/repos/markstory/lint-test/check-runs',
            data=review,
            headers={'Accept': 'application/vnd.github.antiope-preview+json'})
        assert model._json.called