def start_review(): event = request.headers.get('X-Github-Event') if event == 'ping': return Response(status=200) try: action = request.json["action"] pull_request = request.json["pull_request"] number = pull_request["number"] base_repo_url = pull_request["base"]["repo"]["git_url"] head_repo_url = pull_request["head"]["repo"]["git_url"] head_repo_ref = pull_request["head"]["ref"] user = pull_request["base"]["repo"]["owner"]["login"] head_user = pull_request["head"]["repo"]["owner"]["login"] repo = pull_request["base"]["repo"]["name"] head_repo = pull_request["head"]["repo"]["name"] except Exception as e: log.error("Got an invalid JSON body. '%s'", e) return Response(status=403, response="You must provide a valid JSON body\n") log.info( "Received GitHub pull request notification for " "%s %s, (%s) from: %s", base_repo_url, number, action, head_repo_url) if action not in ("opened", "synchronize", "reopened", "closed"): log.info("Ignored '%s' action." % action) return Response(status=204) if action == "closed": return close_review(user, repo, pull_request) gh = get_repository(app.config, head_user, head_repo) try: lintrc = get_lintrc(gh, head_repo_ref) log.debug("lintrc file contents '%s'", lintrc) except Exception as e: log.warn( "Cannot download .lintrc file for '%s', " "skipping lint checks.", base_repo_url) log.warn(e) return Response(status=204) try: log.info("Scheduling pull request for %s/%s %s", user, repo, number) process_pull_request.delay(user, repo, number, lintrc) except: log.error('Could not publish job to celery. Make sure its running.') return Response(status=500) return Response(status=204)
def start_review(): event = request.headers.get('X-Github-Event') if event == 'ping': return Response(status=200) try: action = request.json["action"] pull_request = request.json["pull_request"] number = pull_request["number"] base_repo_url = pull_request["base"]["repo"]["git_url"] head_repo_url = pull_request["head"]["repo"]["git_url"] head_repo_ref = pull_request["head"]["ref"] user = pull_request["base"]["repo"]["owner"]["login"] head_user = pull_request["head"]["repo"]["owner"]["login"] repo = pull_request["base"]["repo"]["name"] head_repo = pull_request["head"]["repo"]["name"] except Exception as e: log.error("Got an invalid JSON body. '%s'", e) return Response(status=403, response="You must provide a valid JSON body\n") log.info("Received GitHub pull request notification for " "%s %s, (%s) from: %s", base_repo_url, number, action, head_repo_url) if action not in ("opened", "synchronize", "reopened", "closed"): log.info("Ignored '%s' action." % action) return Response(status=204) if action == "closed": return close_review(user, repo, pull_request) gh = get_repository(app.config, head_user, head_repo) try: lintrc = get_lintrc(gh, head_repo_ref) log.debug("lintrc file contents '%s'", lintrc) except Exception as e: log.warn("Cannot download .lintrc file for '%s', " "skipping lint checks.", base_repo_url) log.warn(e) return Response(status=204) try: log.info("Scheduling pull request for %s/%s %s", user, repo, number) process_pull_request.delay(user, repo, number, lintrc) except: log.error('Could not publish job to celery. Make sure its running.') return Response(status=500) return Response(status=204)
def main(): parser = argparse.ArgumentParser(description='Scan the code for issues and report as comments in GitHub') parser.add_argument('--pull-request', dest="pull_request", help="The PR to scan", type=int) ## Disabled for now # parser.add_argument('--commit', help="The commit to scan", type=str) parser.add_argument('--user', help="The GitHub User who owns the repo", type=str, default=app.config['GITHUB_USER']) parser.add_argument('--repo', help="The GitHub Repo name", type=str) runtime_config = parser.parse_args() gh = get_repository(app.config, runtime_config.user, runtime_config.repo) try: lintrc = get_lintrc(gh) log.debug("lintrc file contents '%s'", lintrc) except Exception as e: log.warn("Cannot download .lintrc file for '%s', " "skipping lint checks.", base_repo_url) log.warn(e) return 2 if (runtime_config.pull_request > 0): tasks.process_pull_request(runtime_config.user, runtime_config.repo, runtime_config.pull_request, lintrc)
def test_get_lintrc(self): repo = Mock(spec=Repository) github.get_lintrc(repo, 'HEAD') repo.file_contents.assert_called_with('.lintrc', 'HEAD')
def test_get_lintrc(): gh = github.get_client(config, 'markstory', 'lint-review') lintrc = github.get_lintrc(gh) assert lintrc is not None, 'Should get something' assert isinstance(lintrc, str)
def test_get_lintrc(): repo = Mock(spec=github3.repos.repo.Repository) github.get_lintrc(repo) repo.file_contents.assert_called_with('.lintrc')