Merge "Add hook for specifying which labels need to be set on reverts"
This commit is contained in:
		@@ -419,10 +419,22 @@
 | 
			
		||||
      });
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    // TODO(rmistry): Redo this after
 | 
			
		||||
    // https://bugs.chromium.org/p/gerrit/issues/detail?id=4671 is resolved.
 | 
			
		||||
    _setLabelValuesOnRevert: function(newChangeId) {
 | 
			
		||||
      var labels = this.$.jsAPI.getLabelValuesPostRevert(this.change);
 | 
			
		||||
      if (labels) {
 | 
			
		||||
        var url = '/changes/' + newChangeId + '/revisions/current/review';
 | 
			
		||||
        this.$.restAPI.send(this.actions.revert.method, url, {labels: labels});
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    _handleResponse: function(action, response) {
 | 
			
		||||
      return this.$.restAPI.getResponseObject(response).then(function(obj) {
 | 
			
		||||
        switch (action.__key) {
 | 
			
		||||
          case ChangeActions.REVERT:
 | 
			
		||||
            this._setLabelValuesOnRevert(obj.change_id);
 | 
			
		||||
            // Fall through.
 | 
			
		||||
          case RevisionActions.CHERRYPICK:
 | 
			
		||||
            page.show(this.changePath(obj._number));
 | 
			
		||||
            break;
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,7 @@
 | 
			
		||||
    SUBMIT_CHANGE: 'submitchange',
 | 
			
		||||
    COMMENT: 'comment',
 | 
			
		||||
    REVERT: 'revert',
 | 
			
		||||
    POST_REVERT: 'postrevert',
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  var Element = {
 | 
			
		||||
@@ -160,6 +161,20 @@
 | 
			
		||||
      return msg;
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    getLabelValuesPostRevert: function(change) {
 | 
			
		||||
      var labels = {};
 | 
			
		||||
      this._getEventCallbacks(EventType.POST_REVERT).forEach(
 | 
			
		||||
          function(callback) {
 | 
			
		||||
            try {
 | 
			
		||||
              labels = callback(change);
 | 
			
		||||
            } catch (err) {
 | 
			
		||||
              console.error(err);
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
      );
 | 
			
		||||
      return labels;
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    _getEventCallbacks: function(type) {
 | 
			
		||||
      return this._eventCallbacks[type] || [];
 | 
			
		||||
    },
 | 
			
		||||
 
 | 
			
		||||
@@ -121,6 +121,22 @@ limitations under the License.
 | 
			
		||||
      assert.isTrue(errorStub.calledTwice);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('postrevert event', function(done) {
 | 
			
		||||
      function getLabels(c) {
 | 
			
		||||
        return {'Code-Review': 1};
 | 
			
		||||
      }
 | 
			
		||||
      done();
 | 
			
		||||
 | 
			
		||||
      assert.deepEqual(element.getLabelValuesPostRevert(null), {});
 | 
			
		||||
      assert.equal(errorStub.callCount, 0);
 | 
			
		||||
 | 
			
		||||
      plugin.on(element.EventType.POST_REVERT, throwErrFn);
 | 
			
		||||
      plugin.on(element.EventType.POST_REVERT, getLabels);
 | 
			
		||||
      assert.deepEqual(element.getLabelValuesPostRevert(null),
 | 
			
		||||
                       {'Code-Review': 1});
 | 
			
		||||
      assert.isTrue(errorStub.calledOnce);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('labelchange event', function(done) {
 | 
			
		||||
      var testChange = {_number: 42};
 | 
			
		||||
      plugin.on(element.EventType.LABEL_CHANGE, throwErrFn);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user