Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjustment to catch and raise merge conflicts #68

Merged
merged 1 commit into from
Sep 20, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions conda_forge_webservices/linting.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import shutil
import tempfile
import textwrap
import time

import requests
from git import Repo
Expand All @@ -27,9 +28,13 @@ def compute_lint_message(repo_owner, repo_name, pr_id):
owner = gh.get_user(repo_owner)
remote_repo = owner.get_repo(repo_name)

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

@jakirkham jakirkham Sep 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go ahead and sleep to start with. This simplifies the logic of this loop and gives GitHub a chance to compute the mergeability of the PR before we request it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, not sure what a reasonable timeout is between checks, but figured 0.1s would be a good starting place.

Copy link
Member Author

@jakirkham jakirkham Sep 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add that mergeable appears to be undefined if the pull request is closed as well. So there is a pretty rare case that could occur where we get here and the pull request is closed. This would result in an infinite loop. We can solve that a couple of ways.

  1. Check whether the PR is still open.
  2. Retry up to some limit.

My preference is to go for 1. Though maybe there is value in doing 2 as well. We would probably want to not have a message in that case. Currently we would get the merge conflict message. Feedback appreciated.

Copy link
Member Author

@jakirkham jakirkham Sep 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now handle 1. This functionality is also broken out in PR ( #70 ), but had to be merged back into this PR to handle merge conflicts.

pull_request = remote_repo.get_pull(pr_id)
if pull_request.state != "open":
return {}
Copy link
Member Author

@jakirkham jakirkham Sep 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skip linting if the PR turns out to be closed at any point.

mergeable = pull_request.mergeable

with tmp_directory() as tmp_dir:
repo = Repo.clone_from(remote_repo.clone_url, tmp_dir)
Expand All @@ -40,7 +45,7 @@ def compute_lint_message(repo_owner, repo_name, pr_id):
sha = str(repo.head.object.hexsha)

# Raise an error if the PR is not mergeable.
if not pull_request.mergeable:
if not mergeable:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to using the stored result from our checks for mergeability above.

message = textwrap.dedent("""
Hi! This is the friendly automated conda-forge-linting service.

Expand Down