From 76e98d42679e5a1167ebad419ec66abfd70f7a3c Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 2 May 2017 21:12:58 +0100 Subject: [PATCH] improve version hyperlinking removed redundant v prefix (key already says version) links to most applicable version/tag tag-commit -> commit commit1-commit2-commit3 -> commit1 (v)x.y.z -> tag commit -> commit Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/structures/UserSettings.js | 25 +++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index ba5d5780b4..88e6829514 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -32,13 +32,22 @@ import AccessibleButton from '../views/elements/AccessibleButton'; // if this looks like a release, use the 'version' from package.json; else use // the git sha. Prepend version with v, to look like riot-web version -const REACT_SDK_VERSION = 'dist' in package_json ? `v${package_json.version}` : package_json.gitHead || ''; +const REACT_SDK_VERSION = 'dist' in package_json ? package_json.version : package_json.gitHead || ''; // Simple method to help prettify GH Release Tags and Commit Hashes. -const GHVersionUrl = function(repo, token) { - const uriTail = (token.startsWith('v') && token.includes('.')) ? `releases/tag/${token}` : `commit/${token}`; - return `https://github.com/${repo}/${uriTail}`; -} +const semVerRegex = /^v?(\d+\.\d+\.\d+)(?:-(?:\d+-g)?(.+))?|$/i; +const gHVersionLabel = function(repo, token) { + const match = token.match(semVerRegex); + let url; // assume commit hash + if (match && match[1]) { // basic semVer string possibly with commit hash + url = (match.length > 1 && match[2]) + ? `https://github.com/${repo}/commit/${match[2]}` + : `https://github.com/${repo}/releases/tag/v${match[1]}`; + } else { + url = `https://github.com/${repo}/commit/${token.split('-')[0]}`; + } + return {token}; +}; // Enumerate some simple 'flip a bit' UI settings (if any). // 'id' gives the key name in the im.vector.web.settings account data event @@ -911,7 +920,7 @@ module.exports = React.createClass({ // we are using a version old version of olm. We assume the former. let olmVersionString = ""; if (olmVersion !== undefined) { - olmVersionString = `v${olmVersion[0]}.${olmVersion[1]}.${olmVersion[2]}`; + olmVersionString = `${olmVersion[0]}.${olmVersion[1]}.${olmVersion[2]}`; } return ( @@ -995,11 +1004,11 @@ module.exports = React.createClass({
matrix-react-sdk version: {(REACT_SDK_VERSION !== '') - ? {REACT_SDK_VERSION} + ? gHVersionLabel('matrix-org/matrix-react-sdk', REACT_SDK_VERSION) : REACT_SDK_VERSION }
riot-web version: {(this.state.vectorVersion !== null) - ? {this.state.vectorVersion} + ? gHVersionLabel('vector-im/riot-web', this.state.vectorVersion) : 'unknown' }
olm version: {olmVersionString}