mirror of
https://github.com/alibaba/open-code-review.git
synced 2026-08-23 15:44:34 +00:00
Some checks are pending
CI / test (push) Waiting to run
CI / windows (push) Waiting to run
CI / cross-compile (amd64, darwin) (push) Waiting to run
CI / cross-compile (amd64, windows) (push) Waiting to run
CI / cross-compile (arm64, darwin) (push) Waiting to run
CI / cross-compile (arm64, linux) (push) Waiting to run
CI / cross-compile (arm64, windows) (push) Waiting to run
CodeQL Advanced / Analyze (go) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
// SPDX-License-Identifier: Apache-2.0
|
|
// Copyright 2026 alibaba/open-code-review Contributors
|
|
|
|
"use strict";
|
|
|
|
const SEMVER_RE =
|
|
/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
|
|
function parseVersionOutput(output) {
|
|
const match = String(output || "").match(
|
|
/v(\d+\.\d+(?:\.\d+)?(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?)/
|
|
);
|
|
return match ? match[1] : null;
|
|
}
|
|
|
|
function semverGt(a, b) {
|
|
if (!SEMVER_RE.test(a) || !SEMVER_RE.test(b)) return false;
|
|
|
|
const aWithoutBuild = a.replace(/\+.*$/, "");
|
|
const bWithoutBuild = b.replace(/\+.*$/, "");
|
|
const pa = aWithoutBuild.replace(/-.*$/, "").split(".").map(Number);
|
|
const pb = bWithoutBuild.replace(/-.*$/, "").split(".").map(Number);
|
|
for (let i = 0; i < 3; i++) {
|
|
if (pa[i] > pb[i]) return true;
|
|
if (pa[i] < pb[i]) return false;
|
|
}
|
|
const aPre = aWithoutBuild.includes("-");
|
|
const bPre = bWithoutBuild.includes("-");
|
|
if (bPre && !aPre) return true;
|
|
return false;
|
|
}
|
|
|
|
function shouldShowUpdateHint(hintVersion, installedVersion) {
|
|
if (!SEMVER_RE.test(hintVersion) || !SEMVER_RE.test(installedVersion)) {
|
|
return false;
|
|
}
|
|
return semverGt(hintVersion, installedVersion);
|
|
}
|
|
|
|
module.exports = {
|
|
SEMVER_RE,
|
|
parseVersionOutput,
|
|
semverGt,
|
|
shouldShowUpdateHint,
|
|
};
|