Example #1
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)
Example #2
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)
Example #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)
Example #4
0
def setup_repo(mock_fetch, mock_checkout):
    """Set up a repo, avoiding fetch and checkout."""
    git_dir = os.path.join(temp_repo_dir, 'test_clone')
    if not os.path.exists(git_dir):
        git.clone_or_update({}, 'git://github.com/markstory/lint-review.git',
                            git_dir, 'master')

    git.clone_or_update({}, git_dir, clone_path, 'master')
Example #5
0
 def test_clone_or_update(self, mock_fetch, mock_checkout):
     teardown_repo()
     git.clone_or_update(
         config,
         'git://github.com/markstory/lint-review.git',
         clone_path,
         'e4f880c77e6b2c81c81cad5d45dd4e1c39b919a0')
     assert git.exists(clone_path)
Example #6
0
def test_clone_or_update():
    path = settings['WORKSPACE'] + '/test_clone'

    assert not (git.exists(path)), 'Directory should not exist.'
    git.clone_or_update(config, 'git://github.com/markstory/lint-review.git',
                        path, 'e4f880c77e6b2c81c81cad5d45dd4e1c39b919a0')
    assert git.exists(path)
    git.destroy(path)
Example #7
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)
Example #8
0
def test_clone_or_update():
    path = settings["WORKSPACE"] + "/test_clone"

    assert not (git.exists(path)), "Directory should not exist."
    git.clone_or_update(
        config, "git://github.com/markstory/lint-review.git", path, "e4f880c77e6b2c81c81cad5d45dd4e1c39b919a0"
    )
    assert git.exists(path)
    git.destroy(path)
Example #9
0
def test_clone_or_update():
    path = settings['WORKSPACE'] + '/test_clone'

    assert not(git.exists(path)), 'Directory should not exist.'
    git.clone_or_update(
        'git://github.com/markstory/lint-review.git',
        path,
        'e4f880c77e6b2c81c81cad5d45dd4e1c39b919a0')
    assert git.exists(path)
    git.destroy(path)
Example #10
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)
Example #11
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)
Example #12
0
def setup_repo(mock_fetch, mock_checkout):
    """Set up a repo, avoiding fetch and checkout."""
    git_dir = os.path.join(temp_repo_dir, 'test_clone')
    if not os.path.exists(git_dir):
        git.clone_or_update(
            {},
            'git://github.com/markstory/lint-review.git',
            git_dir,
            'master')

    git.clone_or_update(
        {},
        git_dir,
        clone_path,
        'master')
Example #13
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)
Example #14
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)
    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)
Example #15
0
def setup_repo():
    git.clone_or_update(
        {},
        'git://github.com/markstory/lint-review.git',
        clone_path,
        'master')
Example #16
0
def test_clone_or_update():
    git.clone_or_update(config, 'git://github.com/markstory/lint-review.git',
                        clone_path, 'e4f880c77e6b2c81c81cad5d45dd4e1c39b919a0')
    assert git.exists(clone_path)