Skip to content

Commit

Permalink
Merge branch 'skip_closed_prs' into adj_catch_merge_conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
jakirkham committed Sep 20, 2016
2 parents 0a60908 + 8772076 commit 6186ca4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
36 changes: 22 additions & 14 deletions conda_forge_webservices/linting.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ def compute_lint_message(repo_owner, repo_name, pr_id):
gh = github.Github(os.environ['GH_TOKEN'])

owner = gh.get_user(repo_owner)
repo = owner.get_repo(repo_name)
remote_repo = owner.get_repo(repo_name)

mergeable = None
while mergeable is None:
time.sleep(0.1)
pull_request = repo.get_pull(pr_id)
pull_request = remote_repo.get_pull(pr_id)
if pull_request.state != "open":
return {}
mergeable = pull_request.mergeable

with tmp_directory() as tmp_dir:
repo = Repo.clone_from(repo.clone_url, tmp_dir)
repo = Repo.clone_from(remote_repo.clone_url, tmp_dir)

# Checkout the PR head.
repo.remotes.origin.fetch('pull/{pr}/head:pr/{pr}'.format(pr=pr_id))
Expand Down Expand Up @@ -121,9 +123,12 @@ def compute_lint_message(repo_owner, repo_name, pr_id):
message = bad
status = 'bad'

lint_info = {'message': message,
'status': status,
'sha': sha}
lint_info = {}
pull_request = remote_repo.get_pull(pr_id)
if pull_request.state == "open":
lint_info = {'message': message,
'status': status,
'sha': sha}

return lint_info

Expand Down Expand Up @@ -156,13 +161,14 @@ def set_pr_status(owner, repo_name, lint_info, target_url=None):

user = gh.get_user(owner)
repo = user.get_repo(repo_name)
commit = repo.get_commit(lint_info['sha'])
if lint_info['status'] == 'good':
commit.create_status("success", description="All recipes are excellent.",
context="conda-forge-linter", target_url=target_url)
else:
commit.create_status("failure", description="Some recipes need some changes.",
context="conda-forge-linter", target_url=target_url)
if lint_info:
commit = repo.get_commit(lint_info['sha'])
if lint_info['status'] == 'good':
commit.create_status("success", description="All recipes are excellent.",
context="conda-forge-linter", target_url=target_url)
else:
commit.create_status("failure", description="Some recipes need some changes.",
context="conda-forge-linter", target_url=target_url)


def main():
Expand All @@ -178,7 +184,9 @@ def main():

lint_info = compute_lint_message(owner, repo_name, args.pr)

if args.enable_commenting:
if not lint_info:
print('Linting was skipped.')
elif args.enable_commenting:
msg = comment_on_pr(owner, repo_name, args.pr, lint_info['message'])
set_pr_status(owner, repo_name, lint_info, target_url=msg.html_url)
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def test_good_recipe(self):
""")

lint = compute_lint_message('conda-forge', 'conda-forge-webservices', 16)
self.assert_(lint)
self.assertMultiLineEqual(expected_message, lint['message'])

def test_conflict_ok_recipe(self):
Expand All @@ -41,6 +42,7 @@ def test_conflict_ok_recipe(self):
""")

lint = compute_lint_message('conda-forge', 'conda-forge-webservices', 56)
self.assert_(lint)
self.assertMultiLineEqual(expected_message, lint['message'])

def test_conflict_2_ok_recipe(self):
Expand All @@ -54,6 +56,7 @@ def test_conflict_2_ok_recipe(self):
""")

lint = compute_lint_message('conda-forge', 'conda-forge-webservices', 57)
self.assert_(lint)
self.assertMultiLineEqual(expected_message, lint['message'])

def test_bad_recipe(self):
Expand All @@ -76,6 +79,7 @@ def test_bad_recipe(self):
""")

lint = compute_lint_message('conda-forge', 'conda-forge-webservices', 17)
self.assert_(lint)
self.assertMultiLineEqual(expected_message, lint['message'])

def test_no_recipe(self):
Expand All @@ -87,6 +91,7 @@ def test_no_recipe(self):
""")

lint = compute_lint_message('conda-forge', 'conda-forge-webservices', 18)
self.assert_(lint)
self.assertMultiLineEqual(expected_message, lint['message'])


Expand Down
5 changes: 3 additions & 2 deletions conda_forge_webservices/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ def post(self):
# Only do anything if we are working with conda-forge, and an open PR.
if is_open and owner == 'conda-forge':
lint_info = linting.compute_lint_message(owner, repo_name, pr_id)
msg = linting.comment_on_pr(owner, repo_name, pr_id, lint_info['message'])
linting.set_pr_status(owner, repo_name, lint_info, target_url=msg.html_url)
if lint_info:
msg = linting.comment_on_pr(owner, repo_name, pr_id, lint_info['message'])
linting.set_pr_status(owner, repo_name, lint_info, target_url=msg.html_url)
else:
print('Unhandled event "{}".'.format(event))
self.set_status(404)
Expand Down

0 comments on commit 6186ca4

Please sign in to comment.