Merge "When edit is latest patchset, select it by default"
This commit is contained in:
@@ -924,6 +924,30 @@
|
|||||||
return msg.replace(REVIEWERS_REGEX, '$1=\u200B');
|
return msg.replace(REVIEWERS_REGEX, '$1=\u200B');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility function to make the necessary modifications to a change in the
|
||||||
|
* case an edit exists.
|
||||||
|
*
|
||||||
|
* @param {!Object} change
|
||||||
|
* @param {?Object} edit
|
||||||
|
*/
|
||||||
|
_processEdit(change, edit) {
|
||||||
|
if (!edit) { return; }
|
||||||
|
change.revisions[edit.commit.commit] = {
|
||||||
|
_number: this.EDIT_NAME,
|
||||||
|
basePatchNum: edit.base_patch_set_number,
|
||||||
|
commit: edit.commit,
|
||||||
|
fetch: edit.fetch,
|
||||||
|
};
|
||||||
|
// If the edit is based on the most recent patchset, load it by
|
||||||
|
// default, unless another patch set to load was specified in the URL.
|
||||||
|
if (!this._patchRange.patchNum &&
|
||||||
|
change.current_revision === edit.base_revision) {
|
||||||
|
change.current_revision = edit.commit.commit;
|
||||||
|
this._patchRange.patchNum = this.EDIT_NAME;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
_getChangeDetail() {
|
_getChangeDetail() {
|
||||||
const detailCompletes = this.$.restAPI.getChangeDetail(
|
const detailCompletes = this.$.restAPI.getChangeDetail(
|
||||||
this._changeNum, this._handleGetChangeDetailError.bind(this));
|
this._changeNum, this._handleGetChangeDetailError.bind(this));
|
||||||
@@ -935,14 +959,7 @@
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
this._upgradeUrl(change, this.params);
|
this._upgradeUrl(change, this.params);
|
||||||
if (edit) {
|
this._processEdit(change, edit);
|
||||||
change.revisions[edit.commit.commit] = {
|
|
||||||
_number: this.EDIT_NAME,
|
|
||||||
basePatchNum: edit.base_patch_set_number,
|
|
||||||
commit: edit.commit,
|
|
||||||
fetch: edit.fetch,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
// Issue 4190: Coalesce missing topics to null.
|
// Issue 4190: Coalesce missing topics to null.
|
||||||
if (!change.topic) { change.topic = null; }
|
if (!change.topic) { change.topic = null; }
|
||||||
if (!change.reviewer_updates) {
|
if (!change.reviewer_updates) {
|
||||||
|
|||||||
@@ -886,6 +886,7 @@ limitations under the License.
|
|||||||
commit: {commit: 'bar'},
|
commit: {commit: 'bar'},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
element._patchRange = {};
|
||||||
|
|
||||||
return element._getChangeDetail().then(() => {
|
return element._getChangeDetail().then(() => {
|
||||||
const revs = element._change.revisions;
|
const revs = element._change.revisions;
|
||||||
@@ -1296,6 +1297,43 @@ limitations under the License.
|
|||||||
assert.isTrue(callCompute({basePatchNum: 1, patchNum: 'edit'}));
|
assert.isTrue(callCompute({basePatchNum: 1, patchNum: 'edit'}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('_processEdit', () => {
|
||||||
|
element._patchRange = {};
|
||||||
|
const change = {
|
||||||
|
current_revision: 'foo',
|
||||||
|
revisions: {foo: {commit: {}}},
|
||||||
|
};
|
||||||
|
let mockChange;
|
||||||
|
|
||||||
|
// With no edit, mockChange should be unmodified.
|
||||||
|
element._processEdit(mockChange = _.cloneDeep(change), null);
|
||||||
|
assert.deepEqual(mockChange, change);
|
||||||
|
|
||||||
|
// When edit is not based on the latest PS, current_revision should be
|
||||||
|
// unmodified.
|
||||||
|
const edit = {
|
||||||
|
base_patch_set_number: 1,
|
||||||
|
commit: {commit: 'bar'},
|
||||||
|
fetch: true,
|
||||||
|
};
|
||||||
|
element._processEdit(mockChange = _.cloneDeep(change), edit);
|
||||||
|
assert.notDeepEqual(mockChange, change);
|
||||||
|
assert.equal(mockChange.revisions.bar._number, element.EDIT_NAME);
|
||||||
|
assert.equal(mockChange.current_revision, change.current_revision);
|
||||||
|
assert.deepEqual(mockChange.revisions.bar.commit, {commit: 'bar'});
|
||||||
|
|
||||||
|
edit.base_revision = 'foo';
|
||||||
|
element._processEdit(mockChange = _.cloneDeep(change), edit);
|
||||||
|
assert.notDeepEqual(mockChange, change);
|
||||||
|
assert.equal(mockChange.current_revision, 'bar');
|
||||||
|
|
||||||
|
// If _patchRange.patchNum is defined, do not load edit.
|
||||||
|
element._patchRange.patchNum = 'baz';
|
||||||
|
change.current_revision = 'baz';
|
||||||
|
element._processEdit(mockChange = _.cloneDeep(change), edit);
|
||||||
|
assert.equal(element._patchRange.patchNum, 'baz');
|
||||||
|
});
|
||||||
|
|
||||||
suite('_upgradeUrl calls', () => {
|
suite('_upgradeUrl calls', () => {
|
||||||
let upgradeStub;
|
let upgradeStub;
|
||||||
const mockChange = {project: 'test'};
|
const mockChange = {project: 'test'};
|
||||||
|
|||||||
Reference in New Issue
Block a user