Merge "Add submission ID and reverted changes to commit message"
This commit is contained in:
@@ -209,6 +209,7 @@ limitations under the License.
|
||||
hidden></gr-confirm-revert-dialog>
|
||||
<gr-confirm-revert-submission-dialog id="confirmRevertSubmissionDialog"
|
||||
class="confirmDialog"
|
||||
commit-message="[[commitMessage]]"
|
||||
on-confirm="_handleRevertSubmissionDialogConfirm"
|
||||
on-cancel="_handleConfirmDialogCancel"
|
||||
hidden></gr-confirm-revert-submission-dialog>
|
||||
|
||||
@@ -924,17 +924,15 @@
|
||||
this._showActionDialog(this.$.confirmRevertDialog);
|
||||
}
|
||||
|
||||
_modifyRevertSubmissionMsg() {
|
||||
return this.$.jsAPI.modifyRevertSubmissionMsg(this.change,
|
||||
this.$.confirmRevertSubmissionDialog.message, this.commitMessage);
|
||||
}
|
||||
|
||||
showRevertSubmissionDialog() {
|
||||
this.$.confirmRevertSubmissionDialog.populateRevertSubmissionMessage(
|
||||
this.commitMessage, this.change.current_revision);
|
||||
this.$.confirmRevertSubmissionDialog.message =
|
||||
this._modifyRevertSubmissionMsg();
|
||||
this._showActionDialog(this.$.confirmRevertSubmissionDialog);
|
||||
const query = 'submissionid:' + this.change.submission_id;
|
||||
this.$.restAPI.getChanges('', query)
|
||||
.then(changes => {
|
||||
this.$.confirmRevertSubmissionDialog.
|
||||
populateRevertSubmissionMessage(
|
||||
this.commitMessage, this.change, changes);
|
||||
this._showActionDialog(this.$.confirmRevertSubmissionDialog);
|
||||
});
|
||||
}
|
||||
|
||||
_handleActionTap(e) {
|
||||
|
||||
@@ -1467,6 +1467,36 @@ limitations under the License.
|
||||
});
|
||||
});
|
||||
|
||||
suite('show revert submission dialog', () => {
|
||||
setup(() => {
|
||||
element.change.submission_id = '199';
|
||||
element.change.current_revision = '2000';
|
||||
sandbox.stub(element.$.restAPI, 'getChanges')
|
||||
.returns(Promise.resolve([
|
||||
{change_id: '12345678901234', topic: 'T', subject: 'random'},
|
||||
{change_id: '23456', topic: 'T', subject: 'a'.repeat(100)},
|
||||
]));
|
||||
});
|
||||
|
||||
test('revert submission shows submissionId', done => {
|
||||
const expectedMsg = 'Revert submission 199' + '\n\n' +
|
||||
'Reason for revert: <INSERT REASONING HERE>' + '\n' +
|
||||
'Reverted Changes:' + '\n' +
|
||||
'1234567890:random' + '\n' +
|
||||
'23456:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...' +
|
||||
'\n';
|
||||
const modifiedMsg = expectedMsg + 'abcd';
|
||||
sandbox.stub(element.$.confirmRevertSubmissionDialog,
|
||||
'_modifyRevertSubmissionMsg').returns(modifiedMsg);
|
||||
element.showRevertSubmissionDialog();
|
||||
flush(() => {
|
||||
const msg = element.$.confirmRevertSubmissionDialog.message;
|
||||
assert.equal(msg, modifiedMsg);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('single changes revert', () => {
|
||||
let navigateToSearchQueryStub;
|
||||
setup(() => {
|
||||
|
||||
@@ -20,6 +20,7 @@ limitations under the License.
|
||||
<link rel="import" href="../../../behaviors/fire-behavior/fire-behavior.html">
|
||||
<link rel="import" href="../../shared/gr-dialog/gr-dialog.html">
|
||||
<link rel="import" href="../../../styles/shared-styles.html">
|
||||
<link rel="import" href="../../shared/gr-js-api-interface/gr-js-api-interface.html">
|
||||
|
||||
<dom-module id="gr-confirm-revert-submission-dialog">
|
||||
<template>
|
||||
@@ -66,6 +67,7 @@ limitations under the License.
|
||||
bind-value="{{message}}"></iron-autogrow-textarea>
|
||||
</div>
|
||||
</gr-dialog>
|
||||
<gr-js-api-interface id="jsAPI"></gr-js-api-interface>
|
||||
</template>
|
||||
<script src="gr-confirm-revert-submission-dialog.js"></script>
|
||||
</dom-module>
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
const ERR_COMMIT_NOT_FOUND =
|
||||
'Unable to find the commit hash of this change.';
|
||||
const CHANGE_SUBJECT_LIMIT = 50;
|
||||
|
||||
/**
|
||||
* @appliesMixin Gerrit.FireMixin
|
||||
@@ -44,18 +45,40 @@
|
||||
static get properties() {
|
||||
return {
|
||||
message: String,
|
||||
commitMessage: String,
|
||||
};
|
||||
}
|
||||
|
||||
populateRevertSubmissionMessage(message, commitHash) {
|
||||
getTrimmedChangeSubject(subject) {
|
||||
if (!subject) return '';
|
||||
if (subject.length < CHANGE_SUBJECT_LIMIT) return subject;
|
||||
return subject.substring(0, CHANGE_SUBJECT_LIMIT) + '...';
|
||||
}
|
||||
|
||||
_modifyRevertSubmissionMsg(change) {
|
||||
return this.$.jsAPI.modifyRevertSubmissionMsg(change,
|
||||
this.message, this.commitMessage);
|
||||
}
|
||||
|
||||
populateRevertSubmissionMessage(message, change, changes) {
|
||||
// Follow the same convention of the revert
|
||||
const revertTitle = 'Revert submission';
|
||||
const commitHash = change.current_revision;
|
||||
if (!commitHash) {
|
||||
this.fire('show-alert', {message: ERR_COMMIT_NOT_FOUND});
|
||||
return;
|
||||
}
|
||||
this.message = `${revertTitle}\n\n` +
|
||||
`Reason for revert: <INSERT REASONING HERE>\n`;
|
||||
const submissionId = change.submission_id;
|
||||
const revertTitle = 'Revert submission ' + submissionId;
|
||||
this.changes = changes;
|
||||
this.message = revertTitle + '\n\n' +
|
||||
'Reason for revert: <INSERT REASONING HERE>\n';
|
||||
this.message += 'Reverted Changes:\n';
|
||||
changes = changes || [];
|
||||
changes.forEach(change => {
|
||||
this.message += change.change_id.substring(0, 10) + ':' +
|
||||
this.getTrimmedChangeSubject(change.subject) + '\n';
|
||||
});
|
||||
this.message = this._modifyRevertSubmissionMsg(change);
|
||||
}
|
||||
|
||||
_handleConfirmTap(e) {
|
||||
|
||||
Reference in New Issue
Block a user