Ui/add changelog link (#9216)
* link to changelog in version * link to specific changelog version number * update CHANGELOG headings to match expected format * clean up and add tests * handle errors * use https * update test url
This commit is contained in:
parent
e8db47f92d
commit
88a0e432e8
|
@ -10,7 +10,10 @@
|
|||
© {{date-format (now) "YYYY"}} HashiCorp
|
||||
</span>
|
||||
<span>
|
||||
Vault {{activeCluster.leaderNode.version}}
|
||||
<a href={{changelog-url-for activeCluster.leaderNode.version}}
|
||||
class="link has-text-grey">
|
||||
Vault {{activeCluster.leaderNode.version}}
|
||||
</a>
|
||||
</span>
|
||||
{{#if (is-version "OSS")}}
|
||||
<span>
|
||||
|
|
37
ui/lib/core/addon/helpers/changelog-url-for.js
Normal file
37
ui/lib/core/addon/helpers/changelog-url-for.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
import { helper } from '@ember/component/helper';
|
||||
|
||||
/*
|
||||
This helper returns a url to the changelog for the specified version.
|
||||
It assumes that Changelog headers for Vault versions >= 1.4.3 are structured as:
|
||||
|
||||
## v1.5.0
|
||||
### Month, DD, YYYY
|
||||
|
||||
## v1.4.5
|
||||
### Month, DD, YYY
|
||||
|
||||
etc.
|
||||
*/
|
||||
|
||||
export function changelogUrlFor([version]) {
|
||||
let url = 'https://www.github.com/hashicorp/vault/blob/master/CHANGELOG.md#';
|
||||
|
||||
try {
|
||||
// strip the '+prem' from enterprise versions and remove periods
|
||||
let versionNumber = version
|
||||
.split('+')[0]
|
||||
.split('.')
|
||||
.join('');
|
||||
|
||||
// only recent versions have a predictable url
|
||||
if (versionNumber >= '143') {
|
||||
return url.concat('v', versionNumber);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
console.log('Cannot generate URL for version: ', version);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
export default helper(changelogUrlFor);
|
1
ui/lib/core/app/helpers/changelog-url-for.js
Normal file
1
ui/lib/core/app/helpers/changelog-url-for.js
Normal file
|
@ -0,0 +1 @@
|
|||
export { default, changelogUrlFor } from 'core/helpers/changelog-url-for';
|
29
ui/tests/integration/helpers/changelog-url-for-test.js
Normal file
29
ui/tests/integration/helpers/changelog-url-for-test.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'ember-qunit';
|
||||
import { changelogUrlFor } from '../../../helpers/changelog-url-for';
|
||||
|
||||
const CHANGELOG_URL = 'https://www.github.com/hashicorp/vault/blob/master/CHANGELOG.md#';
|
||||
|
||||
module('Integration | Helper | changelog-url-for', function(hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it builds an enterprise URL', function(assert) {
|
||||
const result = changelogUrlFor(['1.5.0+prem']);
|
||||
assert.equal(result, CHANGELOG_URL.concat('v150'));
|
||||
});
|
||||
|
||||
test('it builds an OSS URL', function(assert) {
|
||||
const result = changelogUrlFor(['1.4.3']);
|
||||
assert.equal(result, CHANGELOG_URL.concat('v143'));
|
||||
});
|
||||
|
||||
test('it returns the base changelog URL if the version is less than 1.4.3', function(assert) {
|
||||
const result = changelogUrlFor(['1.4.0']);
|
||||
assert.equal(result, CHANGELOG_URL);
|
||||
});
|
||||
|
||||
test('it returns the base changelog URL if version cannot be found', function(assert) {
|
||||
const result = changelogUrlFor(['']);
|
||||
assert.equal(result, CHANGELOG_URL);
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue