Skip to content
This repository has been archived by the owner on Apr 18, 2018. It is now read-only.

Commit

Permalink
Merge pull request #92 from rschlaikjer/add-rerun-detection-button
Browse files Browse the repository at this point in the history
Add rerun detection button

Allow pushmasters to manually trigger merge-detection. Useful when a previous push has certed.
  • Loading branch information
ymilki committed Aug 18, 2014
2 parents afc70b2 + 890b4ab commit 645dd1b
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 13 deletions.
30 changes: 21 additions & 9 deletions pushmanager/core/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ class GitTaskAction(object):
VERIFY_BRANCH = 1
TEST_PICKME_CONFLICT = 2
TEST_ALL_PICKMES = 3
TEST_CONFLICTING_PICKMES = 4


class GitQueueTask(object):
Expand Down Expand Up @@ -1239,15 +1240,24 @@ def verify_branch_failure(cls, request, failure_msg):
MailQueue.enqueue_user_email([user_to_notify], msg, subject)

@classmethod
def requeue_pickmes_with_conflicts(cls, push_id):
def requeue_pickmes_for_push(cls, push_id, conflicting_only=False):
request_details = []
for pickme_id in cls._get_request_ids_in_push(push_id):
req = cls._get_request(pickme_id)
if req and req['tags'] and 'conflict-pickme' in req['tags']:
GitQueue.enqueue_request(
GitTaskAction.TEST_PICKME_CONFLICT,
pickme_id,
requeue=False
)
request_details.append(cls._get_request(pickme_id))

if conflicting_only:
request_details = [
req for req in request_details
if req and req['tags']
and 'conflict-pickme' in req['tags']
]

for req in request_details:
GitQueue.enqueue_request(
GitTaskAction.TEST_PICKME_CONFLICT,
req['id'],
requeue=False
)

