Skip to content

Commit

Permalink
Ui/add changelog link (#9216)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Noelle Daley authored and andaley committed Jun 23, 2020
1 parent 8a3cbf0 commit 9f2f1a9
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ui/app/templates/vault.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
37 changes: 37 additions & 0 deletions ui/lib/core/addon/helpers/changelog-url-for.js
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions ui/lib/core/app/helpers/changelog-url-for.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default, changelogUrlFor } from 'core/helpers/changelog-url-for';
29 changes: 29 additions & 0 deletions ui/tests/integration/helpers/changelog-url-for-test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit 9f2f1a9

Please sign in to comment.