ES6ify /gr-commit-info/*
Bug: Issue 6179 Change-Id: If69916b8dc45160813e2690dee706dd15d972c89
This commit is contained in:
@@ -31,13 +31,13 @@
|
||||
},
|
||||
},
|
||||
|
||||
_isWebLink: function(link) {
|
||||
_isWebLink(link) {
|
||||
// This is a whitelist of web link types that provide direct links to
|
||||
// the commit in the url property.
|
||||
return link.name === 'gitiles' || link.name === 'gitweb';
|
||||
},
|
||||
|
||||
_computeShowWebLink: function(change, commitInfo, serverConfig) {
|
||||
_computeShowWebLink(change, commitInfo, serverConfig) {
|
||||
if (serverConfig.gitweb && serverConfig.gitweb.url &&
|
||||
serverConfig.gitweb.type && serverConfig.gitweb.type.revision) {
|
||||
return true;
|
||||
@@ -47,8 +47,8 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < commitInfo.web_links.length; i++) {
|
||||
if (this._isWebLink(commitInfo.web_links[i])) {
|
||||
for (const link of commitInfo.web_links) {
|
||||
if (this._isWebLink(link)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@
|
||||
return false;
|
||||
},
|
||||
|
||||
_computeWebLink: function(change, commitInfo, serverConfig) {
|
||||
_computeWebLink(change, commitInfo, serverConfig) {
|
||||
if (!this._computeShowWebLink(change, commitInfo, serverConfig)) {
|
||||
return;
|
||||
}
|
||||
@@ -69,10 +69,10 @@
|
||||
.replace('${commit}', commitInfo.commit);
|
||||
}
|
||||
|
||||
var webLink = null;
|
||||
for (var i = 0; i < commitInfo.web_links.length; i++) {
|
||||
if (this._isWebLink(commitInfo.web_links[i])) {
|
||||
webLink = commitInfo.web_links[i].url;
|
||||
let webLink = null;
|
||||
for (const link of commitInfo.web_links) {
|
||||
if (this._isWebLink(link)) {
|
||||
webLink = link.url;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -88,7 +88,7 @@
|
||||
return webLink;
|
||||
},
|
||||
|
||||
_computeShortHash: function(commitInfo) {
|
||||
_computeShortHash(commitInfo) {
|
||||
if (!commitInfo || !commitInfo.commit) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -33,14 +33,14 @@ limitations under the License.
|
||||
</test-fixture>
|
||||
|
||||
<script>
|
||||
suite('gr-commit-info tests', function() {
|
||||
var element;
|
||||
suite('gr-commit-info tests', () => {
|
||||
let element;
|
||||
|
||||
setup(function() {
|
||||
setup(() => {
|
||||
element = fixture('basic');
|
||||
});
|
||||
|
||||
test('no web link when unavailable', function() {
|
||||
test('no web link when unavailable', () => {
|
||||
element.commitInfo = {};
|
||||
element.serverConfig = {};
|
||||
element.change = {labels: []};
|
||||
@@ -49,7 +49,7 @@ limitations under the License.
|
||||
element.commitInfo, element.serverConfig));
|
||||
});
|
||||
|
||||
test('use web link when available', function() {
|
||||
test('use web link when available', () => {
|
||||
element.commitInfo = {web_links: [{name: 'gitweb', url: 'link-url'}]};
|
||||
element.serverConfig = {};
|
||||
|
||||
@@ -59,9 +59,9 @@ limitations under the License.
|
||||
element.serverConfig), '../../link-url');
|
||||
});
|
||||
|
||||
test('does not relativize web links that begin with scheme', function() {
|
||||
test('does not relativize web links that begin with scheme', () => {
|
||||
element.commitInfo = {
|
||||
web_links: [{name: 'gitweb', url: 'https://link-url'}]
|
||||
web_links: [{name: 'gitweb', url: 'https://link-url'}],
|
||||
};
|
||||
element.serverConfig = {};
|
||||
|
||||
@@ -71,7 +71,7 @@ limitations under the License.
|
||||
element.serverConfig), 'https://link-url');
|
||||
});
|
||||
|
||||
test('use gitweb when available', function() {
|
||||
test('use gitweb when available', () => {
|
||||
element.commitInfo = {commit: 'commit-sha'};
|
||||
element.serverConfig = {gitweb: {
|
||||
url: 'url-base/',
|
||||
@@ -80,7 +80,7 @@ limitations under the License.
|
||||
element.change = {
|
||||
project: 'project-name',
|
||||
labels: [],
|
||||
current_revision: element.commitInfo.commit
|
||||
current_revision: element.commitInfo.commit,
|
||||
};
|
||||
|
||||
assert.isOk(element._computeShowWebLink(element.change,
|
||||
@@ -90,10 +90,10 @@ limitations under the License.
|
||||
element.serverConfig), 'url-base/xx project-name xx commit-sha xx');
|
||||
});
|
||||
|
||||
test('prefer gitweb when both are available', function() {
|
||||
test('prefer gitweb when both are available', () => {
|
||||
element.commitInfo = {
|
||||
commit: 'commit-sha',
|
||||
web_links: [{url: 'link-url'}]
|
||||
web_links: [{url: 'link-url'}],
|
||||
};
|
||||
element.serverConfig = {gitweb: {
|
||||
url: 'url-base/',
|
||||
@@ -102,20 +102,20 @@ limitations under the License.
|
||||
element.change = {
|
||||
project: 'project-name',
|
||||
labels: [],
|
||||
current_revision: element.commitInfo.commit
|
||||
current_revision: element.commitInfo.commit,
|
||||
};
|
||||
|
||||
assert.isOk(element._computeShowWebLink(element.change,
|
||||
element.commitInfo, element.serverConfig));
|
||||
|
||||
var link = element._computeWebLink(element.change, element.commitInfo,
|
||||
const link = element._computeWebLink(element.change, element.commitInfo,
|
||||
element.serverConfig);
|
||||
|
||||
assert.equal(link, 'url-base/xx project-name xx commit-sha xx');
|
||||
assert.notEqual(link, '../../link-url');
|
||||
});
|
||||
|
||||
test('ignore web links that are neither gitweb nor gitiles', function() {
|
||||
test('ignore web links that are neither gitweb nor gitiles', () => {
|
||||
element.commitInfo = {
|
||||
commit: 'commit-sha',
|
||||
web_links: [
|
||||
@@ -126,7 +126,7 @@ limitations under the License.
|
||||
{
|
||||
name: 'gitiles',
|
||||
url: 'https://link-url',
|
||||
}
|
||||
},
|
||||
],
|
||||
};
|
||||
element.serverConfig = {};
|
||||
|
||||
Reference in New Issue
Block a user