Merge "ES6ify /gr-change-metadata/*"
diff --git a/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/TestAccount.java b/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/TestAccount.java
index 5117328..3ab4a88 100644
--- a/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/TestAccount.java
+++ b/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/TestAccount.java
@@ -16,12 +16,15 @@
import static java.util.stream.Collectors.toList;
+import com.google.common.net.InetAddresses;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.server.mail.Address;
import com.jcraft.jsch.KeyPair;
import java.io.ByteArrayOutputStream;
+import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.List;
+import org.apache.http.client.utils.URIBuilder;
import org.eclipse.jgit.lib.PersonIdent;
public class TestAccount {
@@ -77,12 +80,13 @@
}
public String getHttpUrl(GerritServer server) {
- return String.format(
- "http://%s:%s@%s:%d",
- username,
- httpPassword,
- server.getHttpAddress().getAddress().getHostAddress(),
- server.getHttpAddress().getPort());
+ InetSocketAddress addr = server.getHttpAddress();
+ return new URIBuilder()
+ .setScheme("http")
+ .setUserInfo(username, httpPassword)
+ .setHost(InetAddresses.toUriString(addr.getAddress()))
+ .setPort(addr.getPort())
+ .toString();
}
public Account.Id getId() {
diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/IoUtil.java b/gerrit-common/src/main/java/com/google/gerrit/common/IoUtil.java
index 1ac42d1..624bcea 100644
--- a/gerrit-common/src/main/java/com/google/gerrit/common/IoUtil.java
+++ b/gerrit-common/src/main/java/com/google/gerrit/common/IoUtil.java
@@ -56,6 +56,10 @@
}
public static void loadJARs(Collection<Path> jars) {
+ if (jars.isEmpty()) {
+ return;
+ }
+
ClassLoader cl = IoUtil.class.getClassLoader();
if (!(cl instanceof URLClassLoader)) {
throw noAddURL("Not loaded by URLClassLoader", null);
diff --git a/gerrit-plugin-api/BUILD b/gerrit-plugin-api/BUILD
index ebc5619..2e768ee 100644
--- a/gerrit-plugin-api/BUILD
+++ b/gerrit-plugin-api/BUILD
@@ -19,6 +19,7 @@
"//gerrit-extension-api:api",
"//gerrit-gwtexpui:server",
"//gerrit-reviewdb:server",
+ "//gerrit-server/src/main/prolog:common",
"//lib/commons:lang",
"//lib/commons:lang3",
"//lib/dropwizard:dropwizard-core",
diff --git a/lib/prolog/BUILD b/lib/prolog/BUILD
index 875f135..f6b4c5f 100644
--- a/lib/prolog/BUILD
+++ b/lib/prolog/BUILD
@@ -6,6 +6,13 @@
)
java_library(
+ name = "runtime-neverlink",
+ data = ["//lib:LICENSE-prologcafe"],
+ visibility = ["//visibility:public"],
+ exports = ["@prolog_runtime//jar:neverlink"],
+)
+
+java_library(
name = "compiler",
data = ["//lib:LICENSE-prologcafe"],
visibility = ["//visibility:public"],
diff --git a/lib/prolog/prolog.bzl b/lib/prolog/prolog.bzl
index cae85ad..43a8bab 100644
--- a/lib/prolog/prolog.bzl
+++ b/lib/prolog/prolog.bzl
@@ -12,14 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-load("//tools/bzl:genrule2.bzl", "genrule2")
-
def prolog_cafe_library(
name,
srcs,
deps = [],
**kwargs):
- genrule2(
+ native.genrule(
name = name + '__pl2j',
cmd = '$(location //lib/prolog:compiler_bin) ' +
'$$(dirname $@) $@ ' +
@@ -31,6 +29,6 @@
native.java_library(
name = name,
srcs = [':' + name + '__pl2j'],
- deps = ['//lib/prolog:runtime'] + deps,
+ deps = ['//lib/prolog:runtime-neverlink'] + deps,
**kwargs
)
diff --git a/polygerrit-ui/app/elements/change/gr-confirm-abandon-dialog/gr-confirm-abandon-dialog.js b/polygerrit-ui/app/elements/change/gr-confirm-abandon-dialog/gr-confirm-abandon-dialog.js
index e47f14f..074e39e 100644
--- a/polygerrit-ui/app/elements/change/gr-confirm-abandon-dialog/gr-confirm-abandon-dialog.js
+++ b/polygerrit-ui/app/elements/change/gr-confirm-abandon-dialog/gr-confirm-abandon-dialog.js
@@ -33,16 +33,16 @@
message: String,
},
- resetFocus: function() {
+ resetFocus() {
this.$.messageInput.textarea.focus();
},
- _handleConfirmTap: function(e) {
+ _handleConfirmTap(e) {
e.preventDefault();
this.fire('confirm', {reason: this.message}, {bubbles: false});
},
- _handleCancelTap: function(e) {
+ _handleCancelTap(e) {
e.preventDefault();
this.fire('cancel', null, {bubbles: false});
},
diff --git a/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog.js b/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog.js
index f843ee8..b26802d 100644
--- a/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog.js
+++ b/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog.js
@@ -35,7 +35,7 @@
_schemes: {
type: Array,
- value: function() { return []; },
+ value() { return []; },
computed: '_computeSchemes(change, patchNum)',
observer: '_schemesChanged',
},
@@ -50,7 +50,7 @@
Gerrit.RESTClientBehavior,
],
- focus: function() {
+ focus() {
if (this._schemes.length) {
this.$$('.copyToClipboard').focus();
} else {
@@ -58,59 +58,60 @@
}
},
- getFocusStops: function() {
- var links = this.$$('#archives').querySelectorAll('a');
+ getFocusStops() {
+ const links = this.$$('#archives').querySelectorAll('a');
return {
start: this.$.closeButton,
end: links[links.length - 1],
};
},
- _loggedInChanged: function(loggedIn) {
+ _loggedInChanged(loggedIn) {
if (!loggedIn) { return; }
- this.$.restAPI.getPreferences().then(function(prefs) {
+ this.$.restAPI.getPreferences().then(prefs => {
if (prefs.download_scheme) {
// Note (issue 5180): normalize the download scheme with lower-case.
this._selectedScheme = prefs.download_scheme.toLowerCase();
}
- }.bind(this));
+ });
},
- _computeDownloadCommands: function(change, patchNum, _selectedScheme) {
- var commandObj;
- for (var rev in change.revisions) {
+ _computeDownloadCommands(change, patchNum, _selectedScheme) {
+ let commandObj;
+ for (const rev in change.revisions) {
if (change.revisions[rev]._number === patchNum &&
change.revisions[rev].fetch.hasOwnProperty(_selectedScheme)) {
commandObj = change.revisions[rev].fetch[_selectedScheme].commands;
break;
}
}
- var commands = [];
- for (var title in commandObj) {
+ const commands = [];
+ for (const title in commandObj) {
+ if (!commandObj.hasOwnProperty(title)) { continue; }
commands.push({
- title: title,
+ title,
command: commandObj[title],
});
}
return commands;
},
- _computeZipDownloadLink: function(change, patchNum) {
+ _computeZipDownloadLink(change, patchNum) {
return this._computeDownloadLink(change, patchNum, true);
},
- _computeZipDownloadFilename: function(change, patchNum) {
+ _computeZipDownloadFilename(change, patchNum) {
return this._computeDownloadFilename(change, patchNum, true);
},
- _computeDownloadLink: function(change, patchNum, zip) {
+ _computeDownloadLink(change, patchNum, zip) {
return this.changeBaseURL(change._number, patchNum) + '/patch?' +
(zip ? 'zip' : 'download');
},
- _computeDownloadFilename: function(change, patchNum, zip) {
- var shortRev;
- for (var rev in change.revisions) {
+ _computeDownloadFilename(change, patchNum, zip) {
+ let shortRev;
+ for (const rev in change.revisions) {
if (change.revisions[rev]._number === patchNum) {
shortRev = rev.substr(0, 7);
break;
@@ -119,15 +120,15 @@
return shortRev + '.diff.' + (zip ? 'zip' : 'base64');
},
- _computeArchiveDownloadLink: function(change, patchNum, format) {
+ _computeArchiveDownloadLink(change, patchNum, format) {
return this.changeBaseURL(change._number, patchNum) +
'/archive?format=' + format;
},
- _computeSchemes: function(change, patchNum) {
- for (var rev in change.revisions) {
+ _computeSchemes(change, patchNum) {
+ for (const rev in change.revisions) {
if (change.revisions[rev]._number === patchNum) {
- var fetch = change.revisions[rev].fetch;
+ const fetch = change.revisions[rev].fetch;
if (fetch) {
return Object.keys(fetch).sort();
}
@@ -137,47 +138,47 @@
return [];
},
- _computePatchSetQuantity: function(revisions) {
+ _computePatchSetQuantity(revisions) {
if (!revisions) { return 0; }
return Object.keys(revisions).length;
},
- _computeSchemeSelected: function(scheme, selectedScheme) {
+ _computeSchemeSelected(scheme, selectedScheme) {
return scheme === selectedScheme;
},
- _handleSchemeTap: function(e) {
+ _handleSchemeTap(e) {
e.preventDefault();
- var el = Polymer.dom(e).rootTarget;
+ const el = Polymer.dom(e).rootTarget;
this._selectedScheme = el.getAttribute('data-scheme');
if (this.loggedIn) {
this.$.restAPI.savePreferences({download_scheme: this._selectedScheme});
}
},
- _handleInputTap: function(e) {
+ _handleInputTap(e) {
e.preventDefault();
Polymer.dom(e).rootTarget.select();
},
- _handleCloseTap: function(e) {
+ _handleCloseTap(e) {
e.preventDefault();
this.fire('close', null, {bubbles: false});
},
- _schemesChanged: function(schemes) {
+ _schemesChanged(schemes) {
if (schemes.length === 0) { return; }
- if (schemes.indexOf(this._selectedScheme) === -1) {
+ if (!schemes.includes(this._selectedScheme)) {
this._selectedScheme = schemes.sort()[0];
}
},
- _copyToClipboard: function(e) {
+ _copyToClipboard(e) {
e.target.parentElement.querySelector('.copyCommand').select();
document.execCommand('copy');
getSelection().removeAllRanges();
e.target.textContent = 'done';
- setTimeout(function() { e.target.textContent = 'copy'; }, 1000);
+ setTimeout(() => { e.target.textContent = 'copy'; }, 1000);
},
});
})();
diff --git a/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog_test.html b/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog_test.html
index 0635d6d..4a8d2d9 100644
--- a/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog_test.html
+++ b/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog_test.html
@@ -48,8 +48,8 @@
fetch: {
repo: {
commands: {
- repo: 'repo download test-project 5/1'
- }
+ repo: 'repo download test-project 5/1',
+ },
},
ssh: {
commands: {
@@ -69,8 +69,8 @@
'Pull':
'git pull ' +
'ssh://andybons@localhost:29418/test-project ' +
- 'refs/changes/05/5/1'
- }
+ 'refs/changes/05/5/1',
+ },
},
http: {
commands: {
@@ -90,12 +90,12 @@
'Pull':
'git pull ' +
'http://andybons@localhost:8080/a/test-project ' +
- 'refs/changes/05/5/1'
- }
- }
- }
- }
- }
+ 'refs/changes/05/5/1',
+ },
+ },
+ },
+ },
+ },
};
}
@@ -106,74 +106,74 @@
'34685798fe548b6d17d1e8e5edc43a26d055cc72': {
_number: 1,
fetch: {},
- }
- }
+ },
+ },
};
}
- suite('gr-download-dialog tests with no fetch options', function() {
- var element;
+ suite('gr-download-dialog tests with no fetch options', () => {
+ let element;
- setup(function() {
+ setup(() => {
element = fixture('basic');
element.change = getChangeObjectNoFetch();
element.patchNum = 1;
element.config = {
schemes: {
'anonymous http': {},
- http: {},
- repo: {},
- ssh: {},
+ 'http': {},
+ 'repo': {},
+ 'ssh': {},
},
archives: ['tgz', 'tar', 'tbz2', 'txz'],
};
});
- test('focuses on first download link if no copy links', function() {
+ test('focuses on first download link if no copy links', () => {
flushAsynchronousOperations();
- var focusStub = sinon.stub(element.$.download, 'focus');
+ const focusStub = sinon.stub(element.$.download, 'focus');
element.focus();
assert.isTrue(focusStub.called);
focusStub.restore();
});
});
- suite('gr-download-dialog tests', function() {
- var element;
+ suite('gr-download-dialog tests', () => {
+ let element;
- setup(function() {
+ setup(() => {
element = fixture('basic');
element.change = getChangeObject();
element.patchNum = 1;
element.config = {
schemes: {
'anonymous http': {},
- http: {},
- repo: {},
- ssh: {},
+ 'http': {},
+ 'repo': {},
+ 'ssh': {},
},
archives: ['tgz', 'tar', 'tbz2', 'txz'],
};
});
- test('focuses on first copy link', function() {
+ test('focuses on first copy link', () => {
flushAsynchronousOperations();
- var focusStub = sinon.stub(element.$$('.copyToClipboard'), 'focus');
+ const focusStub = sinon.stub(element.$$('.copyToClipboard'), 'focus');
element.focus();
flushAsynchronousOperations();
assert.isTrue(focusStub.called);
focusStub.restore();
});
- test('copy to clipboard', function() {
+ test('copy to clipboard', () => {
flushAsynchronousOperations();
- var clipboardSpy = sinon.spy(element, '_copyToClipboard');
- var copyBtn = element.$$('.copyToClipboard');
+ const clipboardSpy = sinon.spy(element, '_copyToClipboard');
+ const copyBtn = element.$$('.copyToClipboard');
MockInteractions.tap(copyBtn);
assert.isTrue(clipboardSpy.called);
});
- test('element visibility', function() {
+ test('element visibility', () => {
assert.isFalse(element.$$('ul').hasAttribute('hidden'));
assert.isFalse(element.$$('main').hasAttribute('hidden'));
assert.isFalse(element.$$('.archivesContainer').hasAttribute('hidden'));
@@ -182,40 +182,40 @@
assert.isTrue(element.$$('.archivesContainer').hasAttribute('hidden'));
});
- test('computed fields', function() {
+ test('computed fields', () => {
assert.equal(element._computeArchiveDownloadLink(
{_number: 123}, 2, 'tgz'),
'/changes/123/revisions/2/archive?format=tgz');
});
- test('close event', function(done) {
- element.addEventListener('close', function() {
+ test('close event', done => {
+ element.addEventListener('close', () => {
done();
});
MockInteractions.tap(element.$$('.closeButtonContainer gr-button'));
});
- test('tab selection', function() {
+ test('tab selection', () => {
flushAsynchronousOperations();
- var el = element.$$('[data-scheme="http"]').parentElement;
+ let el = element.$$('[data-scheme="http"]').parentElement;
assert.isTrue(el.hasAttribute('selected'));
- ['repo', 'ssh'].forEach(function(scheme) {
- var el = element.$$('[data-scheme="' + scheme + '"]').parentElement;
+ for (const scheme of ['repo', 'ssh']) {
+ const el = element.$$('[data-scheme="' + scheme + '"]').parentElement;
assert.isFalse(el.hasAttribute('selected'));
- });
+ }
MockInteractions.tap(element.$$('[data-scheme="ssh"]'));
el = element.$$('[data-scheme="ssh"]').parentElement;
assert.isTrue(el.hasAttribute('selected'));
- ['http', 'repo'].forEach(function(scheme) {
- var el = element.$$('[data-scheme="' + scheme + '"]').parentElement;
+ for (const scheme of ['http', 'repo']) {
+ const el = element.$$('[data-scheme="' + scheme + '"]').parentElement;
assert.isFalse(el.hasAttribute('selected'));
- });
+ }
});
- test('loads scheme from preferences w/o initial login', function(done) {
+ test('loads scheme from preferences w/o initial login', done => {
stub('gr-rest-api-interface', {
- getPreferences: function() {
+ getPreferences() {
return Promise.resolve({download_scheme: 'repo'});
},
});
@@ -223,19 +223,19 @@
element.loggedIn = true;
assert.isTrue(element.$.restAPI.getPreferences.called);
- element.$.restAPI.getPreferences.lastCall.returnValue.then(function() {
+ element.$.restAPI.getPreferences.lastCall.returnValue.then(() => {
assert.equal(element._selectedScheme, 'repo');
done();
});
});
});
- suite('gr-download-dialog tests', function() {
- var element;
+ suite('gr-download-dialog tests', () => {
+ let element;
- setup(function() {
+ setup(() => {
stub('gr-rest-api-interface', {
- getPreferences: function() {
+ getPreferences() {
return Promise.resolve({download_scheme: 'repo'});
},
});
@@ -246,28 +246,28 @@
element.config = {
schemes: {
'anonymous http': {},
- http: {},
- repo: {},
- ssh: {},
+ 'http': {},
+ 'repo': {},
+ 'ssh': {},
},
archives: ['tgz', 'tar', 'tbz2', 'txz'],
};
});
- test('loads scheme from preferences', function(done) {
- element.$.restAPI.getPreferences.lastCall.returnValue.then(function() {
+ test('loads scheme from preferences', done => {
+ element.$.restAPI.getPreferences.lastCall.returnValue.then(() => {
assert.equal(element._selectedScheme, 'repo');
done();
});
});
- test('saves scheme to preferences', function() {
- var savePrefsStub = sinon.stub(element.$.restAPI, 'savePreferences',
- function() { return Promise.resolve(); });
+ test('saves scheme to preferences', () => {
+ const savePrefsStub = sinon.stub(element.$.restAPI, 'savePreferences',
+ () => { return Promise.resolve(); });
Polymer.dom.flush();
- var firstSchemeButton = element.$$('li gr-button[data-scheme]');
+ const firstSchemeButton = element.$$('li gr-button[data-scheme]');
MockInteractions.tap(firstSchemeButton);
@@ -277,9 +277,9 @@
});
});
- test('normalize scheme from preferences', function(done) {
+ test('normalize scheme from preferences', done => {
stub('gr-rest-api-interface', {
- getPreferences: function() {
+ getPreferences() {
return Promise.resolve({download_scheme: 'REPO'});
},
});
@@ -287,10 +287,10 @@
element.change = getChangeObject();
element.patchNum = 1;
element.config = {
- schemes: {'anonymous http': {}, http: {}, repo: {}, ssh: {}},
+ schemes: {'anonymous http': {}, 'http': {}, 'repo': {}, 'ssh': {}},
archives: ['tgz', 'tar', 'tbz2', 'txz'],
};
- element.$.restAPI.getPreferences.lastCall.returnValue.then(function() {
+ element.$.restAPI.getPreferences.lastCall.returnValue.then(() => {
assert.equal(element._selectedScheme, 'repo');
done();
});
diff --git a/polygerrit-ui/app/elements/change/gr-message/gr-message.js b/polygerrit-ui/app/elements/change/gr-message/gr-message.js
index 5467af9..919ef6b 100644
--- a/polygerrit-ui/app/elements/change/gr-message/gr-message.js
+++ b/polygerrit-ui/app/elements/change/gr-message/gr-message.js
@@ -30,7 +30,7 @@
*/
listeners: {
- 'tap': '_handleTap',
+ tap: '_handleTap',
},
properties: {
@@ -86,16 +86,16 @@
'_updateExpandedClass(message.expanded)',
],
- ready: function() {
- this.$.restAPI.getConfig().then(function(config) {
+ ready() {
+ this.$.restAPI.getConfig().then(config => {
this.config = config;
- }.bind(this));
- this.$.restAPI.getLoggedIn().then(function(loggedIn) {
+ });
+ this.$.restAPI.getLoggedIn().then(loggedIn => {
this._loggedIn = loggedIn;
- }.bind(this));
+ });
},
- _updateExpandedClass: function(expanded) {
+ _updateExpandedClass(expanded) {
if (expanded) {
this.classList.add('expanded');
} else {
@@ -103,25 +103,25 @@
}
},
- _computeAuthor: function(message) {
+ _computeAuthor(message) {
return message.author || message.updated_by;
},
- _computeShowAvatar: function(author, config) {
+ _computeShowAvatar(author, config) {
return !!(author && config && config.plugin && config.plugin.has_avatars);
},
- _computeShowOnBehalfOf: function(message) {
- var author = message.author || message.updated_by;
+ _computeShowOnBehalfOf(message) {
+ const author = message.author || message.updated_by;
return !!(author && message.real_author &&
author._account_id != message.real_author._account_id);
},
- _computeShowReplyButton: function(message, loggedIn) {
+ _computeShowReplyButton(message, loggedIn) {
return !!message.message && loggedIn;
},
- _computeExpanded: function(expanded) {
+ _computeExpanded(expanded) {
return expanded;
},
@@ -130,54 +130,54 @@
* should be true or not, then _expanded is set to true if there are
* inline comments (otherwise false).
*/
- _commentsChanged: function(value) {
+ _commentsChanged(value) {
if (this.message && this.message.expanded === undefined) {
this.set('message.expanded', Object.keys(value || {}).length > 0);
}
},
- _handleTap: function(e) {
+ _handleTap(e) {
if (this.message.expanded) { return; }
e.stopPropagation();
this.set('message.expanded', true);
},
- _handleAuthorTap: function(e) {
+ _handleAuthorTap(e) {
if (!this.message.expanded) { return; }
e.stopPropagation();
this.set('message.expanded', false);
},
- _computeIsAutomated: function(message) {
+ _computeIsAutomated(message) {
return !!(message.reviewer ||
- (message.tag && message.tag.indexOf('autogenerated') === 0));
+ (message.tag && message.tag.startsWith('autogenerated')));
},
- _computeIsHidden: function(hideAutomated, isAutomated) {
+ _computeIsHidden(hideAutomated, isAutomated) {
return hideAutomated && isAutomated;
},
- _computeIsReviewerUpdate: function(event) {
+ _computeIsReviewerUpdate(event) {
return event.type === 'REVIEWER_UPDATE';
},
- _computeClass: function(expanded, showAvatar) {
- var classes = [];
+ _computeClass(expanded, showAvatar) {
+ const classes = [];
classes.push(expanded ? 'expanded' : 'collapsed');
classes.push(showAvatar ? 'showAvatar' : 'hideAvatar');
return classes.join(' ');
},
- _computeMessageHash: function(message) {
+ _computeMessageHash(message) {
return '#message-' + message.id;
},
- _handleLinkTap: function(e) {
+ _handleLinkTap(e) {
e.preventDefault();
this.fire('scroll-to', {message: this.message}, {bubbles: false});
- var hash = this._computeMessageHash(this.message);
+ const hash = this._computeMessageHash(this.message);
// Don't add the hash to the window history if it's already there.
// Otherwise you mess up expected back button behavior.
if (window.location.hash == hash) { return; }
@@ -186,7 +186,7 @@
page.show(window.location.pathname + hash, null, false);
},
- _handleReplyTap: function(e) {
+ _handleReplyTap(e) {
e.preventDefault();
this.fire('reply', {message: this.message});
},
diff --git a/polygerrit-ui/app/elements/change/gr-message/gr-message_test.html b/polygerrit-ui/app/elements/change/gr-message/gr-message_test.html
index 72c09d9..5f8b312 100644
--- a/polygerrit-ui/app/elements/change/gr-message/gr-message_test.html
+++ b/polygerrit-ui/app/elements/change/gr-message/gr-message_test.html
@@ -33,30 +33,30 @@
</test-fixture>
<script>
- suite('gr-message tests', function() {
- var element;
+ suite('gr-message tests', () => {
+ let element;
- setup(function() {
+ setup(() => {
stub('gr-rest-api-interface', {
- getLoggedIn: function() { return Promise.resolve(false); },
+ getLoggedIn() { return Promise.resolve(false); },
});
element = fixture('basic');
});
- test('reply event', function(done) {
+ test('reply event', done => {
element.message = {
- 'id': '47c43261_55aa2c41',
- 'author': {
- '_account_id': 1115495,
- 'name': 'Andrew Bonventre',
- 'email': 'andybons@chromium.org',
+ id: '47c43261_55aa2c41',
+ author: {
+ _account_id: 1115495,
+ name: 'Andrew Bonventre',
+ email: 'andybons@chromium.org',
},
- 'date': '2016-01-12 20:24:49.448000000',
- 'message': 'Uploaded patch set 1.',
- '_revision_number': 1
+ date: '2016-01-12 20:24:49.448000000',
+ message: 'Uploaded patch set 1.',
+ _revision_number: 1,
};
- element.addEventListener('reply', function(e) {
+ element.addEventListener('reply', e => {
assert.deepEqual(e.detail.message, element.message);
done();
});
@@ -64,38 +64,38 @@
MockInteractions.tap(element.$$('.replyContainer gr-button'));
});
- test('reviewer update', function() {
- var author = {
+ test('reviewer update', () => {
+ const author = {
_account_id: 1115495,
name: 'Andrew Bonventre',
email: 'andybons@chromium.org',
};
- var reviewer = {
+ const reviewer = {
_account_id: 123456,
name: 'Foo Bar',
email: 'barbar@chromium.org',
};
element.message = {
id: 0xDEADBEEF,
- author: author,
- reviewer: reviewer,
+ author,
+ reviewer,
date: '2016-01-12 20:24:49.448000000',
type: 'REVIEWER_UPDATE',
updates: [
{
message: 'Added to CC:',
reviewers: [reviewer],
- }
+ },
],
};
flushAsynchronousOperations();
- var content = element.$$('.contentContainer');
+ const content = element.$$('.contentContainer');
assert.isOk(content);
assert.strictEqual(element.$$('gr-account-chip').account, reviewer);
assert.equal(author.name, element.$$('.author > .name').textContent);
});
- test('autogenerated prefix hiding', function() {
+ test('autogenerated prefix hiding', () => {
element.message = {
tag: 'autogenerated:gerrit:test',
updated: '2016-01-12 20:24:49.448000000',
@@ -109,7 +109,7 @@
assert.isTrue(element.hidden);
});
- test('reviewer message treated as autogenerated', function() {
+ test('reviewer message treated as autogenerated', () => {
element.message = {
tag: 'autogenerated:gerrit:test',
updated: '2016-01-12 20:24:49.448000000',
@@ -124,7 +124,7 @@
assert.isTrue(element.hidden);
});
- test('tag that is not autogenerated prefix does not hide', function() {
+ test('tag that is not autogenerated prefix does not hide', () => {
element.message = {
tag: 'something',
updated: '2016-01-12 20:24:49.448000000',
@@ -138,16 +138,16 @@
assert.isFalse(element.hidden);
});
- test('reply button hidden unless logged in', function() {
- var message = {
- 'message': 'Uploaded patch set 1.',
+ test('reply button hidden unless logged in', () => {
+ const message = {
+ message: 'Uploaded patch set 1.',
};
assert.isFalse(element._computeShowReplyButton(message, false));
assert.isTrue(element._computeShowReplyButton(message, true));
});
- test('_computeShowOnBehalfOf', function() {
- var message = {
+ test('_computeShowOnBehalfOf', () => {
+ const message = {
message: '...',
};
assert.isNotOk(element._computeShowOnBehalfOf(message));
diff --git a/polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-changes-list.js b/polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-changes-list.js
index 8501b20..fe35c7f 100644
--- a/polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-changes-list.js
+++ b/polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-changes-list.js
@@ -41,23 +41,23 @@
},
_relatedResponse: {
type: Object,
- value: function() { return {changes: []}; },
+ value() { return {changes: []}; },
},
_submittedTogether: {
type: Array,
- value: function() { return []; },
+ value() { return []; },
},
_conflicts: {
type: Array,
- value: function() { return []; },
+ value() { return []; },
},
_cherryPicks: {
type: Array,
- value: function() { return []; },
+ value() { return []; },
},
_sameTopic: {
type: Array,
- value: function() { return []; },
+ value() { return []; },
},
},
@@ -71,53 +71,52 @@
'_conflicts, _cherryPicks, _sameTopic)',
],
- clear: function() {
+ clear() {
this.loading = true;
this.hidden = true;
},
- reload: function() {
+ reload() {
if (!this.change || !this.patchNum) {
return Promise.resolve();
}
this.loading = true;
- var promises = [
- this._getRelatedChanges().then(function(response) {
+ const promises = [
+ this._getRelatedChanges().then(response => {
this._relatedResponse = response;
this.hasParent = this._calculateHasParent(this.change.change_id,
response.changes);
-
- }.bind(this)),
- this._getSubmittedTogether().then(function(response) {
+ }),
+ this._getSubmittedTogether().then(response => {
this._submittedTogether = response;
- }.bind(this)),
- this._getCherryPicks().then(function(response) {
+ }),
+ this._getCherryPicks().then(response => {
this._cherryPicks = response;
- }.bind(this)),
+ }),
];
// Get conflicts if change is open and is mergeable.
if (this.changeIsOpen(this.change.status) && this.change.mergeable) {
- promises.push(this._getConflicts().then(function(response) {
+ promises.push(this._getConflicts().then(response => {
this._conflicts = response;
- }.bind(this)));
+ }));
}
- promises.push(this._getServerConfig().then(function(config) {
+ promises.push(this._getServerConfig().then(config => {
if (this.change.topic && !config.change.submit_whole_topic) {
- return this._getChangesWithSameTopic().then(function(response) {
+ return this._getChangesWithSameTopic().then(response => {
this._sameTopic = response;
- }.bind(this));
+ });
} else {
this._sameTopic = [];
}
return this._sameTopic;
- }.bind(this)));
+ }));
- return Promise.all(promises).then(function() {
+ return Promise.all(promises).then(() => {
this.loading = false;
- }.bind(this));
+ });
},
/**
@@ -128,62 +127,62 @@
* @param {Array} relatedChanges
* @return {Boolean}
*/
- _calculateHasParent: function(currentChangeId, relatedChanges) {
+ _calculateHasParent(currentChangeId, relatedChanges) {
return relatedChanges.length > 0 &&
relatedChanges[relatedChanges.length - 1].change_id !==
currentChangeId;
},
- _getRelatedChanges: function() {
+ _getRelatedChanges() {
return this.$.restAPI.getRelatedChanges(this.change._number,
this.patchNum);
},
- _getSubmittedTogether: function() {
+ _getSubmittedTogether() {
return this.$.restAPI.getChangesSubmittedTogether(this.change._number);
},
- _getServerConfig: function() {
+ _getServerConfig() {
return this.$.restAPI.getConfig();
},
- _getConflicts: function() {
+ _getConflicts() {
return this.$.restAPI.getChangeConflicts(this.change._number);
},
- _getCherryPicks: function() {
+ _getCherryPicks() {
return this.$.restAPI.getChangeCherryPicks(this.change.project,
this.change.change_id, this.change._number);
},
- _getChangesWithSameTopic: function() {
+ _getChangesWithSameTopic() {
return this.$.restAPI.getChangesWithSameTopic(this.change.topic);
},
- _computeChangeURL: function(changeNum, patchNum) {
- var urlStr = this.getBaseUrl() + '/c/' + changeNum;
+ _computeChangeURL(changeNum, patchNum) {
+ let urlStr = this.getBaseUrl() + '/c/' + changeNum;
if (patchNum != null) {
urlStr += '/' + patchNum;
}
return urlStr;
},
- _computeChangeContainerClass: function(currentChange, relatedChange) {
- var classes = ['changeContainer'];
+ _computeChangeContainerClass(currentChange, relatedChange) {
+ const classes = ['changeContainer'];
if (relatedChange.change_id === currentChange.change_id) {
classes.push('thisChange');
}
return classes.join(' ');
},
- _computeLinkClass: function(change) {
+ _computeLinkClass(change) {
if (change.status == this.ChangeStatus.ABANDONED) {
return 'strikethrough';
}
},
- _computeChangeStatusClass: function(change) {
- var classes = ['status'];
+ _computeChangeStatusClass(change) {
+ const classes = ['status'];
if (change._revision_number != change._current_revision_number) {
classes.push('notCurrent');
} else if (this._isIndirectAncestor(change)) {
@@ -196,7 +195,7 @@
return classes.join(' ');
},
- _computeChangeStatus: function(change) {
+ _computeChangeStatus(change) {
switch (change.status) {
case this.ChangeStatus.MERGED:
return 'Merged';
@@ -215,16 +214,16 @@
return '';
},
- _resultsChanged: function(related, submittedTogether, conflicts,
+ _resultsChanged(related, submittedTogether, conflicts,
cherryPicks, sameTopic) {
- var results = [
+ const results = [
related,
submittedTogether,
conflicts,
cherryPicks,
sameTopic,
];
- for (var i = 0; i < results.length; i++) {
+ for (let i = 0; i < results.length; i++) {
if (results[i].length > 0) {
this.hidden = false;
this.fire('update', null, {bubbles: false});
@@ -234,23 +233,23 @@
this.hidden = true;
},
- _isIndirectAncestor: function(change) {
- return this._connectedRevisions.indexOf(change.commit.commit) == -1;
+ _isIndirectAncestor(change) {
+ return !this._connectedRevisions.includes(change.commit.commit);
},
- _computeConnectedRevisions: function(change, patchNum, relatedChanges) {
- var connected = [];
- var changeRevision;
- for (var rev in change.revisions) {
+ _computeConnectedRevisions(change, patchNum, relatedChanges) {
+ const connected = [];
+ let changeRevision;
+ for (const rev in change.revisions) {
if (change.revisions[rev]._number == patchNum) {
changeRevision = rev;
}
}
- var commits = relatedChanges.map(function(c) { return c.commit; });
- var pos = commits.length - 1;
+ const commits = relatedChanges.map(c => { return c.commit; });
+ let pos = commits.length - 1;
while (pos >= 0) {
- var commit = commits[pos].commit;
+ const commit = commits[pos].commit;
connected.push(commit);
if (commit == changeRevision) {
break;
@@ -258,8 +257,8 @@
pos--;
}
while (pos >= 0) {
- for (var i = 0; i < commits[pos].parents.length; i++) {
- if (connected.indexOf(commits[pos].parents[i].commit) != -1) {
+ for (let i = 0; i < commits[pos].parents.length; i++) {
+ if (connected.includes(commits[pos].parents[i].commit)) {
connected.push(commits[pos].commit);
break;
}
diff --git a/polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-changes-list_test.html b/polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-changes-list_test.html
index 171f758..4a25405 100644
--- a/polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-changes-list_test.html
+++ b/polygerrit-ui/app/elements/change/gr-related-changes-list/gr-related-changes-list_test.html
@@ -33,21 +33,21 @@
</test-fixture>
<script>
- suite('gr-related-changes-list tests', function() {
- var element;
- var sandbox;
+ suite('gr-related-changes-list tests', () => {
+ let element;
+ let sandbox;
- setup(function() {
+ setup(() => {
element = fixture('basic');
sandbox = sinon.sandbox.create();
});
- teardown(function() {
+ teardown(() => {
sandbox.restore();
});
- test('connected revisions', function() {
- var change = {
+ test('connected revisions', () => {
+ const change = {
revisions: {
'e3c6d60783bfdec9ebae7dcfec4662360433449e': {
_number: 1,
@@ -72,8 +72,8 @@
},
},
};
- var patchNum = 7;
- var relatedChanges = [
+ let patchNum = 7;
+ let relatedChanges = [
{
commit: {
commit: '2cebeedfb1e80f4b872d0a13ade529e70652c0c8',
@@ -136,7 +136,7 @@
},
];
- var connectedChanges =
+ let connectedChanges =
element._computeConnectedRevisions(change, patchNum, relatedChanges);
assert.deepEqual(connectedChanges, [
'613bc4f81741a559c6667ac08d71dcc3348f73ce',
@@ -222,9 +222,9 @@
]);
});
- test('_computeChangeContainerClass', function() {
- var change1 = {change_id: 123};
- var change2 = {change_id: 456};
+ test('_computeChangeContainerClass', () => {
+ const change1 = {change_id: 123};
+ const change2 = {change_id: 456};
assert.notEqual(element._computeChangeContainerClass(
change1, change1).indexOf('thisChange'), -1);
@@ -232,26 +232,25 @@
change1, change2).indexOf('thisChange'), -1);
});
- suite('get conflicts tests', function() {
- var element;
- var conflictsStub;
+ suite('get conflicts tests', () => {
+ let element;
+ let conflictsStub;
- setup(function() {
+ setup(() => {
element = fixture('basic');
- sandbox.stub(element, '_getRelatedChanges',
- function() {
- return Promise.resolve({changes: []});
- });
+ sandbox.stub(element, '_getRelatedChanges', () => {
+ return Promise.resolve({changes: []});
+ });
sandbox.stub(element, '_getSubmittedTogether',
- function() { return Promise.resolve(); });
+ () => { return Promise.resolve(); });
sandbox.stub(element, '_getCherryPicks',
- function() { return Promise.resolve(); });
+ () => { return Promise.resolve(); });
conflictsStub = sandbox.stub(element, '_getConflicts',
- function() { return Promise.resolve(['test data']); });
+ () => { return Promise.resolve(['test data']); });
});
- test('request conflicts if open and mergeable', function() {
+ test('request conflicts if open and mergeable', () => {
element.patchNum = 7;
element.change = {
change_id: 123,
@@ -262,7 +261,7 @@
assert.isTrue(conflictsStub.called);
});
- test('does not request conflicts if closed and mergeable', function() {
+ test('does not request conflicts if closed and mergeable', () => {
element.patchNum = 7;
element.change = {
change_id: 123,
@@ -273,7 +272,7 @@
assert.isFalse(conflictsStub.called);
});
- test('does not request conflicts if open and not mergeable', function() {
+ test('does not request conflicts if open and not mergeable', () => {
element.patchNum = 7;
element.change = {
change_id: 123,
@@ -284,7 +283,7 @@
assert.isFalse(conflictsStub.called);
});
- test('doesnt request conflicts if closed and not mergeable', function() {
+ test('doesnt request conflicts if closed and not mergeable', () => {
element.patchNum = 7;
element.change = {
change_id: 123,
@@ -296,9 +295,9 @@
});
});
- test('_calculateHasParent', function() {
- var changeId = 123;
- var relatedChanges = [];
+ test('_calculateHasParent', () => {
+ const changeId = 123;
+ const relatedChanges = [];
assert.equal(element._calculateHasParent(changeId, relatedChanges),
false);
@@ -310,10 +309,9 @@
relatedChanges.push({change_id: 234});
assert.equal(element._calculateHasParent(changeId, relatedChanges),
true);
-
});
- test('clear hides', function() {
+ test('clear hides', () => {
element.loading = false;
element.hidden = false;
element.clear();
@@ -321,8 +319,8 @@
assert.isTrue(element.hidden);
});
- test('update fires', function() {
- var updateHandler = sandbox.stub();
+ test('update fires', () => {
+ const updateHandler = sandbox.stub();
element.addEventListener('update', updateHandler);
element._resultsChanged([], [], [], [], []);
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-comment-thread-group/gr-diff-comment-thread-group.js b/polygerrit-ui/app/elements/diff/gr-diff-comment-thread-group/gr-diff-comment-thread-group.js
index df75d52..7899fc7 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-comment-thread-group/gr-diff-comment-thread-group.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-comment-thread-group/gr-diff-comment-thread-group.js
@@ -21,7 +21,7 @@
changeNum: String,
comments: {
type: Array,
- value: function() { return []; },
+ value() { return []; },
},
patchForNewThreads: String,
projectConfig: Object,
@@ -32,7 +32,7 @@
},
_threads: {
type: Array,
- value: function() { return []; },
+ value() { return []; },
},
},
@@ -40,16 +40,16 @@
'_commentsChanged(comments.*)',
],
- addNewThread: function(locationRange) {
+ addNewThread(locationRange) {
this.push('_threads', {
comments: [],
- locationRange: locationRange,
+ locationRange,
patchNum: this.patchForNewThreads,
});
},
- removeThread: function(locationRange) {
- for (var i = 0; i < this._threads.length; i++) {
+ removeThread(locationRange) {
+ for (let i = 0; i < this._threads.length; i++) {
if (this._threads[i].locationRange === locationRange) {
this.splice('_threads', i, 1);
return;
@@ -57,10 +57,10 @@
}
},
- getThreadForRange: function(rangeToCheck) {
- var threads = [].filter.call(
+ getThreadForRange(rangeToCheck) {
+ const threads = [].filter.call(
Polymer.dom(this.root).querySelectorAll('gr-diff-comment-thread'),
- function(thread) {
+ thread => {
return thread.locationRange === rangeToCheck;
});
if (threads.length === 1) {
@@ -68,13 +68,13 @@
}
},
- _commentsChanged: function() {
+ _commentsChanged() {
this._threads = this._getThreadGroups(this.comments);
},
- _sortByDate: function(threadGroups) {
+ _sortByDate(threadGroups) {
if (!threadGroups.length) { return; }
- return threadGroups.sort(function(a, b) {
+ return threadGroups.sort((a, b) => {
// If a comment is a draft, it doesn't have a start_datetime yet.
// Assume it is newer than the comment it is being compared to.
if (!a.start_datetime) {
@@ -88,7 +88,7 @@
});
},
- _calculateLocationRange: function(range, comment) {
+ _calculateLocationRange(range, comment) {
return 'range-' + range.start_line + '-' +
range.start_character + '-' +
range.end_line + '-' +
@@ -102,15 +102,15 @@
* This is needed for switching between side-by-side and unified views when
* there are unsaved drafts.
*/
- _getPatchNum: function(comment) {
+ _getPatchNum(comment) {
return comment.patchNum || this.patchForNewThreads;
},
- _getThreadGroups: function(comments) {
- var threadGroups = {};
+ _getThreadGroups(comments) {
+ const threadGroups = {};
- comments.forEach(function(comment) {
- var locationRange;
+ for (const comment of comments) {
+ let locationRange;
if (!comment.range) {
locationRange = 'line-' + comment.__commentSide;
} else {
@@ -123,18 +123,18 @@
threadGroups[locationRange] = {
start_datetime: comment.updated,
comments: [comment],
- locationRange: locationRange,
+ locationRange,
commentSide: comment.__commentSide,
patchNum: this._getPatchNum(comment),
};
}
- }.bind(this));
+ }
- var threadGroupArr = [];
- var threadGroupKeys = Object.keys(threadGroups);
- threadGroupKeys.forEach(function(threadGroupKey) {
+ const threadGroupArr = [];
+ const threadGroupKeys = Object.keys(threadGroups);
+ for (const threadGroupKey of threadGroupKeys) {
threadGroupArr.push(threadGroups[threadGroupKey]);
- });
+ }
return this._sortByDate(threadGroupArr);
},
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-comment-thread-group/gr-diff-comment-thread-group_test.html b/polygerrit-ui/app/elements/diff/gr-diff-comment-thread-group/gr-diff-comment-thread-group_test.html
index 53a8e81..056b74f 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-comment-thread-group/gr-diff-comment-thread-group_test.html
+++ b/polygerrit-ui/app/elements/diff/gr-diff-comment-thread-group/gr-diff-comment-thread-group_test.html
@@ -34,25 +34,25 @@
</test-fixture>
<script>
- suite('gr-diff-comment-thread-group tests', function() {
- var element;
- var sandbox;
+ suite('gr-diff-comment-thread-group tests', () => {
+ let element;
+ let sandbox;
- setup(function() {
+ setup(() => {
sandbox = sinon.sandbox.create();
stub('gr-rest-api-interface', {
- getLoggedIn: function() { return Promise.resolve(false); },
+ getLoggedIn() { return Promise.resolve(false); },
});
element = fixture('basic');
});
- teardown(function() {
+ teardown(() => {
sandbox.restore();
});
- test('_getThreadGroups', function() {
+ test('_getThreadGroups', () => {
element.patchForNewThreads = 3;
- var comments = [
+ const comments = [
{
id: 'sallys_confession',
message: 'i like you, jack',
@@ -66,23 +66,23 @@
},
];
- var expectedThreadGroups = [
+ let expectedThreadGroups = [
{
start_datetime: '2015-12-23 15:00:20.396000000',
commentSide: 'left',
comments: [{
- id: 'sallys_confession',
- message: 'i like you, jack',
- updated: '2015-12-23 15:00:20.396000000',
- __commentSide: 'left',
- }, {
- id: 'jacks_reply',
- message: 'i like you, too',
- updated: '2015-12-24 15:00:20.396000000',
- __commentSide: 'left',
- }],
+ id: 'sallys_confession',
+ message: 'i like you, jack',
+ updated: '2015-12-23 15:00:20.396000000',
+ __commentSide: 'left',
+ }, {
+ id: 'jacks_reply',
+ message: 'i like you, too',
+ updated: '2015-12-24 15:00:20.396000000',
+ __commentSide: 'left',
+ }],
locationRange: 'line-left',
- patchNum: 3
+ patchNum: 3,
},
];
@@ -91,33 +91,33 @@
// Patch num should get inherited from comment rather
comments.push({
- id: 'betsys_confession',
- message: 'i like you, jack',
- updated: '2015-12-24 15:00:10.396000000',
- range: {
- start_line: 1,
- start_character: 1,
- end_line: 1,
- end_character: 2,
- },
- __commentSide: 'left',
- });
+ id: 'betsys_confession',
+ message: 'i like you, jack',
+ updated: '2015-12-24 15:00:10.396000000',
+ range: {
+ start_line: 1,
+ start_character: 1,
+ end_line: 1,
+ end_character: 2,
+ },
+ __commentSide: 'left',
+ });
expectedThreadGroups = [
{
start_datetime: '2015-12-23 15:00:20.396000000',
commentSide: 'left',
comments: [{
- id: 'sallys_confession',
- message: 'i like you, jack',
- updated: '2015-12-23 15:00:20.396000000',
- __commentSide: 'left',
- }, {
- id: 'jacks_reply',
- message: 'i like you, too',
- updated: '2015-12-24 15:00:20.396000000',
- __commentSide: 'left',
- }],
+ id: 'sallys_confession',
+ message: 'i like you, jack',
+ updated: '2015-12-23 15:00:20.396000000',
+ __commentSide: 'left',
+ }, {
+ id: 'jacks_reply',
+ message: 'i like you, too',
+ updated: '2015-12-24 15:00:20.396000000',
+ __commentSide: 'left',
+ }],
patchNum: 3,
locationRange: 'line-left',
},
@@ -145,8 +145,8 @@
expectedThreadGroups);
});
- test('_sortByDate', function() {
- var threadGroups = [
+ test('_sortByDate', () => {
+ let threadGroups = [
{
start_datetime: '2015-12-23 15:00:20.396000000',
comments: [],
@@ -159,12 +159,12 @@
},
];
- var expectedResult = [
+ let expectedResult = [
{
start_datetime: '2015-12-22 15:00:10.396000000',
comments: [],
locationRange: 'range-1-1-1-2',
- },{
+ }, {
start_datetime: '2015-12-23 15:00:20.396000000',
comments: [],
locationRange: 'line',
@@ -175,7 +175,7 @@
// When a comment doesn't have a date, the one without the date should be
// last.
- var threadGroups = [
+ threadGroups = [
{
start_datetime: '2015-12-23 15:00:20.396000000',
comments: [],
@@ -187,7 +187,7 @@
},
];
- var expectedResult = [
+ expectedResult = [
{
start_datetime: '2015-12-23 15:00:20.396000000',
comments: [],
@@ -198,22 +198,25 @@
locationRange: 'range-1-1-1-2',
},
];
+
+ assert.deepEqual(element._sortByDate(threadGroups), expectedResult);
});
- test('_calculateLocationRange', function() {
- var comment = {__commentSide: 'left'};
- var range = {
+ test('_calculateLocationRange', () => {
+ const comment = {__commentSide: 'left'};
+ const range = {
start_line: 1,
start_character: 2,
end_line: 3,
end_character: 4,
};
assert.equal(
- element._calculateLocationRange(range, comment), 'range-1-2-3-4-left');
+ element._calculateLocationRange(range, comment),
+ 'range-1-2-3-4-left');
});
- test('thread groups are updated when comments change', function() {
- var commentsChangedStub = sandbox.stub(element, '_commentsChanged');
+ test('thread groups are updated when comments change', () => {
+ const commentsChangedStub = sandbox.stub(element, '_commentsChanged');
element.comments = [];
element.comments.push({
id: 'sallys_confession',
@@ -223,16 +226,16 @@
assert(commentsChangedStub.called);
});
- test('addNewThread', function() {
- var locationRange = 'range-1-2-3-4';
+ test('addNewThread', () => {
+ const locationRange = 'range-1-2-3-4';
element._threads = [{locationRange: 'line'}];
element.addNewThread(locationRange);
assert(element._threads.length, 2);
});
- test('_getPatchNum', function() {
+ test('_getPatchNum', () => {
element.patchForNewThreads = 3;
- var comment = {
+ const comment = {
id: 'sallys_confession',
message: 'i like you, jack',
updated: '2015-12-23 15:00:20.396000000',
@@ -242,11 +245,11 @@
assert.equal(element._getPatchNum(comment), 4);
});
- test('removeThread', function() {
- var locationRange = 'range-1-2-3-4';
+ test('removeThread', () => {
+ const locationRange = 'range-1-2-3-4';
element._threads = [
{locationRange: 'range-1-2-3-4', comments: []},
- {locationRange: 'line', comments: []}
+ {locationRange: 'line', comments: []},
];
flushAsynchronousOperations();
element.removeThread(locationRange);
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.js b/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.js
index 0791193..ea6347f 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.js
@@ -173,6 +173,9 @@
},
_eraseDraftComment: function() {
+ // Prevents a race condition in which removing the draft comment occurs
+ // prior to it being saved.
+ this.cancelDebouncer('store');
this.$.storage.eraseDraftComment({
changeNum: this.changeNum,
patchNum: this._getPatchNum(),
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment_test.html b/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment_test.html
index 919a64f..bcac6b3 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment_test.html
+++ b/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment_test.html
@@ -476,6 +476,7 @@
test('draft saving/editing', function(done) {
var fireStub = sinon.stub(element, 'fire');
+ let cancelDebounce = sandbox.stub(element, 'cancelDebouncer');
element.draft = true;
MockInteractions.tap(element.$$('.edit'));
@@ -507,6 +508,7 @@
element._xhrPromise.then(function(draft) {
assert(fireStub.calledWith('comment-save'),
'comment-save should be sent');
+ assert(cancelDebounce.calledWith('store'));
assert.deepEqual(fireStub.lastCall.args[1], {
comment: {
__commentSide: 'right',
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-preferences/gr-diff-preferences.js b/polygerrit-ui/app/elements/diff/gr-diff-preferences/gr-diff-preferences.js
index e29f8ef..20833d0 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-preferences/gr-diff-preferences.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-preferences/gr-diff-preferences.js
@@ -41,20 +41,19 @@
'_localPrefsChanged(localPrefs.*)',
],
- getFocusStops: function() {
+ getFocusStops() {
return {
start: this.$.contextSelect,
end: this.$.cancelButton,
};
},
- resetFocus: function() {
+ resetFocus() {
this.$.contextSelect.focus();
},
- _prefsChanged: function(changeRecord) {
- var prefs = changeRecord.base;
- // TODO(andybons): This is not supported in IE. Implement a polyfill.
+ _prefsChanged(changeRecord) {
+ const prefs = changeRecord.base;
// NOTE: Object.assign is NOT automatically a deep copy. If prefs adds
// an object as a value, it must be marked enumerable.
this._newPrefs = Object.assign({}, prefs);
@@ -65,71 +64,70 @@
this.$.syntaxHighlightInput.checked = prefs.syntax_highlighting;
},
- _localPrefsChanged: function(changeRecord) {
- var localPrefs = changeRecord.base || {};
- // TODO(viktard): This is not supported in IE. Implement a polyfill.
+ _localPrefsChanged(changeRecord) {
+ const localPrefs = changeRecord.base || {};
this._newLocalPrefs = Object.assign({}, localPrefs);
},
- _handleContextSelectChange: function(e) {
- var selectEl = Polymer.dom(e).rootTarget;
+ _handleContextSelectChange(e) {
+ const selectEl = Polymer.dom(e).rootTarget;
this.set('_newPrefs.context', parseInt(selectEl.value, 10));
},
- _handleShowTabsTap: function(e) {
+ _handleShowTabsTap(e) {
this.set('_newPrefs.show_tabs', Polymer.dom(e).rootTarget.checked);
},
- _handleShowTrailingWhitespaceTap: function(e) {
+ _handleShowTrailingWhitespaceTap(e) {
this.set('_newPrefs.show_whitespace_errors',
Polymer.dom(e).rootTarget.checked);
},
- _handleSyntaxHighlightTap: function(e) {
+ _handleSyntaxHighlightTap(e) {
this.set('_newPrefs.syntax_highlighting',
Polymer.dom(e).rootTarget.checked);
},
- _handlelineWrappingTap: function(e) {
+ _handlelineWrappingTap(e) {
this.set('_newPrefs.line_wrapping', Polymer.dom(e).rootTarget.checked);
},
- _handleSave: function(e) {
+ _handleSave(e) {
e.stopPropagation();
this.prefs = this._newPrefs;
this.localPrefs = this._newLocalPrefs;
- var el = Polymer.dom(e).rootTarget;
+ const el = Polymer.dom(e).rootTarget;
el.disabled = true;
this.$.storage.savePreferences(this._localPrefs);
- this._saveDiffPreferences().then(function(response) {
+ this._saveDiffPreferences().then(response => {
el.disabled = false;
if (!response.ok) { return response; }
this.$.prefsOverlay.close();
- }.bind(this)).catch(function(err) {
+ }).catch(err => {
el.disabled = false;
- }.bind(this));
+ });
},
- _handleCancel: function(e) {
+ _handleCancel(e) {
e.stopPropagation();
this.$.prefsOverlay.close();
},
- _handlePrefsTap: function(e) {
+ _handlePrefsTap(e) {
e.preventDefault();
this._openPrefs();
},
- open: function() {
- this.$.prefsOverlay.open().then(function() {
- var focusStops = this.getFocusStops();
+ open() {
+ this.$.prefsOverlay.open().then(() => {
+ const focusStops = this.getFocusStops();
this.$.prefsOverlay.setFocusStops(focusStops);
this.resetFocus();
- }.bind(this));
+ });
},
- _saveDiffPreferences: function() {
+ _saveDiffPreferences() {
return this.$.restAPI.saveDiffPreferences(this.prefs);
},
});
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-preferences/gr-diff-preferences_test.html b/polygerrit-ui/app/elements/diff/gr-diff-preferences/gr-diff-preferences_test.html
index b163c71..d201edf 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-preferences/gr-diff-preferences_test.html
+++ b/polygerrit-ui/app/elements/diff/gr-diff-preferences/gr-diff-preferences_test.html
@@ -33,20 +33,20 @@
</test-fixture>
<script>
- suite('gr-diff-preferences tests', function() {
- var element;
- var sandbox;
+ suite('gr-diff-preferences tests', () => {
+ let element;
+ let sandbox;
- setup(function() {
+ setup(() => {
sandbox = sinon.sandbox.create();
element = fixture('basic');
});
- teardown(function() {
+ teardown(() => {
sandbox.restore();
});
- test('model changes', function() {
+ test('model changes', () => {
element.prefs = {
context: 10,
font_size: 12,
@@ -78,7 +78,7 @@
assert.isFalse(element._newPrefs.syntax_highlighting);
});
- test('clicking fit to screen hides line length input', function() {
+ test('clicking fit to screen hides line length input', () => {
element.prefs = {line_wrapping: false};
assert.isFalse(element.$.columnsPref.hidden);
@@ -90,31 +90,31 @@
assert.isFalse(element.$.columnsPref.hidden);
});
- test('clicking save button calls _handleSave function', function() {
- var savePrefs = sinon.stub(element, '_handleSave');
+ test('clicking save button calls _handleSave function', () => {
+ const savePrefs = sinon.stub(element, '_handleSave');
MockInteractions.tap(element.$.saveButton);
flushAsynchronousOperations();
assert(savePrefs.calledOnce);
savePrefs.restore();
});
- test('save button', function() {
+ test('save button', () => {
element.prefs = {
font_size: '11',
};
element._newPrefs = {
font_size: '12',
};
- var saveStub = sandbox.stub(element.$.restAPI, 'saveDiffPreferences',
- function() { return Promise.resolve(); });
+ const saveStub = sandbox.stub(element.$.restAPI, 'saveDiffPreferences',
+ () => { return Promise.resolve(); });
MockInteractions.tap(element.$$('gr-button[primary]'));
assert.deepEqual(element.prefs, element._newPrefs);
assert.deepEqual(saveStub.lastCall.args[0], element._newPrefs);
});
- test('cancel button', function() {
- var closeStub = sandbox.stub(element.$.prefsOverlay, 'close');
+ test('cancel button', () => {
+ const closeStub = sandbox.stub(element.$.prefsOverlay, 'close');
MockInteractions.tap(element.$$('gr-button:not([primary])'));
assert.isTrue(closeStub.called);
});
diff --git a/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select.js b/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select.js
index 58d29bd..e9437bd 100644
--- a/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select.js
+++ b/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select.js
@@ -15,7 +15,7 @@
'use strict';
// Maximum length for patch set descriptions.
- var PATCH_DESC_MAX_LENGTH = 500;
+ const PATCH_DESC_MAX_LENGTH = 500;
Polymer({
is: 'gr-patch-range-select',
@@ -36,15 +36,15 @@
behaviors: [Gerrit.PatchSetBehavior],
- _updateSelected: function() {
+ _updateSelected() {
this._rightSelected = this.patchRange.patchNum;
this._leftSelected = this.patchRange.basePatchNum;
},
- _handlePatchChange: function(e) {
- var leftPatch = this._leftSelected;
- var rightPatch = this._rightSelected;
- var rangeStr = rightPatch;
+ _handlePatchChange(e) {
+ const leftPatch = this._leftSelected;
+ const rightPatch = this._rightSelected;
+ let rangeStr = rightPatch;
if (leftPatch != 'PARENT') {
rangeStr = leftPatch + '..' + rangeStr;
}
@@ -52,11 +52,11 @@
e.target.blur();
},
- _computeLeftDisabled: function(patchNum, patchRange) {
+ _computeLeftDisabled(patchNum, patchRange) {
return parseInt(patchNum, 10) >= parseInt(patchRange.patchNum, 10);
},
- _computeRightDisabled: function(patchNum, patchRange) {
+ _computeRightDisabled(patchNum, patchRange) {
if (patchRange.basePatchNum == 'PARENT') { return false; }
return parseInt(patchNum, 10) <= parseInt(patchRange.basePatchNum, 10);
},
@@ -66,16 +66,16 @@
// are loaded, the correct value will get selected. I attempted to
// debounce these, but because they are detecting two different
// events, sometimes the timing was off and one ended up missing.
- _synchronizeSelectionRight: function() {
+ _synchronizeSelectionRight() {
this.$.rightPatchSelect.value = this._rightSelected;
},
- _synchronizeSelectionLeft: function() {
+ _synchronizeSelectionLeft() {
this.$.leftPatchSelect.value = this._leftSelected;
},
- _computePatchSetDescription: function(revisions, patchNum) {
- var rev = this.getRevisionByPatchNum(revisions, patchNum);
+ _computePatchSetDescription(revisions, patchNum) {
+ const rev = this.getRevisionByPatchNum(revisions, patchNum);
return (rev && rev.description) ?
rev.description.substring(0, PATCH_DESC_MAX_LENGTH) : '';
},
diff --git a/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select_test.html b/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select_test.html
index 00d73bf..0195eac 100644
--- a/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select_test.html
+++ b/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select_test.html
@@ -34,24 +34,24 @@
</test-fixture>
<script>
- suite('gr-patch-range-select tests', function() {
- var element;
+ suite('gr-patch-range-select tests', () => {
+ let element;
- setup(function() {
+ setup(() => {
element = fixture('basic');
});
- test('enabled/disabled options', function() {
- var patchRange = {
+ test('enabled/disabled options', () => {
+ const patchRange = {
basePatchNum: 'PARENT',
patchNum: '3',
};
- ['1', '2', '3'].forEach(function(patchNum) {
+ for (const patchNum of ['1', '2', '3']) {
assert.isFalse(element._computeRightDisabled(patchNum, patchRange));
- });
- ['PARENT', '1', '2'].forEach(function(patchNum) {
+ }
+ for (const patchNum of ['PARENT', '1', '2']) {
assert.isFalse(element._computeLeftDisabled(patchNum, patchRange));
- });
+ }
assert.isTrue(element._computeLeftDisabled('3', patchRange));
patchRange.basePatchNum = '2';
@@ -61,11 +61,11 @@
assert.isFalse(element._computeRightDisabled('3', patchRange));
});
- test('navigation', function(done) {
- var showStub = sinon.stub(page, 'show');
- var leftSelectEl = element.$.leftPatchSelect;
- var rightSelectEl = element.$.rightPatchSelect;
- var blurSpy = sinon.spy(leftSelectEl, 'blur');
+ test('navigation', done => {
+ const showStub = sinon.stub(page, 'show');
+ const leftSelectEl = element.$.leftPatchSelect;
+ const rightSelectEl = element.$.rightPatchSelect;
+ const blurSpy = sinon.spy(leftSelectEl, 'blur');
element.changeNum = '42';
element.path = 'path/to/file.txt';
element.availablePatches = ['1', '2', '3'];
@@ -75,8 +75,8 @@
};
flushAsynchronousOperations();
- var numEvents = 0;
- leftSelectEl.addEventListener('change', function(e) {
+ let numEvents = 0;
+ leftSelectEl.addEventListener('change', e => {
numEvents++;
if (numEvents == 1) {
assert(showStub.lastCall.calledWithExactly(
@@ -98,23 +98,23 @@
element.fire('change', {}, {node: leftSelectEl});
});
- test('filesWeblinks', function() {
+ test('filesWeblinks', () => {
element.filesWeblinks = {
meta_a: [
{
name: 'foo',
url: 'f.oo',
- }
+ },
],
meta_b: [
{
name: 'bar',
url: 'ba.r',
- }
+ },
],
};
flushAsynchronousOperations();
- var domApi = Polymer.dom(element.root);
+ const domApi = Polymer.dom(element.root);
assert.equal(
domApi.querySelector('a[href="f.oo"]').textContent, 'foo');
assert.equal(
diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-actions-js-api.js b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-actions-js-api.js
index 9bcde07..99c4fed 100644
--- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-actions-js-api.js
+++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-actions-js-api.js
@@ -22,13 +22,13 @@
}
GrChangeActionsInterface.prototype.addPrimaryActionKey = function(key) {
- if (this._el.primaryActionKeys.indexOf(key) !== -1) { return; }
+ if (this._el.primaryActionKeys.includes(key)) { return; }
this._el.push('primaryActionKeys', key);
};
GrChangeActionsInterface.prototype.removePrimaryActionKey = function(key) {
- this._el.primaryActionKeys = this._el.primaryActionKeys.filter(function(k) {
+ this._el.primaryActionKeys = this._el.primaryActionKeys.filter(k => {
return k !== key;
});
};
diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-actions-js-api_test.html b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-actions-js-api_test.html
index d964cde..24fee39 100644
--- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-actions-js-api_test.html
+++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-actions-js-api_test.html
@@ -37,43 +37,44 @@
</test-fixture>
<script>
- suite('gr-js-api-interface tests', function() {
- var element;
- var changeActions;
+ suite('gr-js-api-interface tests', () => {
+ let element;
+ let changeActions;
// Because deepEqual doesn’t behave in Safari.
function assertArraysEqual(actual, expected) {
assert.equal(actual.length, expected.length);
- for (var i = 0; i < actual.length; i++) {
+ for (let i = 0; i < actual.length; i++) {
assert.equal(actual[i], expected[i]);
}
}
- setup(function() {
+ setup(() => {
element = fixture('basic');
element.change = {};
element._hasKnownChainState = false;
- var plugin;
- Gerrit.install(function(p) { plugin = p; }, '0.1',
+ let plugin;
+ Gerrit.install(p => { plugin = p; }, '0.1',
'http://test.com/plugins/testplugin/static/test.js');
changeActions = plugin.changeActions();
});
- teardown(function() {
+ teardown(() => {
changeActions = null;
});
- test('property existence', function() {
- [
+ test('property existence', () => {
+ const properties = [
'ActionType',
'ChangeActions',
'RevisionActions',
- ].forEach(function(p) {
+ ];
+ for (const p of properties) {
assertArraysEqual(changeActions[p], element[p]);
- });
+ }
});
- test('add/remove primary action keys', function() {
+ test('add/remove primary action keys', () => {
element.primaryActionKeys = [];
changeActions.addPrimaryActionKey('foo');
assertArraysEqual(element.primaryActionKeys, ['foo']);
@@ -89,34 +90,34 @@
assertArraysEqual(element.primaryActionKeys, []);
});
- test('action buttons', function(done) {
- var key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
- var handler = sinon.spy();
+ test('action buttons', done => {
+ const key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
+ const handler = sinon.spy();
changeActions.addTapListener(key, handler);
- flush(function() {
+ flush(() => {
MockInteractions.tap(element.$$('[data-action-key="' + key + '"]'));
assert(handler.calledOnce);
changeActions.removeTapListener(key, handler);
MockInteractions.tap(element.$$('[data-action-key="' + key + '"]'));
assert(handler.calledOnce);
changeActions.remove(key);
- flush(function() {
+ flush(() => {
assert.isNull(element.$$('[data-action-key="' + key + '"]'));
done();
});
});
});
- test('action button properties', function(done) {
- var key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
- flush(function() {
- var button = element.$$('[data-action-key="' + key + '"]');
+ test('action button properties', done => {
+ const key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
+ flush(() => {
+ const button = element.$$('[data-action-key="' + key + '"]');
assert.isOk(button);
assert.equal(button.getAttribute('data-label'), 'Bork!');
assert.isNotOk(button.disabled);
changeActions.setLabel(key, 'Yo');
changeActions.setEnabled(key, false);
- flush(function() {
+ flush(() => {
assert.equal(button.getAttribute('data-label'), 'Yo');
assert.isTrue(button.disabled);
done();
@@ -124,30 +125,30 @@
});
});
- test('hide action buttons', function(done) {
- var key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
- flush(function() {
- var button = element.$$('[data-action-key="' + key + '"]');
+ test('hide action buttons', done => {
+ const key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
+ flush(() => {
+ const button = element.$$('[data-action-key="' + key + '"]');
assert.isOk(button);
assert.isFalse(button.hasAttribute('hidden'));
changeActions.setActionHidden(
changeActions.ActionType.REVISION, key, true);
- flush(function() {
- var button = element.$$('[data-action-key="' + key + '"]');
+ flush(() => {
+ const button = element.$$('[data-action-key="' + key + '"]');
assert.isNotOk(button);
done();
});
});
});
- test('move action button to overflow', function(done) {
- var key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
- flush(function() {
+ test('move action button to overflow', done => {
+ const key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
+ flush(() => {
assert.isTrue(element.$.moreActions.hidden);
assert.isOk(element.$$('[data-action-key="' + key + '"]'));
changeActions.setActionOverflow(
changeActions.ActionType.REVISION, key, true);
- flush(function() {
+ flush(() => {
assert.isNotOk(element.$$('[data-action-key="' + key + '"]'));
assert.isFalse(element.$.moreActions.hidden);
assert.strictEqual(element.$.moreActions.items[0].name, 'Bork!');
@@ -156,17 +157,19 @@
});
});
- test('change actions priority', function(done) {
- var key1 = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
- var key2 = changeActions.add(changeActions.ActionType.CHANGE, 'Squanch?');
- flush(function() {
- var buttons =
+ test('change actions priority', done => {
+ const key1 =
+ changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
+ const key2 =
+ changeActions.add(changeActions.ActionType.CHANGE, 'Squanch?');
+ flush(() => {
+ let buttons =
Polymer.dom(element.root).querySelectorAll('[data-action-key]');
assert.equal(buttons[0].getAttribute('data-action-key'), key1);
assert.equal(buttons[1].getAttribute('data-action-key'), key2);
changeActions.setActionPriority(
changeActions.ActionType.REVISION, key1, 10);
- flush(function() {
+ flush(() => {
buttons =
Polymer.dom(element.root).querySelectorAll('[data-action-key]');
assert.equal(buttons[0].getAttribute('data-action-key'), key2);
diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-reply-js-api_test.html b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-reply-js-api_test.html
index c2357cc..73f3479 100644
--- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-reply-js-api_test.html
+++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-reply-js-api_test.html
@@ -37,35 +37,35 @@
</test-fixture>
<script>
- suite('gr-change-reply-js-api tests', function() {
- var element;
- var sandbox;
- var changeReply;
+ suite('gr-change-reply-js-api tests', () => {
+ let element;
+ let sandbox;
+ let changeReply;
- setup(function() {
+ setup(() => {
stub('gr-rest-api-interface', {
- getConfig: function() { return Promise.resolve({}); },
- getAccount: function() { return Promise.resolve(null); },
+ getConfig() { return Promise.resolve({}); },
+ getAccount() { return Promise.resolve(null); },
});
element = fixture('basic');
sandbox = sinon.sandbox.create();
- var plugin;
- Gerrit.install(function(p) { plugin = p; }, '0.1',
+ let plugin;
+ Gerrit.install(p => { plugin = p; }, '0.1',
'http://test.com/plugins/testplugin/static/test.js');
changeReply = plugin.changeReply();
});
- teardown(function() {
+ teardown(() => {
changeReply = null;
sandbox.restore();
});
- test('calls', function() {
- var setLabelValueStub = sinon.stub(element, 'setLabelValue');
+ test('calls', () => {
+ const setLabelValueStub = sinon.stub(element, 'setLabelValue');
changeReply.setLabelValue('My-Label', '+1337');
assert(setLabelValueStub.calledWithExactly('My-Label', '+1337'));
- var sendStub = sinon.stub(element, 'send');
+ const sendStub = sinon.stub(element, 'send');
changeReply.send(false);
assert(sendStub.calledWithExactly(false));
});
diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface.js b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface.js
index 34ca728..70a9bf5 100644
--- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface.js
+++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface.js
@@ -14,7 +14,7 @@
(function() {
'use strict';
- var EventType = {
+ const EventType = {
HISTORY: 'history',
LABEL_CHANGE: 'labelchange',
SHOW_CHANGE: 'showchange',
@@ -25,7 +25,7 @@
POST_REVERT: 'postrevert',
};
- var Element = {
+ const Element = {
CHANGE_ACTIONS: 'changeactions',
REPLY_DIALOG: 'replydialog',
};
@@ -44,11 +44,11 @@
},
},
- Element: Element,
- EventType: EventType,
+ Element,
+ EventType,
- handleEvent: function(type, detail) {
- Gerrit.awaitPluginsLoaded().then(function() {
+ handleEvent(type, detail) {
+ Gerrit.awaitPluginsLoaded().then(() => {
switch (type) {
case EventType.HISTORY:
this._handleHistory(detail);
@@ -67,27 +67,27 @@
type);
break;
}
- }.bind(this));
+ });
},
- addElement: function(key, el) {
+ addElement(key, el) {
this._elements[key] = el;
},
- getElement: function(key) {
+ getElement(key) {
return this._elements[key];
},
- addEventCallback: function(eventName, callback) {
+ addEventCallback(eventName, callback) {
if (!this._eventCallbacks[eventName]) {
this._eventCallbacks[eventName] = [];
}
this._eventCallbacks[eventName].push(callback);
},
- canSubmitChange: function(change, revision) {
- var submitCallbacks = this._getEventCallbacks(EventType.SUBMIT_CHANGE);
- var cancelSubmit = submitCallbacks.some(function(callback) {
+ canSubmitChange(change, revision) {
+ const submitCallbacks = this._getEventCallbacks(EventType.SUBMIT_CHANGE);
+ const cancelSubmit = submitCallbacks.some(callback => {
try {
return callback(change, revision) === false;
} catch (err) {
@@ -99,28 +99,29 @@
return !cancelSubmit;
},
- _removeEventCallbacks: function() {
- for (var k in EventType) {
+ _removeEventCallbacks() {
+ for (const k in EventType) {
+ if (!EventType.hasOwnProperty(k)) { continue; }
this._eventCallbacks[EventType[k]] = [];
}
},
- _handleHistory: function(detail) {
- this._getEventCallbacks(EventType.HISTORY).forEach(function(cb) {
+ _handleHistory(detail) {
+ for (const cb of this._getEventCallbacks(EventType.HISTORY)) {
try {
cb(detail.path);
} catch (err) {
console.error(err);
}
- });
+ }
},
- _handleShowChange: function(detail) {
- this._getEventCallbacks(EventType.SHOW_CHANGE).forEach(function(cb) {
- var change = detail.change;
- var patchNum = detail.patchNum;
- var revision;
- for (var rev in change.revisions) {
+ _handleShowChange(detail) {
+ for (const cb of this._getEventCallbacks(EventType.SHOW_CHANGE)) {
+ const change = detail.change;
+ const patchNum = detail.patchNum;
+ let revision;
+ for (const rev in change.revisions) {
if (change.revisions[rev]._number == patchNum) {
revision = change.revisions[rev];
break;
@@ -131,67 +132,63 @@
} catch (err) {
console.error(err);
}
- });
+ }
},
- handleCommitMessage: function(change, msg) {
- this._getEventCallbacks(EventType.COMMIT_MSG_EDIT).forEach(
- function(cb) {
- try {
- cb(change, msg);
- } catch (err) {
- console.error(err);
- }
- }
- );
+ handleCommitMessage(change, msg) {
+ for (const cb of this._getEventCallbacks(EventType.COMMIT_MSG_EDIT)) {
+ try {
+ cb(change, msg);
+ } catch (err) {
+ console.error(err);
+ }
+ }
},
- _handleComment: function(detail) {
- this._getEventCallbacks(EventType.COMMENT).forEach(function(cb) {
+ _handleComment(detail) {
+ for (const cb of this._getEventCallbacks(EventType.COMMENT)) {
try {
cb(detail.node);
} catch (err) {
console.error(err);
}
- });
+ }
},
- _handleLabelChange: function(detail) {
- this._getEventCallbacks(EventType.LABEL_CHANGE).forEach(function(cb) {
+ _handleLabelChange(detail) {
+ for (const cb of this._getEventCallbacks(EventType.LABEL_CHANGE)) {
try {
cb(detail.change);
} catch (err) {
console.error(err);
}
- });
+ }
},
- modifyRevertMsg: function(change, revertMsg, origMsg) {
- this._getEventCallbacks(EventType.REVERT).forEach(function(callback) {
+ modifyRevertMsg(change, revertMsg, origMsg) {
+ for (const cb of this._getEventCallbacks(EventType.REVERT)) {
try {
- revertMsg = callback(change, revertMsg, origMsg);
+ revertMsg = cb(change, revertMsg, origMsg);
} catch (err) {
console.error(err);
}
- });
+ }
return revertMsg;
},
- getLabelValuesPostRevert: function(change) {
- var labels = {};
- this._getEventCallbacks(EventType.POST_REVERT).forEach(
- function(callback) {
- try {
- labels = callback(change);
- } catch (err) {
- console.error(err);
- }
- }
- );
+ getLabelValuesPostRevert(change) {
+ let labels = {};
+ for (const cb of this._getEventCallbacks(EventType.POST_REVERT)) {
+ try {
+ labels = cb(change);
+ } catch (err) {
+ console.error(err);
+ }
+ }
return labels;
},
- _getEventCallbacks: function(type) {
+ _getEventCallbacks(type) {
return this._eventCallbacks[type] || [];
},
});
diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface_test.html b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface_test.html
index d62bdd8..c3013bd 100644
--- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface_test.html
+++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface_test.html
@@ -31,45 +31,45 @@
</test-fixture>
<script>
- suite('gr-js-api-interface tests', function() {
- var element;
- var plugin;
- var errorStub;
- var sandbox;
+ suite('gr-js-api-interface tests', () => {
+ let element;
+ let plugin;
+ let errorStub;
+ let sandbox;
- var throwErrFn = function() {
+ const throwErrFn = function() {
throw Error('Unfortunately, this handler has stopped');
};
- setup(function() {
+ setup(() => {
sandbox = sinon.sandbox.create();
stub('gr-rest-api-interface', {
- getAccount: function() {
+ getAccount() {
return Promise.resolve({name: 'Judy Hopps'});
},
});
element = fixture('basic');
errorStub = sandbox.stub(console, 'error');
Gerrit._setPluginsCount(1);
- Gerrit.install(function(p) { plugin = p; }, '0.1',
+ Gerrit.install(p => { plugin = p; }, '0.1',
'http://test.com/plugins/testplugin/static/test.js');
});
- teardown(function() {
+ teardown(() => {
sandbox.restore();
element._removeEventCallbacks();
plugin = null;
});
- test('url', function() {
+ test('url', () => {
assert.equal(plugin.url(), 'http://test.com/plugins/testplugin/');
assert.equal(plugin.url('/static/test.js'),
'http://test.com/plugins/testplugin/static/test.js');
});
- test('history event', function(done) {
+ test('history event', done => {
plugin.on(element.EventType.HISTORY, throwErrFn);
- plugin.on(element.EventType.HISTORY, function(path) {
+ plugin.on(element.EventType.HISTORY, path => {
assert.equal(path, '/path/to/awesomesauce');
assert.isTrue(errorStub.calledOnce);
done();
@@ -78,13 +78,13 @@
{path: '/path/to/awesomesauce'});
});
- test('showchange event', function(done) {
- var testChange = {
+ test('showchange event', done => {
+ const testChange = {
_number: 42,
revisions: {def: {_number: 2}, abc: {_number: 1}},
};
plugin.on(element.EventType.SHOW_CHANGE, throwErrFn);
- plugin.on(element.EventType.SHOW_CHANGE, function(change, revision) {
+ plugin.on(element.EventType.SHOW_CHANGE, (change, revision) => {
assert.deepEqual(change, testChange);
assert.deepEqual(revision, testChange.revisions.abc);
assert.isTrue(errorStub.calledOnce);
@@ -94,28 +94,28 @@
{change: testChange, patchNum: 1});
});
- test('handleEvent awaits plugins load', function(done) {
- var testChange = {
+ test('handleEvent awaits plugins load', done => {
+ const testChange = {
_number: 42,
revisions: {def: {_number: 2}, abc: {_number: 1}},
};
- var spy = sandbox.spy();
+ const spy = sandbox.spy();
Gerrit._setPluginsCount(1);
plugin.on(element.EventType.SHOW_CHANGE, spy);
element.handleEvent(element.EventType.SHOW_CHANGE,
{change: testChange, patchNum: 1});
assert.isFalse(spy.called);
Gerrit._setPluginsCount(0);
- flush(function() {
+ flush(() => {
assert.isTrue(spy.called);
done();
});
});
- test('comment event', function(done) {
- var testCommentNode = {foo: 'bar'};
+ test('comment event', done => {
+ const testCommentNode = {foo: 'bar'};
plugin.on(element.EventType.COMMENT, throwErrFn);
- plugin.on(element.EventType.COMMENT, function(commentNode) {
+ plugin.on(element.EventType.COMMENT, commentNode => {
assert.deepEqual(commentNode, testCommentNode);
assert.isTrue(errorStub.calledOnce);
done();
@@ -123,7 +123,7 @@
element.handleEvent(element.EventType.COMMENT, {node: testCommentNode});
});
- test('revert event', function() {
+ test('revert event', () => {
function appendToRevertMsg(c, revertMsg, originalMsg) {
return revertMsg + '\n' + originalMsg.replace(/^/gm, '> ') + '\ninfo';
}
@@ -134,16 +134,16 @@
plugin.on(element.EventType.REVERT, throwErrFn);
plugin.on(element.EventType.REVERT, appendToRevertMsg);
assert.equal(element.modifyRevertMsg(null, 'test', 'origTest'),
- 'test\n> origTest\ninfo');
+ 'test\n> origTest\ninfo');
assert.isTrue(errorStub.calledOnce);
plugin.on(element.EventType.REVERT, appendToRevertMsg);
assert.equal(element.modifyRevertMsg(null, 'test', 'origTest'),
- 'test\n> origTest\ninfo\n> origTest\ninfo');
+ 'test\n> origTest\ninfo\n> origTest\ninfo');
assert.isTrue(errorStub.calledTwice);
});
- test('postrevert event', function() {
+ test('postrevert event', () => {
function getLabels(c) {
return {'Code-Review': 1};
}
@@ -158,10 +158,10 @@
assert.isTrue(errorStub.calledOnce);
});
- test('commitmsgedit event', function(done) {
- var testMsg = 'Test CL commit message';
+ test('commitmsgedit event', done => {
+ const testMsg = 'Test CL commit message';
plugin.on(element.EventType.COMMIT_MSG_EDIT, throwErrFn);
- plugin.on(element.EventType.COMMIT_MSG_EDIT, function(change, msg) {
+ plugin.on(element.EventType.COMMIT_MSG_EDIT, (change, msg) => {
assert.deepEqual(msg, testMsg);
assert.isTrue(errorStub.calledOnce);
done();
@@ -169,10 +169,10 @@
element.handleCommitMessage(null, testMsg);
});
- test('labelchange event', function(done) {
- var testChange = {_number: 42};
+ test('labelchange event', done => {
+ const testChange = {_number: 42};
plugin.on(element.EventType.LABEL_CHANGE, throwErrFn);
- plugin.on(element.EventType.LABEL_CHANGE, function(change) {
+ plugin.on(element.EventType.LABEL_CHANGE, change => {
assert.deepEqual(change, testChange);
assert.isTrue(errorStub.calledOnce);
done();
@@ -180,41 +180,41 @@
element.handleEvent(element.EventType.LABEL_CHANGE, {change: testChange});
});
- test('submitchange', function() {
+ test('submitchange', () => {
plugin.on(element.EventType.SUBMIT_CHANGE, throwErrFn);
- plugin.on(element.EventType.SUBMIT_CHANGE, function() { return true; });
+ plugin.on(element.EventType.SUBMIT_CHANGE, () => { return true; });
assert.isTrue(element.canSubmitChange());
assert.isTrue(errorStub.calledOnce);
- plugin.on(element.EventType.SUBMIT_CHANGE, function() { return false; });
- plugin.on(element.EventType.SUBMIT_CHANGE, function() { return true; });
+ plugin.on(element.EventType.SUBMIT_CHANGE, () => { return false; });
+ plugin.on(element.EventType.SUBMIT_CHANGE, () => { return true; });
assert.isFalse(element.canSubmitChange());
assert.isTrue(errorStub.calledTwice);
});
- test('versioning', function() {
- var callback = sandbox.spy();
+ test('versioning', () => {
+ const callback = sandbox.spy();
Gerrit.install(callback, '0.0pre-alpha');
assert(callback.notCalled);
});
- test('getAccount', function(done) {
- Gerrit.getLoggedIn().then(function(loggedIn) {
+ test('getAccount', done => {
+ Gerrit.getLoggedIn().then(loggedIn => {
assert.isTrue(loggedIn);
done();
});
});
- test('_setPluginsCount', function(done) {
+ test('_setPluginsCount', done => {
stub('gr-reporting', {
- pluginsLoaded: function() {
+ pluginsLoaded() {
assert.equal(Gerrit._pluginsPending, 0);
done();
- }
+ },
});
Gerrit._setPluginsCount(0);
});
- test('_arePluginsLoaded', function() {
+ test('_arePluginsLoaded', () => {
assert.isTrue(Gerrit._arePluginsLoaded());
Gerrit._setPluginsCount(1);
assert.isFalse(Gerrit._arePluginsLoaded());
@@ -222,12 +222,12 @@
assert.isTrue(Gerrit._arePluginsLoaded());
});
- test('_pluginInstalled', function(done) {
+ test('_pluginInstalled', done => {
stub('gr-reporting', {
- pluginsLoaded: function() {
+ pluginsLoaded() {
assert.equal(Gerrit._pluginsPending, 0);
done();
- }
+ },
});
Gerrit._setPluginsCount(2);
Gerrit._pluginInstalled();
@@ -235,34 +235,34 @@
Gerrit._pluginInstalled();
});
- test('install calls _pluginInstalled', function() {
+ test('install calls _pluginInstalled', () => {
sandbox.stub(Gerrit, '_pluginInstalled');
- Gerrit.install(function(p) { plugin = p; }, '0.1',
+ Gerrit.install(p => { plugin = p; }, '0.1',
'http://test.com/plugins/testplugin/static/test.js');
assert.isTrue(Gerrit._pluginInstalled.calledOnce);
});
- test('install calls _pluginInstalled on error', function() {
+ test('install calls _pluginInstalled on error', () => {
sandbox.stub(Gerrit, '_pluginInstalled');
- Gerrit.install(function() {}, '0.0pre-alpha');
+ Gerrit.install(() => {}, '0.0pre-alpha');
assert.isTrue(Gerrit._pluginInstalled.calledOnce);
});
- test('installGwt calls _pluginInstalled', function() {
+ test('installGwt calls _pluginInstalled', () => {
sandbox.stub(Gerrit, '_pluginInstalled');
Gerrit.installGwt();
assert.isTrue(Gerrit._pluginInstalled.calledOnce);
});
- test('installGwt returns a stub object', function() {
- var plugin = Gerrit.installGwt();
+ test('installGwt returns a stub object', () => {
+ const plugin = Gerrit.installGwt();
sandbox.stub(console, 'warn');
assert.isAbove(Object.keys(plugin).length, 0);
- Object.keys(plugin).forEach(function(name) {
+ for (const name of Object.keys(plugin)) {
console.warn.reset();
plugin[name]();
assert.isTrue(console.warn.calledOnce);
- });
+ }
});
});
</script>
diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-public-js-api.js b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-public-js-api.js
index 402b371..a84eedd 100644
--- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-public-js-api.js
+++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-public-js-api.js
@@ -14,17 +14,17 @@
(function(window) {
'use strict';
- var warnNotSupported = function(opt_name) {
+ const warnNotSupported = function(opt_name) {
console.warn('Plugin API method ' + (opt_name || '') + ' is not supported');
};
- var stubbedMethods = ['_loadedGwt', 'screen', 'settingsScreen', 'panel'];
- var GWT_PLUGIN_STUB = {};
- stubbedMethods.forEach(function(name) {
+ const stubbedMethods = ['_loadedGwt', 'screen', 'settingsScreen', 'panel'];
+ const GWT_PLUGIN_STUB = {};
+ for (const name of stubbedMethods) {
GWT_PLUGIN_STUB[name] = warnNotSupported.bind(null, name);
- });
+ }
- var API_VERSION = '0.1';
+ const API_VERSION = '0.1';
// GWT JSNI uses $wnd to refer to window.
// http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html
@@ -38,7 +38,7 @@
}
this._url = new URL(opt_url);
- if (this._url.pathname.indexOf('/plugins') !== 0) {
+ if (!this._url.pathname.startsWith('/plugins')) {
console.warn('Plugin not being loaded from /plugins base path:',
this._url.href, '— Unable to determine name.');
return;
@@ -54,14 +54,14 @@
return this._name;
};
- Plugin.prototype.registerStyleModule =
- function(stylingEndpointName, moduleName) {
+ Plugin.prototype.registerStyleModule = function(stylingEndpointName,
+ moduleName) {
if (!Gerrit._styleModules[stylingEndpointName]) {
Gerrit._styleModules[stylingEndpointName] = [];
}
Gerrit._styleModules[stylingEndpointName].push({
pluginUrl: this._url,
- moduleName: moduleName,
+ moduleName,
});
};
@@ -87,7 +87,7 @@
Plugin._sharedAPIElement.Element.REPLY_DIALOG));
};
- var Gerrit = window.Gerrit || {};
+ const Gerrit = window.Gerrit || {};
// Number of plugins to initialize, -1 means 'not yet known'.
Gerrit._pluginsPending = -1;
@@ -102,12 +102,13 @@
Gerrit.css = function(rulesStr) {
if (!Gerrit._customStyleSheet) {
- var styleEl = document.createElement('style');
+ const styleEl = document.createElement('style');
document.head.appendChild(styleEl);
Gerrit._customStyleSheet = styleEl.sheet;
}
- var name = '__pg_js_api_class_' + Gerrit._customStyleSheet.cssRules.length;
+ const name = '__pg_js_api_class_' +
+ Gerrit._customStyleSheet.cssRules.length;
Gerrit._customStyleSheet.insertRule('.' + name + '{' + rulesStr + '}', 0);
return name;
};
@@ -121,9 +122,9 @@
}
// TODO(andybons): Polyfill currentScript for IE10/11 (edge supports it).
- var src = opt_src || (document.currentScript &&
+ const src = opt_src || (document.currentScript &&
document.currentScript.src || document.currentScript.baseURI);
- var plugin = new Plugin(src);
+ const plugin = new Plugin(src);
try {
callback(plugin);
} catch (e) {
@@ -155,7 +156,7 @@
if (Gerrit._arePluginsLoaded()) {
Gerrit._allPluginsPromise = Promise.resolve();
} else {
- Gerrit._allPluginsPromise = new Promise(function(resolve) {
+ Gerrit._allPluginsPromise = new Promise(resolve => {
Gerrit._resolveAllPluginsLoaded = resolve;
});
}
diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js
index ae42c2a..68576b8 100644
--- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js
+++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js
@@ -14,20 +14,20 @@
(function() {
'use strict';
- var DiffViewMode = {
+ const DiffViewMode = {
SIDE_BY_SIDE: 'SIDE_BY_SIDE',
UNIFIED: 'UNIFIED_DIFF',
};
- var JSON_PREFIX = ')]}\'';
- var MAX_UNIFIED_DEFAULT_WINDOW_WIDTH_PX = 900;
- var PARENT_PATCH_NUM = 'PARENT';
+ const JSON_PREFIX = ')]}\'';
+ const MAX_UNIFIED_DEFAULT_WINDOW_WIDTH_PX = 900;
+ const PARENT_PATCH_NUM = 'PARENT';
- var Requests = {
+ const Requests = {
SEND_DIFF_DRAFT: 'sendDiffDraft',
};
// Must be kept in sync with the ListChangesOption enum and protobuf.
- var ListChangesOption = {
+ const ListChangesOption = {
LABELS: 0,
DETAILED_LABELS: 8,
@@ -115,20 +115,20 @@
},
},
- fetchJSON: function(url, opt_errFn, opt_cancelCondition, opt_params,
+ fetchJSON(url, opt_errFn, opt_cancelCondition, opt_params,
opt_opts) {
opt_opts = opt_opts || {};
// Issue 5715, This can be reverted back once
// iOS 10.3 and mac os 10.12.4 has the fetch api fix.
- var fetchOptions = {
- credentials: 'same-origin'
+ const fetchOptions = {
+ credentials: 'same-origin',
};
if (opt_opts.headers !== undefined) {
fetchOptions['headers'] = opt_opts.headers;
}
- var urlWithParams = this._urlWithParams(url, opt_params);
- return fetch(urlWithParams, fetchOptions).then(function(response) {
+ const urlWithParams = this._urlWithParams(url, opt_params);
+ return fetch(urlWithParams, fetchOptions).then(response => {
if (opt_cancelCondition && opt_cancelCondition()) {
response.body.cancel();
return;
@@ -139,12 +139,12 @@
opt_errFn.call(null, response);
return;
}
- this.fire('server-error', {response: response});
+ this.fire('server-error', {response});
return;
}
return this.getResponseObject(response);
- }.bind(this)).catch(function(err) {
+ }).catch(err => {
if (opt_errFn) {
opt_errFn.call(null, null, err);
} else {
@@ -152,31 +152,28 @@
throw err;
}
throw err;
- }.bind(this));
+ });
},
- _urlWithParams: function(url, opt_params) {
+ _urlWithParams(url, opt_params) {
if (!opt_params) { return this.getBaseUrl() + url; }
- var params = [];
- for (var p in opt_params) {
+ const params = [];
+ for (const p in opt_params) {
if (opt_params[p] == null) {
params.push(encodeURIComponent(p));
continue;
}
- var values = [].concat(opt_params[p]);
- for (var i = 0; i < values.length; i++) {
- params.push(
- encodeURIComponent(p) + '=' +
- encodeURIComponent(values[i]));
+ for (const value of [].concat(opt_params[p])) {
+ params.push(`${encodeURIComponent(p)}=${encodeURIComponent(value)}`);
}
}
return this.getBaseUrl() + url + '?' + params.join('&');
},
- getResponseObject: function(response) {
- return response.text().then(function(text) {
- var result;
+ getResponseObject(response) {
+ return response.text().then(text => {
+ let result;
try {
result = JSON.parse(text.substring(JSON_PREFIX.length));
} catch (_) {
@@ -186,21 +183,21 @@
});
},
- getConfig: function() {
+ getConfig() {
return this._fetchSharedCacheURL('/config/server/info');
},
- getProjectConfig: function(project) {
+ getProjectConfig(project) {
return this._fetchSharedCacheURL(
'/projects/' + encodeURIComponent(project) + '/config');
},
- getVersion: function() {
+ getVersion() {
return this._fetchSharedCacheURL('/config/server/version');
},
- getDiffPreferences: function() {
- return this.getLoggedIn().then(function(loggedIn) {
+ getDiffPreferences() {
+ return this.getLoggedIn().then(loggedIn => {
if (loggedIn) {
return this._fetchSharedCacheURL('/accounts/self/preferences.diff');
}
@@ -224,10 +221,10 @@
tab_size: 8,
theme: 'DEFAULT',
});
- }.bind(this));
+ });
},
- savePreferences: function(prefs, opt_errFn, opt_ctx) {
+ savePreferences(prefs, opt_errFn, opt_ctx) {
// Note (Issue 5142): normalize the download scheme with lower case before
// saving.
if (prefs.download_scheme) {
@@ -238,127 +235,127 @@
opt_ctx);
},
- saveDiffPreferences: function(prefs, opt_errFn, opt_ctx) {
+ saveDiffPreferences(prefs, opt_errFn, opt_ctx) {
// Invalidate the cache.
this._cache['/accounts/self/preferences.diff'] = undefined;
return this.send('PUT', '/accounts/self/preferences.diff', prefs,
opt_errFn, opt_ctx);
},
- getAccount: function() {
- return this._fetchSharedCacheURL('/accounts/self/detail', function(resp) {
+ getAccount() {
+ return this._fetchSharedCacheURL('/accounts/self/detail', resp => {
if (resp.status === 403) {
this._cache['/accounts/self/detail'] = null;
}
- }.bind(this));
+ });
},
- getAccountEmails: function() {
+ getAccountEmails() {
return this._fetchSharedCacheURL('/accounts/self/emails');
},
- addAccountEmail: function(email, opt_errFn, opt_ctx) {
+ addAccountEmail(email, opt_errFn, opt_ctx) {
return this.send('PUT', '/accounts/self/emails/' +
encodeURIComponent(email), null, opt_errFn, opt_ctx);
},
- deleteAccountEmail: function(email, opt_errFn, opt_ctx) {
+ deleteAccountEmail(email, opt_errFn, opt_ctx) {
return this.send('DELETE', '/accounts/self/emails/' +
encodeURIComponent(email), null, opt_errFn, opt_ctx);
},
- setPreferredAccountEmail: function(email, opt_errFn, opt_ctx) {
+ setPreferredAccountEmail(email, opt_errFn, opt_ctx) {
return this.send('PUT', '/accounts/self/emails/' +
encodeURIComponent(email) + '/preferred', null,
- opt_errFn, opt_ctx).then(function() {
- // If result of getAccountEmails is in cache, update it in the cache
- // so we don't have to invalidate it.
- var cachedEmails = this._cache['/accounts/self/emails'];
- if (cachedEmails) {
- var emails = cachedEmails.map(function(entry) {
- if (entry.email === email) {
- return {email: email, preferred: true};
- } else {
- return {email: email};
+ opt_errFn, opt_ctx).then(() => {
+ // If result of getAccountEmails is in cache, update it in the cache
+ // so we don't have to invalidate it.
+ const cachedEmails = this._cache['/accounts/self/emails'];
+ if (cachedEmails) {
+ const emails = cachedEmails.map(entry => {
+ if (entry.email === email) {
+ return {email, preferred: true};
+ } else {
+ return {email};
+ }
+ });
+ this._cache['/accounts/self/emails'] = emails;
}
});
- this._cache['/accounts/self/emails'] = emails;
- }
- }.bind(this));
},
- setAccountName: function(name, opt_errFn, opt_ctx) {
- return this.send('PUT', '/accounts/self/name', {name: name}, opt_errFn,
- opt_ctx).then(function(response) {
+ setAccountName(name, opt_errFn, opt_ctx) {
+ return this.send('PUT', '/accounts/self/name', {name}, opt_errFn,
+ opt_ctx).then(response => {
// If result of getAccount is in cache, update it in the cache
// so we don't have to invalidate it.
- var cachedAccount = this._cache['/accounts/self/detail'];
+ const cachedAccount = this._cache['/accounts/self/detail'];
if (cachedAccount) {
- return this.getResponseObject(response).then(function(newName) {
+ return this.getResponseObject(response).then(newName => {
// Replace object in cache with new object to force UI updates.
// TODO(logan): Polyfill for Object.assign in IE
this._cache['/accounts/self/detail'] = Object.assign(
{}, cachedAccount, {name: newName});
- }.bind(this));
+ });
}
- }.bind(this));
+ });
},
- setAccountStatus: function(status, opt_errFn, opt_ctx) {
- return this.send('PUT', '/accounts/self/status', {status: status},
- opt_errFn, opt_ctx).then(function(response) {
+ setAccountStatus(status, opt_errFn, opt_ctx) {
+ return this.send('PUT', '/accounts/self/status', {status},
+ opt_errFn, opt_ctx).then(response => {
// If result of getAccount is in cache, update it in the cache
// so we don't have to invalidate it.
- var cachedAccount = this._cache['/accounts/self/detail'];
+ const cachedAccount = this._cache['/accounts/self/detail'];
if (cachedAccount) {
- return this.getResponseObject(response).then(function(newStatus) {
+ return this.getResponseObject(response).then(newStatus => {
// Replace object in cache with new object to force UI updates.
// TODO(logan): Polyfill for Object.assign in IE
this._cache['/accounts/self/detail'] = Object.assign(
{}, cachedAccount, {status: newStatus});
- }.bind(this));
+ });
}
- }.bind(this));
+ });
},
- getAccountGroups: function() {
+ getAccountGroups() {
return this._fetchSharedCacheURL('/accounts/self/groups');
},
- getAccountCapabilities: function(opt_params) {
- var queryString = '';
+ getAccountCapabilities(opt_params) {
+ let queryString = '';
if (opt_params) {
queryString = '?q=' + opt_params
- .map(function(param) { return encodeURIComponent(param); })
+ .map(param => { return encodeURIComponent(param); })
.join('&q=');
}
return this._fetchSharedCacheURL('/accounts/self/capabilities' +
queryString);
},
- getLoggedIn: function() {
- return this.getAccount().then(function(account) {
+ getLoggedIn() {
+ return this.getAccount().then(account => {
return account != null;
});
},
- checkCredentials: function() {
+ checkCredentials() {
// Skip the REST response cache.
return this.fetchJSON('/accounts/self/detail');
},
- getPreferences: function() {
- return this.getLoggedIn().then(function(loggedIn) {
+ getPreferences() {
+ return this.getLoggedIn().then(loggedIn => {
if (loggedIn) {
return this._fetchSharedCacheURL('/accounts/self/preferences').then(
- function(res) {
- if (this._isNarrowScreen()) {
- res.default_diff_view = DiffViewMode.UNIFIED;
- } else {
- res.default_diff_view = res.diff_view;
- }
- return Promise.resolve(res);
- }.bind(this));
+ res => {
+ if (this._isNarrowScreen()) {
+ res.default_diff_view = DiffViewMode.UNIFIED;
+ } else {
+ res.default_diff_view = res.diff_view;
+ }
+ return Promise.resolve(res);
+ });
}
return Promise.resolve({
@@ -367,27 +364,27 @@
DiffViewMode.UNIFIED : DiffViewMode.SIDE_BY_SIDE,
diff_view: 'SIDE_BY_SIDE',
});
- }.bind(this));
+ });
},
- getWatchedProjects: function() {
+ getWatchedProjects() {
return this._fetchSharedCacheURL('/accounts/self/watched.projects');
},
- saveWatchedProjects: function(projects, opt_errFn, opt_ctx) {
+ saveWatchedProjects(projects, opt_errFn, opt_ctx) {
return this.send('POST', '/accounts/self/watched.projects', projects,
opt_errFn, opt_ctx)
- .then(function(response) {
+ .then(response => {
return this.getResponseObject(response);
- }.bind(this));
+ });
},
- deleteWatchedProjects: function(projects, opt_errFn, opt_ctx) {
+ deleteWatchedProjects(projects, opt_errFn, opt_ctx) {
return this.send('POST', '/accounts/self/watched.projects:delete',
projects, opt_errFn, opt_ctx);
},
- _fetchSharedCacheURL: function(url, opt_errFn) {
+ _fetchSharedCacheURL(url, opt_errFn) {
if (this._sharedFetchPromises[url]) {
return this._sharedFetchPromises[url];
}
@@ -396,25 +393,25 @@
return Promise.resolve(this._cache[url]);
}
this._sharedFetchPromises[url] = this.fetchJSON(url, opt_errFn).then(
- function(response) {
- if (response !== undefined) {
- this._cache[url] = response;
- }
- this._sharedFetchPromises[url] = undefined;
- return response;
- }.bind(this)).catch(function(err) {
- this._sharedFetchPromises[url] = undefined;
- throw err;
- }.bind(this));
+ response => {
+ if (response !== undefined) {
+ this._cache[url] = response;
+ }
+ this._sharedFetchPromises[url] = undefined;
+ return response;
+ }).catch(err => {
+ this._sharedFetchPromises[url] = undefined;
+ throw err;
+ });
return this._sharedFetchPromises[url];
},
- _isNarrowScreen: function() {
+ _isNarrowScreen() {
return window.innerWidth < MAX_UNIFIED_DEFAULT_WINDOW_WIDTH_PX;
},
- getChanges: function(changesPerPage, opt_query, opt_offset) {
- var options = this._listChangesOptionsToHex(
+ getChanges(changesPerPage, opt_query, opt_offset) {
+ const options = this._listChangesOptionsToHex(
ListChangesOption.LABELS,
ListChangesOption.DETAILED_ACCOUNTS
);
@@ -422,7 +419,7 @@
if (opt_offset === 'n,z') {
opt_offset = 0;
}
- var params = {
+ const params = {
n: changesPerPage,
O: options,
S: opt_offset || 0,
@@ -433,13 +430,13 @@
return this.fetchJSON('/changes/', null, null, params);
},
- getDashboardChanges: function() {
- var options = this._listChangesOptionsToHex(
+ getDashboardChanges() {
+ const options = this._listChangesOptionsToHex(
ListChangesOption.LABELS,
ListChangesOption.DETAILED_ACCOUNTS,
ListChangesOption.REVIEWED
);
- var params = {
+ const params = {
O: options,
q: [
'is:open owner:self',
@@ -451,12 +448,12 @@
return this.fetchJSON('/changes/', null, null, params);
},
- getChangeActionURL: function(changeNum, opt_patchNum, endpoint) {
+ getChangeActionURL(changeNum, opt_patchNum, endpoint) {
return this._changeBaseURL(changeNum, opt_patchNum) + endpoint;
},
- getChangeDetail: function(changeNum, opt_errFn, opt_cancelCondition) {
- var options = this._listChangesOptionsToHex(
+ getChangeDetail(changeNum, opt_errFn, opt_cancelCondition) {
+ const options = this._listChangesOptionsToHex(
ListChangesOption.ALL_REVISIONS,
ListChangesOption.CHANGE_ACTIONS,
ListChangesOption.CURRENT_ACTIONS,
@@ -467,18 +464,18 @@
);
return this._getChangeDetail(
changeNum, options, opt_errFn, opt_cancelCondition)
- .then(GrReviewerUpdatesParser.parse);
+ .then(GrReviewerUpdatesParser.parse);
},
- getDiffChangeDetail: function(changeNum, opt_errFn, opt_cancelCondition) {
- var options = this._listChangesOptionsToHex(
+ getDiffChangeDetail(changeNum, opt_errFn, opt_cancelCondition) {
+ const options = this._listChangesOptionsToHex(
ListChangesOption.ALL_REVISIONS
);
return this._getChangeDetail(changeNum, options, opt_errFn,
opt_cancelCondition);
},
- _getChangeDetail: function(changeNum, options, opt_errFn,
+ _getChangeDetail(changeNum, options, opt_errFn,
opt_cancelCondition) {
return this.fetchJSON(
this.getChangeActionURL(changeNum, null, '/detail'),
@@ -487,13 +484,13 @@
{O: options});
},
- getChangeCommitInfo: function(changeNum, patchNum) {
+ getChangeCommitInfo(changeNum, patchNum) {
return this.fetchJSON(
this.getChangeActionURL(changeNum, patchNum, '/commit?links'));
},
- getChangeFiles: function(changeNum, patchRange) {
- var endpoint = '/files';
+ getChangeFiles(changeNum, patchRange) {
+ let endpoint = '/files';
if (patchRange.basePatchNum !== 'PARENT') {
endpoint += '?base=' + encodeURIComponent(patchRange.basePatchNum);
}
@@ -501,23 +498,23 @@
this.getChangeActionURL(changeNum, patchRange.patchNum, endpoint));
},
- getChangeFilesAsSpeciallySortedArray: function(changeNum, patchRange) {
+ getChangeFilesAsSpeciallySortedArray(changeNum, patchRange) {
return this.getChangeFiles(changeNum, patchRange).then(
this._normalizeChangeFilesResponse.bind(this));
},
- getChangeFilePathsAsSpeciallySortedArray: function(changeNum, patchRange) {
- return this.getChangeFiles(changeNum, patchRange).then(function(files) {
+ getChangeFilePathsAsSpeciallySortedArray(changeNum, patchRange) {
+ return this.getChangeFiles(changeNum, patchRange).then(files => {
return Object.keys(files).sort(this.specialFilePathCompare);
- }.bind(this));
+ });
},
- _normalizeChangeFilesResponse: function(response) {
+ _normalizeChangeFilesResponse(response) {
if (!response) { return []; }
- var paths = Object.keys(response).sort(this.specialFilePathCompare);
- var files = [];
- for (var i = 0; i < paths.length; i++) {
- var info = response[paths[i]];
+ const paths = Object.keys(response).sort(this.specialFilePathCompare);
+ const files = [];
+ for (let i = 0; i < paths.length; i++) {
+ const info = response[paths[i]];
info.__path = paths[i];
info.lines_inserted = info.lines_inserted || 0;
info.lines_deleted = info.lines_deleted || 0;
@@ -526,58 +523,59 @@
return files;
},
- getChangeRevisionActions: function(changeNum, patchNum) {
+ getChangeRevisionActions(changeNum, patchNum) {
return this.fetchJSON(
this.getChangeActionURL(changeNum, patchNum, '/actions')).then(
- function(revisionActions) {
+ revisionActions => {
// The rebase button on change screen is always enabled.
- if (revisionActions.rebase) {
- revisionActions.rebase.rebaseOnCurrent =
+ if (revisionActions.rebase) {
+ revisionActions.rebase.rebaseOnCurrent =
!!revisionActions.rebase.enabled;
- revisionActions.rebase.enabled = true;
- }
- return revisionActions;
- });
+ revisionActions.rebase.enabled = true;
+ }
+ return revisionActions;
+ });
},
- getChangeSuggestedReviewers: function(changeNum, inputVal, opt_errFn,
+ getChangeSuggestedReviewers(changeNum, inputVal, opt_errFn,
opt_ctx) {
- var url = this.getChangeActionURL(changeNum, null, '/suggest_reviewers');
+ const url =
+ this.getChangeActionURL(changeNum, null, '/suggest_reviewers');
return this.fetchJSON(url, opt_errFn, opt_ctx, {
n: 10, // Return max 10 results
q: inputVal,
});
},
- getSuggestedGroups: function(inputVal, opt_n, opt_errFn, opt_ctx) {
- var params = {s: inputVal};
+ getSuggestedGroups(inputVal, opt_n, opt_errFn, opt_ctx) {
+ const params = {s: inputVal};
if (opt_n) { params.n = opt_n; }
return this.fetchJSON('/groups/', opt_errFn, opt_ctx, params);
},
- getSuggestedProjects: function(inputVal, opt_n, opt_errFn, opt_ctx) {
- var params = {p: inputVal};
+ getSuggestedProjects(inputVal, opt_n, opt_errFn, opt_ctx) {
+ const params = {p: inputVal};
if (opt_n) { params.n = opt_n; }
return this.fetchJSON('/projects/', opt_errFn, opt_ctx, params);
},
- getSuggestedAccounts: function(inputVal, opt_n, opt_errFn, opt_ctx) {
- var params = {q: inputVal, suggest: null};
+ getSuggestedAccounts(inputVal, opt_n, opt_errFn, opt_ctx) {
+ const params = {q: inputVal, suggest: null};
if (opt_n) { params.n = opt_n; }
return this.fetchJSON('/accounts/', opt_errFn, opt_ctx, params);
},
- addChangeReviewer: function(changeNum, reviewerID) {
+ addChangeReviewer(changeNum, reviewerID) {
return this._sendChangeReviewerRequest('POST', changeNum, reviewerID);
},
- removeChangeReviewer: function(changeNum, reviewerID) {
+ removeChangeReviewer(changeNum, reviewerID) {
return this._sendChangeReviewerRequest('DELETE', changeNum, reviewerID);
},
- _sendChangeReviewerRequest: function(method, changeNum, reviewerID) {
- var url = this.getChangeActionURL(changeNum, null, '/reviewers');
- var body;
+ _sendChangeReviewerRequest(method, changeNum, reviewerID) {
+ let url = this.getChangeActionURL(changeNum, null, '/reviewers');
+ let body;
switch (method) {
case 'POST':
body = {reviewer: reviewerID};
@@ -592,124 +590,122 @@
return this.send(method, url, body);
},
- getRelatedChanges: function(changeNum, patchNum) {
+ getRelatedChanges(changeNum, patchNum) {
return this.fetchJSON(
this.getChangeActionURL(changeNum, patchNum, '/related'));
},
- getChangesSubmittedTogether: function(changeNum) {
+ getChangesSubmittedTogether(changeNum) {
return this.fetchJSON(
this.getChangeActionURL(changeNum, null, '/submitted_together'));
},
- getChangeConflicts: function(changeNum) {
- var options = this._listChangesOptionsToHex(
+ getChangeConflicts(changeNum) {
+ const options = this._listChangesOptionsToHex(
ListChangesOption.CURRENT_REVISION,
ListChangesOption.CURRENT_COMMIT
);
- var params = {
+ const params = {
O: options,
q: 'status:open is:mergeable conflicts:' + changeNum,
};
return this.fetchJSON('/changes/', null, null, params);
},
- getChangeCherryPicks: function(project, changeID, changeNum) {
- var options = this._listChangesOptionsToHex(
+ getChangeCherryPicks(project, changeID, changeNum) {
+ const options = this._listChangesOptionsToHex(
ListChangesOption.CURRENT_REVISION,
ListChangesOption.CURRENT_COMMIT
);
- var query = [
+ const query = [
'project:' + project,
'change:' + changeID,
'-change:' + changeNum,
'-is:abandoned',
].join(' ');
- var params = {
+ const params = {
O: options,
q: query,
};
return this.fetchJSON('/changes/', null, null, params);
},
- getChangesWithSameTopic: function(topic) {
- var options = this._listChangesOptionsToHex(
+ getChangesWithSameTopic(topic) {
+ const options = this._listChangesOptionsToHex(
ListChangesOption.LABELS,
ListChangesOption.CURRENT_REVISION,
ListChangesOption.CURRENT_COMMIT,
ListChangesOption.DETAILED_LABELS
);
- var params = {
+ const params = {
O: options,
q: 'status:open topic:' + topic,
};
return this.fetchJSON('/changes/', null, null, params);
},
- getReviewedFiles: function(changeNum, patchNum) {
+ getReviewedFiles(changeNum, patchNum) {
return this.fetchJSON(
this.getChangeActionURL(changeNum, patchNum, '/files?reviewed'));
},
- saveFileReviewed: function(changeNum, patchNum, path, reviewed, opt_errFn,
- opt_ctx) {
- var method = reviewed ? 'PUT' : 'DELETE';
- var url = this.getChangeActionURL(changeNum, patchNum,
+ saveFileReviewed(changeNum, patchNum, path, reviewed, opt_errFn, opt_ctx) {
+ const method = reviewed ? 'PUT' : 'DELETE';
+ const url = this.getChangeActionURL(changeNum, patchNum,
'/files/' + encodeURIComponent(path) + '/reviewed');
return this.send(method, url, null, opt_errFn, opt_ctx);
},
- saveChangeReview: function(changeNum, patchNum, review, opt_errFn,
- opt_ctx) {
- var url = this.getChangeActionURL(changeNum, patchNum, '/review');
+ saveChangeReview(changeNum, patchNum, review, opt_errFn, opt_ctx) {
+ const url = this.getChangeActionURL(changeNum, patchNum, '/review');
return this.send('POST', url, review, opt_errFn, opt_ctx);
},
- getFileInChangeEdit: function(changeNum, path) {
+ getFileInChangeEdit(changeNum, path) {
return this.send('GET',
this.getChangeActionURL(changeNum, null,
'/edit/' + encodeURIComponent(path)
));
},
- rebaseChangeEdit: function(changeNum) {
+ rebaseChangeEdit(changeNum) {
return this.send('POST',
this.getChangeActionURL(changeNum, null,
'/edit:rebase'
));
},
- deleteChangeEdit: function(changeNum) {
+ deleteChangeEdit(changeNum) {
return this.send('DELETE',
this.getChangeActionURL(changeNum, null,
'/edit'
));
},
- restoreFileInChangeEdit: function(changeNum, restore_path) {
+ restoreFileInChangeEdit(changeNum, restore_path) {
return this.send('POST',
this.getChangeActionURL(changeNum, null, '/edit'),
- {restore_path: restore_path}
+ {restore_path}
);
},
- renameFileInChangeEdit: function(changeNum, old_path, new_path) {
+ renameFileInChangeEdit(changeNum, old_path, new_path) {
return this.send('POST',
this.getChangeActionURL(changeNum, null, '/edit'),
- {old_path: old_path},
- {new_path: new_path}
+ {old_path},
+ {new_path}
);
},
- deleteFileInChangeEdit: function(changeNum, path) {
+ deleteFileInChangeEdit(changeNum, path) {
return this.send('DELETE',
this.getChangeActionURL(changeNum, null,
'/edit/' + encodeURIComponent(path)
));
},
- saveChangeEdit: function(changeNum, path, contents) {
+ saveChangeEdit(changeNum, path, contents) {
return this.send('PUT',
this.getChangeActionURL(changeNum, null,
'/edit/' + encodeURIComponent(path)
@@ -718,29 +714,29 @@
);
},
- saveChangeCommitMessageEdit: function(changeNum, message) {
- var url = this.getChangeActionURL(changeNum, null, '/edit:message');
- return this.send('PUT', url, {message: message});
+ saveChangeCommitMessageEdit(changeNum, message) {
+ const url = this.getChangeActionURL(changeNum, null, '/edit:message');
+ return this.send('PUT', url, {message});
},
- publishChangeEdit: function(changeNum) {
+ publishChangeEdit(changeNum) {
return this.send('POST',
this.getChangeActionURL(changeNum, null, '/edit:publish'));
},
- saveChangeStarred: function(changeNum, starred) {
- var url = '/accounts/self/starred.changes/' + changeNum;
- var method = starred ? 'PUT' : 'DELETE';
+ saveChangeStarred(changeNum, starred) {
+ const url = '/accounts/self/starred.changes/' + changeNum;
+ const method = starred ? 'PUT' : 'DELETE';
return this.send(method, url);
},
- send: function(method, url, opt_body, opt_errFn, opt_ctx, opt_contentType) {
- var headers = new Headers({
+ send(method, url, opt_body, opt_errFn, opt_ctx, opt_contentType) {
+ const headers = new Headers({
'X-Gerrit-Auth': this._getCookie('XSRF_TOKEN'),
});
- var options = {
- method: method,
- headers: headers,
+ const options = {
+ method,
+ headers,
credentials: 'same-origin',
};
if (opt_body) {
@@ -750,30 +746,30 @@
}
options.body = opt_body;
}
- return fetch(this.getBaseUrl() + url, options).then(function(response) {
+ return fetch(this.getBaseUrl() + url, options).then(response => {
if (!response.ok) {
if (opt_errFn) {
opt_errFn.call(opt_ctx || null, response);
return undefined;
}
- this.fire('server-error', {response: response});
+ this.fire('server-error', {response});
}
return response;
- }.bind(this)).catch(function(err) {
+ }).catch(err => {
this.fire('network-error', {error: err});
if (opt_errFn) {
opt_errFn.call(opt_ctx, null, err);
} else {
throw err;
}
- }.bind(this));
+ });
},
- getDiff: function(changeNum, basePatchNum, patchNum, path,
+ getDiff(changeNum, basePatchNum, patchNum, path,
opt_errFn, opt_cancelCondition) {
- var url = this._getDiffFetchURL(changeNum, patchNum, path);
- var params = {
+ const url = this._getDiffFetchURL(changeNum, patchNum, path);
+ const params = {
context: 'ALL',
intraline: null,
whitespace: 'IGNORE_NONE',
@@ -785,32 +781,29 @@
return this.fetchJSON(url, opt_errFn, opt_cancelCondition, params);
},
- _getDiffFetchURL: function(changeNum, patchNum, path) {
+ _getDiffFetchURL(changeNum, patchNum, path) {
return this._changeBaseURL(changeNum, patchNum) + '/files/' +
encodeURIComponent(path) + '/diff';
},
- getDiffComments: function(changeNum, opt_basePatchNum, opt_patchNum,
- opt_path) {
+ getDiffComments(changeNum, opt_basePatchNum, opt_patchNum, opt_path) {
return this._getDiffComments(changeNum, '/comments', opt_basePatchNum,
opt_patchNum, opt_path);
},
- getDiffRobotComments: function(changeNum, basePatchNum, patchNum,
- opt_path) {
+ getDiffRobotComments(changeNum, basePatchNum, patchNum, opt_path) {
return this._getDiffComments(changeNum, '/robotcomments', basePatchNum,
patchNum, opt_path);
},
- getDiffDrafts: function(changeNum, opt_basePatchNum, opt_patchNum,
- opt_path) {
+ getDiffDrafts(changeNum, opt_basePatchNum, opt_patchNum, opt_path) {
return this._getDiffComments(changeNum, '/drafts', opt_basePatchNum,
opt_patchNum, opt_path);
},
- _setRange: function(comments, comment) {
+ _setRange(comments, comment) {
if (comment.in_reply_to && !comment.range) {
- for (var i = 0; i < comments.length; i++) {
+ for (let i = 0; i < comments.length; i++) {
if (comments[i].id === comment.in_reply_to) {
comment.range = comments[i].range;
break;
@@ -820,18 +813,18 @@
return comment;
},
- _setRanges: function(comments) {
+ _setRanges(comments) {
comments = comments || [];
- comments.sort(function(a, b) {
+ comments.sort((a, b) => {
return util.parseDate(a.updated) - util.parseDate(b.updated);
});
- comments.forEach(function(comment) {
+ for (const comment of comments) {
this._setRange(comments, comment);
- }.bind(this));
+ }
return comments;
},
- _getDiffComments: function(changeNum, endpoint, opt_basePatchNum,
+ _getDiffComments(changeNum, endpoint, opt_basePatchNum,
opt_patchNum, opt_path) {
if (!opt_basePatchNum && !opt_patchNum && !opt_path) {
return this.fetchJSON(
@@ -842,12 +835,12 @@
function withoutParent(c) { return c.side != PARENT_PATCH_NUM; }
function setPath(c) { c.path = opt_path; }
- var promises = [];
- var comments;
- var baseComments;
- var url =
+ const promises = [];
+ let comments;
+ let baseComments;
+ const url =
this._getDiffCommentsFetchURL(changeNum, endpoint, opt_patchNum);
- promises.push(this.fetchJSON(url).then(function(response) {
+ promises.push(this.fetchJSON(url).then(response => {
comments = response[opt_path] || [];
// TODO(kaspern): Implement this on in the backend so this can be
@@ -864,50 +857,50 @@
comments = comments.filter(withoutParent);
comments.forEach(setPath);
- }.bind(this)));
+ }));
if (opt_basePatchNum != PARENT_PATCH_NUM) {
- var baseURL = this._getDiffCommentsFetchURL(changeNum, endpoint,
+ const baseURL = this._getDiffCommentsFetchURL(changeNum, endpoint,
opt_basePatchNum);
- promises.push(this.fetchJSON(baseURL).then(function(response) {
+ promises.push(this.fetchJSON(baseURL).then(response => {
baseComments = (response[opt_path] || []).filter(withoutParent);
baseComments = this._setRanges(baseComments);
baseComments.forEach(setPath);
- }.bind(this)));
+ }));
}
- return Promise.all(promises).then(function() {
+ return Promise.all(promises).then(() => {
return Promise.resolve({
- baseComments: baseComments,
- comments: comments,
+ baseComments,
+ comments,
});
});
},
- _getDiffCommentsFetchURL: function(changeNum, endpoint, opt_patchNum) {
+ _getDiffCommentsFetchURL(changeNum, endpoint, opt_patchNum) {
return this._changeBaseURL(changeNum, opt_patchNum) + endpoint;
},
- saveDiffDraft: function(changeNum, patchNum, draft) {
+ saveDiffDraft(changeNum, patchNum, draft) {
return this._sendDiffDraftRequest('PUT', changeNum, patchNum, draft);
},
- deleteDiffDraft: function(changeNum, patchNum, draft) {
+ deleteDiffDraft(changeNum, patchNum, draft) {
return this._sendDiffDraftRequest('DELETE', changeNum, patchNum, draft);
},
- hasPendingDiffDrafts: function() {
+ hasPendingDiffDrafts() {
return !!this._pendingRequests[Requests.SEND_DIFF_DRAFT];
},
- _sendDiffDraftRequest: function(method, changeNum, patchNum, draft) {
- var url = this.getChangeActionURL(changeNum, patchNum, '/drafts');
+ _sendDiffDraftRequest(method, changeNum, patchNum, draft) {
+ let url = this.getChangeActionURL(changeNum, patchNum, '/drafts');
if (draft.id) {
url += '/' + draft.id;
}
- var body;
+ let body;
if (method === 'PUT') {
body = draft;
}
@@ -917,14 +910,14 @@
}
this._pendingRequests[Requests.SEND_DIFF_DRAFT]++;
- return this.send(method, url, body).then(function(res) {
+ return this.send(method, url, body).then(res => {
this._pendingRequests[Requests.SEND_DIFF_DRAFT]--;
return res;
- }.bind(this));
+ });
},
- _changeBaseURL: function(changeNum, opt_patchNum) {
- var v = '/changes/' + changeNum;
+ _changeBaseURL(changeNum, opt_patchNum) {
+ let v = '/changes/' + changeNum;
if (opt_patchNum) {
v += '/revisions/' + opt_patchNum;
}
@@ -933,49 +926,49 @@
// Derived from
// gerrit-extension-api/src/main/j/c/g/gerrit/extensions/client/ListChangesOption.java
- _listChangesOptionsToHex: function() {
- var v = 0;
- for (var i = 0; i < arguments.length; i++) {
- v |= 1 << arguments[i];
+ _listChangesOptionsToHex(...args) {
+ let v = 0;
+ for (let i = 0; i < args.length; i++) {
+ v |= 1 << args[i];
}
return v.toString(16);
},
- _getCookie: function(name) {
- var key = name + '=';
- var cookies = document.cookie.split(';');
- for (var i = 0; i < cookies.length; i++) {
- var c = cookies[i];
+ _getCookie(name) {
+ const key = name + '=';
+ const cookies = document.cookie.split(';');
+ for (let i = 0; i < cookies.length; i++) {
+ let c = cookies[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
- if (c.indexOf(key) == 0) {
+ if (c.startsWith(key)) {
return c.substring(key.length, c.length);
}
}
return '';
},
- getCommitInfo: function(project, commit) {
+ getCommitInfo(project, commit) {
return this.fetchJSON(
'/projects/' + encodeURIComponent(project) +
'/commits/' + encodeURIComponent(commit));
},
- _fetchB64File: function(url) {
+ _fetchB64File(url) {
return fetch(this.getBaseUrl() + url, {credentials: 'same-origin'})
- .then(function(response) {
+ .then(response => {
if (!response.ok) { return Promise.reject(response.statusText); }
- var type = response.headers.get('X-FYI-Content-Type');
+ const type = response.headers.get('X-FYI-Content-Type');
return response.text()
- .then(function(text) {
- return {body: text, type: type};
- });
+ .then(text => {
+ return {body: text, type};
+ });
});
},
- getChangeFileContents: function(changeId, patchNum, path, opt_parentIndex) {
- var parent = typeof opt_parentIndex === 'number' ?
+ getChangeFileContents(changeId, patchNum, path, opt_parentIndex) {
+ const parent = typeof opt_parentIndex === 'number' ?
'?parent=' + opt_parentIndex : '';
return this._fetchB64File(
'/changes/' + encodeURIComponent(changeId) +
@@ -984,11 +977,11 @@
'/content' + parent);
},
- getImagesForDiff: function(changeNum, diff, patchRange) {
- var promiseA;
- var promiseB;
+ getImagesForDiff(changeNum, diff, patchRange) {
+ let promiseA;
+ let promiseB;
- if (diff.meta_a && diff.meta_a.content_type.indexOf('image/') === 0) {
+ if (diff.meta_a && diff.meta_a.content_type.startsWith('image/')) {
if (patchRange.basePatchNum === 'PARENT') {
// Note: we only attempt to get the image from the first parent.
promiseA = this.getChangeFileContents(changeNum, patchRange.patchNum,
@@ -1001,83 +994,82 @@
promiseA = Promise.resolve(null);
}
- if (diff.meta_b && diff.meta_b.content_type.indexOf('image/') === 0) {
+ if (diff.meta_b && diff.meta_b.content_type.startsWith('image/')) {
promiseB = this.getChangeFileContents(changeNum, patchRange.patchNum,
diff.meta_b.name);
} else {
promiseB = Promise.resolve(null);
}
- return Promise.all([promiseA, promiseB])
- .then(function(results) {
- var baseImage = results[0];
- var revisionImage = results[1];
+ return Promise.all([promiseA, promiseB]).then(results => {
+ const baseImage = results[0];
+ const revisionImage = results[1];
- // Sometimes the server doesn't send back the content type.
- if (baseImage) {
- baseImage._expectedType = diff.meta_a.content_type;
- baseImage._name = diff.meta_a.name;
- }
- if (revisionImage) {
- revisionImage._expectedType = diff.meta_b.content_type;
- revisionImage._name = diff.meta_b.name;
- }
+ // Sometimes the server doesn't send back the content type.
+ if (baseImage) {
+ baseImage._expectedType = diff.meta_a.content_type;
+ baseImage._name = diff.meta_a.name;
+ }
+ if (revisionImage) {
+ revisionImage._expectedType = diff.meta_b.content_type;
+ revisionImage._name = diff.meta_b.name;
+ }
- return {baseImage: baseImage, revisionImage: revisionImage};
- }.bind(this));
+ return {baseImage, revisionImage};
+ });
},
- setChangeTopic: function(changeNum, topic) {
+ setChangeTopic(changeNum, topic) {
return this.send('PUT', '/changes/' + encodeURIComponent(changeNum) +
- '/topic', {topic: topic});
+ '/topic', {topic});
},
- deleteAccountHttpPassword: function() {
+ deleteAccountHttpPassword() {
return this.send('DELETE', '/accounts/self/password.http');
},
- generateAccountHttpPassword: function() {
+ generateAccountHttpPassword() {
return this.send('PUT', '/accounts/self/password.http', {generate: true})
.then(this.getResponseObject);
},
- getAccountSSHKeys: function() {
+ getAccountSSHKeys() {
return this._fetchSharedCacheURL('/accounts/self/sshkeys');
},
- addAccountSSHKey: function(key) {
+ addAccountSSHKey(key) {
return this.send('POST', '/accounts/self/sshkeys', key, null, null,
'plain/text')
- .then(function(response) {
+ .then(response => {
if (response.status < 200 && response.status >= 300) {
return Promise.reject();
}
return this.getResponseObject(response);
- }.bind(this))
- .then(function(obj) {
+ })
+ .then(obj => {
if (!obj.valid) { return Promise.reject(); }
return obj;
});
},
- deleteAccountSSHKey: function(id) {
+ deleteAccountSSHKey(id) {
return this.send('DELETE', '/accounts/self/sshkeys/' + id);
},
- deleteVote: function(changeID, account, label) {
+ deleteVote(changeID, account, label) {
return this.send('DELETE', '/changes/' + changeID +
'/reviewers/' + account + '/votes/' + encodeURIComponent(label));
},
- setDescription: function(changeNum, patchNum, desc) {
+ setDescription(changeNum, patchNum, desc) {
return this.send('PUT',
this.getChangeActionURL(changeNum, patchNum, '/description'),
{description: desc});
},
- confirmEmail: function(token) {
- return this.send('PUT', '/config/server/email.confirm', {token: token})
- .then(function(response) {
+ confirmEmail(token) {
+ return this.send('PUT', '/config/server/email.confirm', {token})
+ .then(response => {
if (response.status === 204) {
return 'Email confirmed successfully.';
}
@@ -1085,39 +1077,39 @@
});
},
- setAssignee: function(changeNum, assignee) {
+ setAssignee(changeNum, assignee) {
return this.send('PUT',
this.getChangeActionURL(changeNum, null, '/assignee'),
- {assignee: assignee});
+ {assignee});
},
- deleteAssignee: function(changeNum) {
+ deleteAssignee(changeNum) {
return this.send('DELETE',
this.getChangeActionURL(changeNum, null, '/assignee'));
},
- probePath: function(path) {
+ probePath(path) {
return fetch(new Request(path, {method: 'HEAD'}))
- .then(function(response) {
- return response.ok;
- });
+ .then(response => {
+ return response.ok;
+ });
},
- startWorkInProgress: function(changeNum, opt_message) {
- var payload = {};
+ startWorkInProgress(changeNum, opt_message) {
+ const payload = {};
if (opt_message) {
payload.message = opt_message;
}
- var url = this.getChangeActionURL(changeNum, null, '/wip');
+ const url = this.getChangeActionURL(changeNum, null, '/wip');
return this.send('POST', url, payload)
- .then(function(response) {
+ .then(response => {
if (response.status === 204) {
return 'Change marked as Work In Progress.';
}
});
},
- startReview: function(changeNum, review) {
+ startReview(changeNum, review) {
return this.send(
'POST', this.getChangeActionURL(changeNum, null, '/ready'), review);
},
diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface_test.html b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface_test.html
index 933b4f4..1ff27d8 100644
--- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface_test.html
+++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface_test.html
@@ -614,7 +614,7 @@
);
});
- test('startWorkInProgress', function() {
+ test('startWorkInProgress', () => {
sandbox.stub(element, 'send').returns(Promise.resolve('ok'));
element.startWorkInProgress('42');
assert.isTrue(element.send.calledWith(
@@ -624,7 +624,7 @@
'POST', '/changes/42/wip', {message: 'revising...'}));
});
- test('startReview', function() {
+ test('startReview', () => {
sandbox.stub(element, 'send').returns(Promise.resolve({}));
element.startReview('42', {message: 'Please review.'});
assert.isTrue(element.send.calledWith(
diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-reviewer-updates-parser.js b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-reviewer-updates-parser.js
index 21a6bc6..4f8deab 100644
--- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-reviewer-updates-parser.js
+++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-reviewer-updates-parser.js
@@ -21,7 +21,7 @@
// TODO (viktard): Polyfill Object.assign for IE.
this.result = Object.assign({}, change);
this._lastState = {};
- };
+ }
GrReviewerUpdatesParser.parse = function(change) {
if (!change ||
@@ -30,7 +30,7 @@
!change.reviewer_updates.length) {
return change;
}
- var parser = new GrReviewerUpdatesParser(change);
+ const parser = new GrReviewerUpdatesParser(change);
parser._filterRemovedMessages();
parser._groupUpdates();
parser._formatUpdates();
@@ -49,7 +49,7 @@
* are used.
*/
GrReviewerUpdatesParser.prototype._filterRemovedMessages = function() {
- this.result.messages = this.result.messages.filter(function(message) {
+ this.result.messages = this.result.messages.filter(message => {
return message.tag !== 'autogenerated:gerrit:deleteReviewer';
});
};
@@ -74,10 +74,10 @@
* @param {Object} update instance of ReviewerUpdateInfo
*/
GrReviewerUpdatesParser.prototype._completeBatch = function(update) {
- var items = [];
- for (var accountId in this._updateItems) {
+ const items = [];
+ for (const accountId in this._updateItems) {
if (!this._updateItems.hasOwnProperty(accountId)) continue;
- var updateItem = this._updateItems[accountId];
+ const updateItem = this._updateItems[accountId];
if (this._lastState[accountId] !== updateItem.state) {
this._lastState[accountId] = updateItem.state;
items.push(updateItem);
@@ -96,14 +96,14 @@
* - Groups with no-change updates are discarded (eg CC -> CC)
*/
GrReviewerUpdatesParser.prototype._groupUpdates = function() {
- var updates = this.result.reviewer_updates;
- var newUpdates = updates.reduce(function(newUpdates, update) {
+ const updates = this.result.reviewer_updates;
+ const newUpdates = updates.reduce((newUpdates, update) => {
if (!this._batch) {
this._batch = this._startBatch(update);
}
- var updateDate = util.parseDate(update.updated).getTime();
- var batchUpdateDate = util.parseDate(this._batch.date).getTime();
- var reviewerId = update.reviewer._account_id.toString();
+ const updateDate = util.parseDate(update.updated).getTime();
+ const batchUpdateDate = util.parseDate(this._batch.date).getTime();
+ const reviewerId = update.reviewer._account_id.toString();
if (updateDate - batchUpdateDate >
GrReviewerUpdatesParser.REVIEWER_UPDATE_THRESHOLD_MILLIS ||
update.updated_by._account_id !== this._batch.author._account_id) {
@@ -122,7 +122,7 @@
this._updateItems[reviewerId].prev_state = this._lastState[reviewerId];
}
return newUpdates;
- }.bind(this), []);
+ }, []);
this._completeBatch();
if (this._batch.updates && this._batch.updates.length) {
newUpdates.push(this._batch);
@@ -157,14 +157,14 @@
* @return {!Object} Hash of arrays of AccountInfo, message as key.
*/
GrReviewerUpdatesParser.prototype._groupUpdatesByMessage = function(updates) {
- return updates.reduce(function(result, item) {
- var message = this._getUpdateMessage(item.prev_state, item.state);
+ return updates.reduce((result, item) => {
+ const message = this._getUpdateMessage(item.prev_state, item.state);
if (!result[message]) {
result[message] = [];
}
result[message].push(item.reviewer);
return result;
- }.bind(this), {});
+ }, {});
};
/**
@@ -173,21 +173,20 @@
* @see https://gerrit-review.googlesource.com/c/94490/
*/
GrReviewerUpdatesParser.prototype._formatUpdates = function() {
- this.result.reviewer_updates.forEach(function(update) {
- var grouppedReviewers = this._groupUpdatesByMessage(update.updates);
- var newUpdates = [];
- for (var message in grouppedReviewers) {
+ for (const update of this.result.reviewer_updates) {
+ const grouppedReviewers = this._groupUpdatesByMessage(update.updates);
+ const newUpdates = [];
+ for (const message in grouppedReviewers) {
if (grouppedReviewers.hasOwnProperty(message)) {
newUpdates.push({
- message: message,
+ message,
reviewers: grouppedReviewers[message],
});
}
}
update.updates = newUpdates;
- }.bind(this));
+ }
};
window.GrReviewerUpdatesParser = GrReviewerUpdatesParser;
-
})(window);
diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/mock-diff-response_test.html b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/mock-diff-response_test.html
index 8141c8a..0385f64 100644
--- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/mock-diff-response_test.html
+++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/mock-diff-response_test.html
@@ -22,44 +22,44 @@
(function() {
'use strict';
- var RESPONSE = {
- 'meta_a': {
- 'name': 'lorem-ipsum.txt',
- 'content_type': 'text/plain',
- 'lines': 45,
+ const RESPONSE = {
+ meta_a: {
+ name: 'lorem-ipsum.txt',
+ content_type: 'text/plain',
+ lines: 45,
},
- 'meta_b': {
- 'name': 'lorem-ipsum.txt',
- 'content_type': 'text/plain',
- 'lines': 48,
+ meta_b: {
+ name: 'lorem-ipsum.txt',
+ content_type: 'text/plain',
+ lines: 48,
},
- 'intraline_status': 'OK',
- 'change_type': 'MODIFIED',
- 'diff_header': [
+ intraline_status: 'OK',
+ change_type: 'MODIFIED',
+ diff_header: [
'diff --git a/lorem-ipsum.txt b/lorem-ipsum.txt',
'index b2adcf4..554ae49 100644',
'--- a/lorem-ipsum.txt',
'+++ b/lorem-ipsum.txt',
],
- 'content': [
+ content: [
{
- 'ab': [
+ ab: [
'Lorem ipsum dolor sit amet, suspendisse inceptos vehicula, ' +
'nulla phasellus.',
'Mattis lectus.',
'Sodales duis.',
'Orci a faucibus.',
- ]
+ ],
},
{
- 'b': [
+ b: [
'Nullam neque, ligula ac, id blandit.',
'Sagittis tincidunt torquent, tempor nunc amet.',
'At rhoncus id.',
],
},
{
- 'ab': [
+ ab: [
'Sem nascetur, erat ut, non in.',
'A donec, venenatis pellentesque dis.',
'Mauris mauris.',
@@ -68,7 +68,7 @@
],
},
{
- 'a': [
+ a: [
'Est amet, vestibulum pellentesque.',
'Erat ligula.',
'Justo eros.',
@@ -76,25 +76,25 @@
],
},
{
- 'ab': [
+ ab: [
'Arcu eget, rhoncus amet cursus, ipsum elementum.',
'Eros suspendisse.',
],
},
{
- 'a': [
+ a: [
'Rhoncus tempor, ultricies aliquam ipsum.',
],
- 'b': [
+ b: [
'Rhoncus tempor, ultricies praesent ipsum.',
],
- 'edit_a': [
+ edit_a: [
[
26,
7,
],
],
- 'edit_b': [
+ edit_b: [
[
26,
8,
@@ -102,7 +102,7 @@
],
},
{
- 'ab': [
+ ab: [
'Sollicitudin duis.',
'Blandit blandit, ante nisl fusce.',
'Felis ac at, tellus consectetuer.',
@@ -131,7 +131,7 @@
],
},
{
- 'b': [
+ b: [
'Eu congue risus.',
'Enim ac, quis elementum.',
'Non et elit.',
@@ -139,7 +139,7 @@
],
},
{
- 'ab': [
+ ab: [
'Nec at.',
'Arcu mauris, venenatis lacus fermentum, praesent duis.',
'Pellentesque amet et, tellus duis.',
@@ -155,7 +155,7 @@
properties: {
diffResponse: {
type: Object,
- value: function() {
+ value() {
return RESPONSE;
},
},