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)
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)
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)
def test_repo_operations(self): teardown_repo() res = git.clone( 'git://github.com/markstory/lint-review.git', clone_path) assert res, 'Cloned successfully.' assert git.exists(clone_path), 'Cloned dir should be there.' git.destroy(clone_path) assert not(git.exists(clone_path)), 'Cloned dir should be gone.'
def test_repo_operations(): path = settings['WORKSPACE'] + '/test_clone' assert not (git.exists(path)), 'Directory should not exist.' res = git.clone('git://github.com/markstory/lint-review.git', path) assert res, 'Cloned successfully.' assert git.exists(path), 'Cloned dir should be there.' git.destroy(path) assert not (git.exists(path)), 'Cloned dir should be gone.'
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)
def test_repo_operations(): path = settings["WORKSPACE"] + "/test_clone" assert not (git.exists(path)), "Directory should not exist." res = git.clone("git://github.com/markstory/lint-review.git", path) assert res, "Cloned successfully." assert git.exists(path), "Cloned dir should be there." git.destroy(path) assert not (git.exists(path)), "Cloned dir should be gone."
def cleanup_pull_request(user, repo, number): """ Cleans up a pull request once its been closed. """ log.info("Cleaning up pull request %s/%s/%s", user, repo, number) path = git.get_repo_path(user, repo, number, config) try: git.destroy(path) except: log.warning("Cannot cleanup '%s' path does not exist.", path)
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)
def test_repo_operations(): path = settings['WORKSPACE'] + '/test_clone' assert not(git.exists(path)), 'Directory should not exist.' res = git.clone( 'git://github.com/markstory/lint-review.git', path) assert res, 'Cloned successfully.' assert git.exists(path), 'Cloned dir should be there.' git.destroy(path) assert not(git.exists(path)), 'Cloned dir should be gone.'
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)
def teardown_repo(): if git.exists(clone_path): git.destroy(clone_path)
def test_destroy_unicode_paths(self): full_clone_path = os.path.join(clone_path, "\u2620.txt") with open(full_clone_path, 'w') as f: f.write('skull and crossbones') git.destroy(clone_path)
def test_destory_unicode_paths(): with open(clone_path + u"/\u2620.txt", 'w') as f: f.write('skull and crossbones') git.destroy(clone_path)