Add project to changeBaseURL calls

Gerrit.RESTClientBehavior provides a changeBaseURL method that is
currently only used to construct download links. These links need to
incorporate the project of the change into their hrefs. Since all call
sites have a change detail object in scope, we can just pass the project
name directly to changeBaseURL.

Change-Id: I899c1e486f20b0097d1aa9617d9944909a3a528f
(cherry picked from commit 90b4dc4803)
This commit is contained in:
Logan Hanks
2018-10-30 09:40:22 -07:00
committed by David Pursehouse
parent 6cd6fad3e1
commit 537b7336fe
7 changed files with 15 additions and 13 deletions

View File

@@ -110,8 +110,9 @@ limitations under the License.
/** /**
* @return {string} * @return {string}
*/ */
changeBaseURL(changeNum, patchNum) { changeBaseURL(project, changeNum, patchNum) {
let v = this.getBaseUrl() + '/changes/' + changeNum; let v = this.getBaseUrl() + '/changes/' +
encodeURIComponent(project) + '~' + changeNum;
if (patchNum) { if (patchNum) {
v += '/revisions/' + patchNum; v += '/revisions/' + patchNum;
} }

View File

@@ -68,8 +68,8 @@ limitations under the License.
test('changeBaseURL', () => { test('changeBaseURL', () => {
assert.deepEqual( assert.deepEqual(
element.changeBaseURL('1', '1'), element.changeBaseURL('test/project', '1', '2'),
'/r/changes/1/revisions/1' '/r/changes/test%2Fproject~1/revisions/2'
); );
}); });

View File

@@ -115,8 +115,8 @@
* @return {string} Not sure why there was a mismatch * @return {string} Not sure why there was a mismatch
*/ */
_computeDownloadLink(change, patchNum, opt_zip) { _computeDownloadLink(change, patchNum, opt_zip) {
return this.changeBaseURL(change._number, patchNum) + '/patch?' + return this.changeBaseURL(change.project, change._number, patchNum) +
(opt_zip ? 'zip' : 'download'); '/patch?' + (opt_zip ? 'zip' : 'download');
}, },
@@ -139,7 +139,7 @@
}, },
_computeArchiveDownloadLink(change, patchNum, format) { _computeArchiveDownloadLink(change, patchNum, format) {
return this.changeBaseURL(change._number, patchNum) + return this.changeBaseURL(change.project, change._number, patchNum) +
'/archive?format=' + format; '/archive?format=' + format;
}, },

View File

@@ -172,8 +172,8 @@ limitations under the License.
test('computed fields', () => { test('computed fields', () => {
assert.equal(element._computeArchiveDownloadLink( assert.equal(element._computeArchiveDownloadLink(
{_number: 123}, 2, 'tgz'), {project: 'test/project', _number: 123}, 2, 'tgz'),
'/changes/123/revisions/2/archive?format=tgz'); '/changes/test%2Fproject~123/revisions/2/archive?format=tgz');
}); });
test('close event', done => { test('close event', done => {

View File

@@ -269,7 +269,7 @@ limitations under the License.
<a <a
class="downloadLink" class="downloadLink"
download download
href$="[[_computeDownloadLink(_changeNum, _patchRange, _path)]]"> href$="[[_computeDownloadLink(_change.project, _changeNum, _patchRange, _path)]]">
Download Download
</a> </a>
</span> </span>

View File

@@ -883,8 +883,8 @@
history.replaceState(null, '', url); history.replaceState(null, '', url);
}, },
_computeDownloadLink(changeNum, patchRange, path) { _computeDownloadLink(project, changeNum, patchRange, path) {
let url = this.changeBaseURL(changeNum, patchRange.patchNum); let url = this.changeBaseURL(project, changeNum, patchRange.patchNum);
url += '/patch?zip&path=' + encodeURIComponent(path); url += '/patch?zip&path=' + encodeURIComponent(path);
return url; return url;
}, },

View File

@@ -556,6 +556,7 @@ limitations under the License.
}); });
test('download link', () => { test('download link', () => {
element._change = {project: 'test'},
element._changeNum = '42'; element._changeNum = '42';
element._patchRange = { element._patchRange = {
basePatchNum: PARENT, basePatchNum: PARENT,
@@ -566,7 +567,7 @@ limitations under the License.
flushAsynchronousOperations(); flushAsynchronousOperations();
const link = element.$$('.downloadLink'); const link = element.$$('.downloadLink');
assert.equal(link.getAttribute('href'), assert.equal(link.getAttribute('href'),
'/changes/42/revisions/10/patch?zip&path=glados.txt'); '/changes/test~42/revisions/10/patch?zip&path=glados.txt');
assert.isTrue(link.hasAttribute('download')); assert.isTrue(link.hasAttribute('download'));
}); });