Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ui/add changelog link #9216

Merged
merged 9 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]) {
chelshaw marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea what all the various versions look like from the perspective of the UI (like the HSM ones). So, I can't comment if this will work in all cases, which is my only concern.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, we're not totally sure what all of the versions look like either which is why i wrapped this in a try block. this way, if we encounter any versions that don't meet the expected format we'll catch the error log the version. if anything fails we default to the regular 'ol changelog which should prevent users from having to deal with broken links.

.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);
});
});