@classmethod
def process_sha_queue(cls):
Expand Down Expand Up @@ -1291,8 +1301,10 @@ def process_conflict_queue(cls):
try:
if task.task_type is GitTaskAction.TEST_PICKME_CONFLICT:
cls.test_pickme_conflicts(task.request_id, **task.kwargs)
elif task.task_type is GitTaskAction.TEST_CONFLICTING_PICKMES:
cls.requeue_pickmes_for_push(task.request_id, conflicting_only=True)
elif task.task_type is GitTaskAction.TEST_ALL_PICKMES:
cls.requeue_pickmes_with_conflicts(task.request_id)
cls.requeue_pickmes_for_push(task.request_id)
else:
logging.error(
"GitConflictQueue encountered unknown task type %d",
Expand Down
2 changes: 2 additions & 0 deletions pushmanager/pushmanager_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from pushmanager.servlets.checklist import ChecklistServlet
from pushmanager.servlets.checklist import ChecklistToggleServlet
from pushmanager.servlets.commentrequest import CommentRequestServlet
from pushmanager.servlets.conflictcheck import ConflictCheckServlet
from pushmanager.servlets.delayrequest import DelayRequestServlet
from pushmanager.servlets.deploypush import DeployPushServlet
from pushmanager.servlets.discardpush import DiscardPushServlet
Expand Down Expand Up @@ -64,6 +65,7 @@ def get_url_specs():
for servlet in (APIServlet,
ChecklistServlet,
ChecklistToggleServlet,
ConflictCheckServlet,
RequestServlet,
RequestsServlet,
NewRequestServlet,
Expand Down
17 changes: 17 additions & 0 deletions pushmanager/servlets/conflictcheck.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pushmanager.core.util
from pushmanager.core.git import GitQueue
from pushmanager.core.git import GitTaskAction
from pushmanager.core.requesthandler import RequestHandler


class ConflictCheckServlet(RequestHandler):

def _arg(self, key):
return pushmanager.core.util.get_str_arg(self.request, key, '')

def post(self):
if not self.current_user:
return self.send_error(403)
self.pushid = pushmanager.core.util.get_int_arg(self.request, 'id')
GitQueue.enqueue_request(GitTaskAction.TEST_ALL_PICKMES, self.pushid)
self.redirect("/push?id=%d" % self.pushid)
4 changes: 3 additions & 1 deletion pushmanager/servlets/pickmerequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,6 @@ def post(self):

def on_db_complete(self, success, db_results):
self.check_db_results(success, db_results)
GitQueue.enqueue_request(GitTaskAction.TEST_ALL_PICKMES, self.pushid)
# Re-check pickmes that are marked as conflicting, in case this was the pickme
# that they conflicted against.
GitQueue.enqueue_request(GitTaskAction.TEST_CONFLICTING_PICKMES, self.pushid)
8 changes: 8 additions & 0 deletions pushmanager/static/js/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,14 @@ $(function() {
$('#push-info-form').hide();
});

$('#rerun-conflict-check').click(function() {
$('#confirm-conflict-check').show();
});

$('#cancel-conflict-check').click(function() {
$('#confirm-conflict-check').hide();
});

$('#discard-push').click(function() {
PushManager.run_command_dialog("git push --delete canon " + $('#push-info').attr('branch'), function() {
// Go ahead and discard it.
Expand Down
15 changes: 15 additions & 0 deletions pushmanager/templates/confirm-conflict-check.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<form id="confirm-conflict-check" class="popup-form" action="/conflictcheck" method="POST">
<div class="form-wrapper">

<h2>Check Push for Conflicts</h2>

<input type="hidden" name="id" value="{{ int(push_info['id']) }}" />

Re-run conflict detection on all requests pickme'd for this push?

<div class="buttons">
<input type="submit" id="check-conflicts" name="check-conflicts" value="Run" />
<input type="reset" id="cancel-conflict-check" name="cancel-conflict-check" value="Don't Run" />
</div>
</div>
</form>
1 change: 1 addition & 0 deletions pushmanager/templates/push-button-bar.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
&mdash;
<li><button id="message-all">Message All</button></li>
<li><button id="show-checklist">Push Checklist</button></li>
<li><button id="rerun-conflict-check">Rerun Conflict Detection</button></li>
{% end %}
{% else %}
{% if push_info['state'] == 'accepting' %}
Expand Down
3 changes: 3 additions & 0 deletions pushmanager/templates/push.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<div id="form-anchor">&nbsp;
{% include 'edit-push.html' %}
</div>
<div id="form-anchor">&nbsp;
{% include 'confirm-conflict-check.html' %}
</div>
<!-- ========= PUSH INFO ========== -->
{% include 'push-info.html' %}
<!-- ========= BUTTON BAR ========== -->
Expand Down
35 changes: 33 additions & 2 deletions pushmanager/tests/test_core_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,40 @@ def update_get_req(i):

get_req.side_effect = update_get_req

pushmanager.core.git.GitQueue.requeue_pickmes_with_conflicts(1)
pushmanager.core.git.GitQueue.requeue_pickmes_for_push(1, conflicting_only=True)

calls = [mock.call(GitTaskAction.TEST_PICKME_CONFLICT, 0, requeue=False)]
calls = [mock.call(GitTaskAction.TEST_PICKME_CONFLICT, 1, requeue=False)]

enqueue_req.assert_has_calls(calls)

def test_requeue_all_pickmes(self):
with nested(
mock.patch.object(GitQueue, '_get_request_ids_in_push'),
mock.patch.object(GitQueue, '_get_request'),
mock.patch.object(GitQueue, 'enqueue_request')
) as (ids_in_push, get_req, enqueue_req):

reqs = [
{'id': 1, 'tags': 'git-ok,conflict-pickme'},
{'id': 2, 'tags': 'git-ok,conflict-master'},
{'id': 3, 'tags': 'git-ok,feature'}
]

ids_in_push.return_value = [0, 1, 2]
get_req.return_value = reqs[0]

def update_get_req(i):
return reqs[i]

get_req.side_effect = update_get_req

pushmanager.core.git.GitQueue.requeue_pickmes_for_push(1)

calls = [
mock.call(GitTaskAction.TEST_PICKME_CONFLICT, 1, requeue=False),
mock.call(GitTaskAction.TEST_PICKME_CONFLICT, 2, requeue=False),
mock.call(GitTaskAction.TEST_PICKME_CONFLICT, 3, requeue=False),
]

enqueue_req.assert_has_calls(calls)

Expand Down
2 changes: 1 addition & 1 deletion pushmanager/tests/test_template_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def test_push_info_list_items_stageenv(self):
'discard-push', 'add-selected-requests',
'remove-selected-requests', 'rebuild-deploy-branch',
'deploy-to-stage-step0', 'deploy-to-prod', 'merge-to-master',
'message-all', 'show-checklist']
'message-all', 'show-checklist', 'rerun-conflict-check']

def test_push_buttons_random_user(self):
with self.no_ui_modules():
Expand Down

0 comments on commit 645dd1b

Please sign in to comment.