Bug 1228311 - Remember last try syntax used for a review; r?smacleod draft
authorManish Goregaokar <manishearth@gmail.com>
Sat, 03 Sep 2016 20:19:45 +0530
changeset 10187 6fdd22a6b7ecb3e3900ee83817ff211723c0dbee
parent 10182 c33117ccdc57078b9d79199f13c8a4528bb01791
push id1467
push userbmo:manishearth@gmail.com
push dateFri, 20 Jan 2017 09:58:33 +0000
reviewerssmacleod
bugs1228311
Bug 1228311 - Remember last try syntax used for a review; r?smacleod MozReview-Commit-ID: 87dGz6I0Jdh
pylib/mozreview/mozreview/hooks.py
pylib/mozreview/mozreview/static/mozreview/js/autoland.js
pylib/mozreview/mozreview/templates/mozreview/commits.html
--- a/pylib/mozreview/mozreview/hooks.py
+++ b/pylib/mozreview/mozreview/hooks.py
@@ -62,39 +62,42 @@ class CommitContextTemplateHook(Template
             cur_index = children_details.index(review_request_details)
             current_child_num = cur_index + 1
             next_child = (children_details[cur_index + 1]
                           if cur_index + 1 < n_children else None)
             prev_child = (children_details[cur_index - 1]
                           if cur_index - 1 >= 0 else None)
 
         latest_autoland_requests = []
+        try_syntax = ''
         repo_urls = set()
         autoland_requests = AutolandRequest.objects.filter(
             review_request_id=parent.id).order_by('-autoland_id')
 
         # We would like to fetch the latest AutolandRequest for each
         # different repository.
         for request in autoland_requests:
             if request.repository_url in repo_urls:
                 continue
 
             repo_urls.add(request.repository_url)
             latest_autoland_requests.append(request)
+            try_syntax = try_syntax or request.extra_data.get('try_syntax', '')
 
         return {
             'review_request_details': review_request_details,
             'parent_details': parent_details,
             'children_details': children_details,
             'num_children': n_children,
             'current_child_num': current_child_num,
             'next_child': next_child,
             'prev_child': prev_child,
             'latest_autoland_requests': latest_autoland_requests,
             'user': user,
+            'try_syntax': 'try_syntax',
         }
 
 class MozReviewApprovalHook(ReviewRequestApprovalHook):
     """Calculates landing approval for review requests.
 
     This hook allows us to control the `approved` and `approval_failure`
     fields on review request model instances, and Web API results
     associated with them. By calculating landing approval and returning
--- a/pylib/mozreview/mozreview/static/mozreview/js/autoland.js
+++ b/pylib/mozreview/mozreview/static/mozreview/js/autoland.js
@@ -55,34 +55,51 @@
       var html = [
         '<label for="mozreview-autoland-try-syntax">TryChooser Syntax</label>',
         '<textarea id="mozreview-autoland-try-syntax" name="mozreview-autoland-try-syntax" placeholder="try: -b do -p win32 -u all -t none"/>',
         '<p>Enter TryChooser syntax here for your Try build.</p>',
         '<p><span id="try-syntax-error">You have an error in your try syntax</span></p>',
         '<p><details id="mozreview-open-try"><summary>Graphically build syntax</summary><p><iframe id="mozreview-trychooser-iframe" src="' + trychooser_url + '"/></p></details></p>',
       ];
 
+
+      var oldTrySyntax = $('#ci-actions').data('try-syntax');
+
+      if (oldTrySyntax !== undefined) {
+        box.find('#mozreview-autoland-try-syntax').val(oldTrySyntax);
+      }
+
+      box.find('#mozreview-autoland-try-syntax').on('change', function () {allowReset = true});
+
+      // in case there was no previous try push, allow the trychooser to reset
+      // the try syntax. Else, wait for it to be changed
+      var allowReset = oldTrySyntax === undefined || oldTrySyntax === "";
       if (trychooser_url === "") {
         html.pop();
       } else {
         window.onmessage = function(e) {
           if (e.origin === new URL(trychooser_url).origin) {
             if (e.data != "") {
               $('#mozreview-autoland-try-syntax').val("try: " + e.data)
-            } else {
+            } else if (allowReset) {
+              // We only reset the value if it has been changed since
+              // This prevents the first load of the page from overriding
+              // the try syntax input
               $('#mozreview-autoland-try-syntax').val("")
             }
           }
         }
       }
 
       for (var i = 0; i < html.length; ++i) {
         box.append($(html[i]).addClass("mozreview-autoland-try-chooser-element"));
       }
 
+
+
       box.modalBox({
           title: "Trigger a Try Build",
           buttons: [
             $('<input type="button"/>')
                 .val(gettext("Cancel")),
             $('<input type="button"/>')
               .val("Submit")
               .click(function() {
--- a/pylib/mozreview/mozreview/templates/mozreview/commits.html
+++ b/pylib/mozreview/mozreview/templates/mozreview/commits.html
@@ -40,17 +40,17 @@ This is the template for the "Commits" l
       {% if parent_details.get_review_request.id == review_request_details.get_review_request.id %}
         &bull; <a href="{{parent_details.get_review_request.get_absolute_url}}diff/#index_header">Squashed Diff</a>
       {% endif %}
   </div>
 
   {% include 'mozreview/commits-requests.html' %}
 
   {% if latest_autoland_requests %}
-  <div id="ci-actions">
+  <div id="ci-actions" data-try-syntax="{{try_syntax}}">
     {% for autoland_request in latest_autoland_requests %}
       {% if not forloop.first %}
       <div class="action-separator"></div>
       {% endif %}
 
       {% if autoland_request.last_known_status == 'P' %}
       <div class="action action-failure">
         <div class="action-icon rounded-icon"></div>