Fix short commit hash link

- Only relativize the commit link if the link does not start with a
  scheme.
- The link text now reflects the SHA-1 of the current revision rather
  than that of the latest revision.

Bug: Issue 4174
Change-Id: Ie66809ce951df6bb8b686bd7fa4ecb4328fb9d1d
This commit is contained in:
Wyatt Allen 2016-06-08 11:52:01 -07:00 committed by Logan Hanks
parent e7d7282284
commit 59b7e5ebe2
3 changed files with 20 additions and 5 deletions

View File

@ -110,10 +110,10 @@ limitations under the License.
<span class="value">
<template is="dom-if" if="[[_showWebLink]]">
<a target="_blank"
href$="[[_webLink]]">[[_computeShortHash(change)]]</a>
href$="[[_webLink]]">[[_computeShortHash(commitInfo)]]</a>
</template>
<template is="dom-if" if="[[!_showWebLink]]">
[[_computeShortHash(change)]]
[[_computeShortHash(commitInfo)]]
</template>
</span>
</section>

View File

@ -68,11 +68,16 @@
.replace('${commit}', commitInfo.commit);
}
return '../../' + commitInfo.web_links[0].url;
var webLink = commitInfo.web_links[0].url;
if (!/^https?\:\/\//.test(webLink)) {
webLink = '../../' + webLink;
}
return webLink;
},
_computeShortHash: function(change) {
return change.current_revision.slice(0, 7);
_computeShortHash: function(commitInfo) {
return commitInfo.commit.slice(0, 7);
},
_computeHideStrategy: function(change) {

View File

@ -87,6 +87,16 @@ limitations under the License.
element.serverConfig), '../../link-url');
});
test('does not relativize web links that begin with scheme', function() {
element.commitInfo = {web_links: [{url: 'https://link-url'}]};
element.serverConfig = {};
assert.isOk(element._computeShowWebLink(element.change,
element.commitInfo, element.serverConfig));
assert.equal(element._computeWebLink(element.change, element.commitInfo,
element.serverConfig), 'https://link-url');
});
test('use gitweb when available', function() {
element.commitInfo = {commit: 'commit-sha'};
element.serverConfig = {gitweb: {