Skip to content
Snippets Groups Projects
Unverified Commit e622519f authored by Jeff Evans's avatar Jeff Evans Committed by GitHub
Browse files

Change implementation of docsUrl to handle RC suffixes for EE versions (#18270)

Change implementation of docsUrl to handle RC suffixes for EE versions

Change the regex used to test the tag to detect any OSS or EE version, including (possibly) an arbitrary suffix after the major and minor parts, and normalize to the major OSS equivalent version instead.  If the suffix, OTOH, is `-SNAPSHOT` (ignoring case), then the doc tag will be `latest`, on the theory that this is as local development build.

v0.41.0 => v0.41
v1.41.1 => v0.41
v1.41.2-RC1 => v0.41
v1.42.0-SNAPSHOT => latest

Adding unit tests for all cases

Update behavior so that -SNAPSHOT suffix points to "latest"
parent 7bf63107
No related branches found
No related tags found
No related merge requests found
......@@ -134,11 +134,21 @@ class Settings {
docsUrl(page = "", anchor = "") {
let { tag } = this.get("version", {});
if (/^v1\.\d+\.\d+$/.test(tag)) {
// if it's a normal EE version, link to the corresponding CE docs
tag = tag.replace("v1", "v0");
} else if (!tag || /v1/.test(tag) || /SNAPSHOT$/.test(tag)) {
// if there's no tag or it's an EE version that might not have a matching CE version, or it's a local build, link to latest
const matches = tag.match(/v[01]\.(\d+)(?:\.\d+)?(-.*)?/);
if (matches) {
if (
matches.length > 2 &&
matches[2] &&
"-snapshot" === matches[2].toLowerCase()
) {
// always point -SNAPSHOT suffixes to "latest", since this is likely a development build off of master
tag = "latest";
} else {
// otherwise, it's a regular OSS or EE version string, just link to the major OSS doc link
tag = "v0." + matches[1];
}
} else {
// otherwise, just link to the latest tag
tag = "latest";
}
if (page) {
......
import MetabaseSettings from "metabase/lib/settings";
function withTempSetting(settingName, settingValue, thunk) {
const origVal = MetabaseSettings.get(settingName);
MetabaseSettings.set(settingName, settingValue);
try {
thunk();
} finally {
MetabaseSettings.set(settingName, origVal);
}
}
describe("MetabaseSettings.docsUrl", () => {
// all of these should point to the same doc URL
[
["v0.41.0", "v0.41"],
["v0.41.1-SNAPSHOT", "latest"],
["v0.41.2-rc1", "v0.41"],
["v0.41.3-RC2", "v0.41"],
["v1.41.4", "v0.41"],
["v1.41.3-snapshot", "latest"],
["v1.41.2-rc1", "v0.41"],
["v1.41.1-RANDOM-SUFFIX", "v0.41"],
].forEach(v => {
it("handles version " + v[0] + " by pointing it to " + v[1], () => {
withTempSetting("version", { tag: v[0] }, () => {
expect(MetabaseSettings.docsUrl()).toBe(
"https://www.metabase.com/docs/" + v[1] + "/",
);
});
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment