mozreview: actually send rewritten commit descriptions to autoland (bug 1229756) r=dminor
authorbyron jones <glob@mozilla.com>
Thu, 03 Dec 2015 01:22:36 +0800
changeset 3515 a2d805bdf9a5d20cfa7e34baac9fee53f43f1bce
parent 3514 58ef7b67c571637c4fb7b303f30b8e73adc2ba5f
child 3516 a7dd4207b7205516d267cea271a226516a2e08ea
push id1379
push userdminor@mozilla.com
push dateWed, 02 Dec 2015 17:36:42 +0000
treeherderversion-control-tools@a2d805bdf9a5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdminor
bugs1229756
mozreview: actually send rewritten commit descriptions to autoland (bug 1229756) r=dminor While commit descriptions were being rewritten and displayed to the user for confirmation, the step of actually sending them to autoland was somehow missed. This extends mozreview's autoland api call to accept a commit_descriptions *json encoded string*, and passes it unmodified to autoland.
pylib/mozreview/mozreview/autoland/resources.py
pylib/mozreview/mozreview/static/mozreview/js/autoland.js
--- a/pylib/mozreview/mozreview/autoland/resources.py
+++ b/pylib/mozreview/mozreview/autoland/resources.py
@@ -107,20 +107,26 @@ class AutolandTriggerResource(BaseAutola
     @webapi_scm_groups_required('scm_level_3')
     @webapi_request_fields(
         required={
             'review_request_id': {
                 'type': int,
                 'description': 'The review request for which to trigger a Try '
                                'build',
             },
+            'commit_descriptions': {
+                'type': six.text_type,
+                'description': 'Commit descriptions which overwrite the repo '
+                               'commit message. JSON encoded string.  See '
+                               '/autoland route for details.',
+            }
         },
     )
     @transaction.atomic
-    def create(self, request, review_request_id, *args, **kwargs):
+    def create(self, request, review_request_id, commit_descriptions, *args, **kwargs):
         try:
             rr = ReviewRequest.objects.get(pk=review_request_id)
         except ReviewRequest.DoesNotExist:
             return DOES_NOT_EXIST
 
         if not is_pushed(rr) or not is_parent(rr):
             logging.error('Failed triggering Autoland because the review '
                           'request is not pushed, or not the parent review '
@@ -161,26 +167,29 @@ class AutolandTriggerResource(BaseAutola
 
         logging.info('Telling Autoland to give status updates to %s'
                      % pingback_url)
 
         lock_id = get_autoland_lock_id(rr.id, target_repository, last_revision)
         if not acquire_lock(lock_id):
             return AUTOLAND_REQUEST_IN_PROGRESS
         try:
-            response = requests.post(autoland_url + '/autoland',
+            response = requests.post(
+                autoland_url + '/autoland',
                 data=json.dumps({
-                'tree': rr.repository.name,
-                'pingback_url': pingback_url,
-                'rev': last_revision,
-                'destination': target_repository,
-                'push_bookmark': push_bookmark,
-            }), headers={
-                'content-type': 'application/json',
-            },
+                    'tree': rr.repository.name,
+                    'pingback_url': pingback_url,
+                    'rev': last_revision,
+                    'destination': target_repository,
+                    'push_bookmark': push_bookmark,
+                    'commit_descriptions': json.loads(commit_descriptions),
+                }),
+                headers={
+                    'content-type': 'application/json',
+                },
                 timeout=AUTOLAND_REQUEST_TIMEOUT,
                 auth=(autoland_user, autoland_password))
         except requests.exceptions.RequestException:
             logging.error('We hit a RequestException when submitting a '
                           'request to Autoland')
             release_lock(lock_id)
             return AUTOLAND_ERROR
         except requests.exceptions.Timeout:
--- a/pylib/mozreview/mozreview/static/mozreview/js/autoland.js
+++ b/pylib/mozreview/mozreview/static/mozreview/js/autoland.js
@@ -161,37 +161,39 @@
           .html(
             '<p>About to land the following commits to <span id="autoland-repo">?</span>.<br>' +
             'Please confirm these commit descriptions are correct before landing.<br>' +
             'If corrections are required please <b>amend</b> the commit ' +
             'message and try again.</p>' +
             '<div id="autoland-commits"/>'
           );
         $('#autoland-repo').text(MozReview.landingRepository);
+        var commit_descriptions = {};
         $.each(rsp.commits, function() {
           $('#autoland-commits')
             .append(
               $('<div/>')
                 .addClass('autoland-commit-desc')
                 .text(this.summary.split("\n")[0]))
             .append(
               $('<div/>')
                 .append(
                   $('<span/>')
                     .addClass('autoland-commit-rev')
                     .text(this.commit.substr(0, 12)))
                 .append(
                   $('<span/>')
                     .addClass('autoland-commit-reviewers')
-                    .text(
-                      this.approved ? 'reviewers: ' + this.reviewers.join(', ')
-                        : 'NOT APPROVED')));
-          $('#autoland-submit')
-            .prop('disabled', false);
+                    .text('reviewers: ' + this.reviewers.join(', '))));
+          // store commit descriptions in a form ready to pass to autoland
+          commit_descriptions[this.commit.substr(0, 12)] = this.summary;
         });
+        $('#autoland-submit')
+          .data('commits', commit_descriptions)
+          .prop('disabled', false);
       },
       error: function(res) {
         box.modalBox('destroy');
         try {
           show_error(jQuery.parseJSON(res.responseText).err.msg);
         } catch(e) {
           show_error(res.responseText);
         }
@@ -205,17 +207,21 @@
     activityIndicator = $("#activity-indicator")
       .removeClass("error")
       .text(gettext("Triggering landing..."))
       .show();
 
     $.ajax({
       type: "POST",
       url: AUTOLAND_URL,
-      data: { review_request_id: MozReview.parentReviewRequest.id }
+      data: {
+          review_request_id: MozReview.parentReviewRequest.id,
+          commit_descriptions: JSON.stringify(
+              $('#autoland-submit').data('commits'))
+      }
     })
     .done(function(){
       // There may be a better way to get the review request updates
       // but this is probably good enough for now
       window.location.reload();
     })
     .fail(function(jqXHR, textStatus, errorThrown){
       var error_text = "";