From f32e21fe4645555e77e732114328513ad32fe842 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Fri, 16 Sep 2022 16:54:17 +0200 Subject: [PATCH] Fix review points and refactor code --- .github/workflows/release-new-action-version.yml | 2 +- dist/index.js | 12 +++++++----- src/installer.ts | 15 ++++++++------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.github/workflows/release-new-action-version.yml b/.github/workflows/release-new-action-version.yml index 6a29095..e72733e 100644 --- a/.github/workflows/release-new-action-version.yml +++ b/.github/workflows/release-new-action-version.yml @@ -25,4 +25,4 @@ jobs: uses: actions/publish-action@v0.2.0 with: source-tag: ${{ env.TAG_NAME }} - slack-webhook: ${{ secrets.SLACK_WEBHOOK }} \ No newline at end of file + slack-webhook: ${{ secrets.SLACK_WEBHOOK }} diff --git a/dist/index.js b/dist/index.js index 1ea5692..5baa561 100644 --- a/dist/index.js +++ b/dist/index.js @@ -212,8 +212,7 @@ class DotnetVersionResolver { } resolveVersionInput() { return __awaiter(this, void 0, void 0, function* () { - if (!semver_1.default.valid(this.inputVersion) && - !semver_1.default.validRange(this.inputVersion)) { + if (!this.isValidVersion(this.inputVersion)) { throw new Error(`'dotnet-version' was supplied in invalid format: ${this.inputVersion}! Supported syntax: A.B.C, A.B, A.B.x, A, A.x`); } if (semver_1.default.valid(this.inputVersion)) { @@ -222,9 +221,9 @@ class DotnetVersionResolver { } else { const [major, minor] = this.inputVersion.split('.'); - if (this.testTag(major)) { + if (this.isNumericTag(major)) { this.resolvedArgument.type = 'channel'; - if (this.testTag(minor)) { + if (this.isNumericTag(minor)) { this.resolvedArgument.value = `${major}.${minor}`; } else { @@ -239,7 +238,10 @@ class DotnetVersionResolver { } }); } - testTag(versionTag) { + isValidVersion(version) { + return semver_1.default.valid(version) || semver_1.default.validRange(version) ? true : false; + } + isNumericTag(versionTag) { return /^\d+$/.test(versionTag); } createDotNetVersion() { diff --git a/src/installer.ts b/src/installer.ts index ce91177..8f3b16c 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -42,10 +42,7 @@ export class DotnetVersionResolver { } private async resolveVersionInput(): Promise { - if ( - !semver.valid(this.inputVersion) && - !semver.validRange(this.inputVersion) - ) { + if (!this.isValidVersion(this.inputVersion)) { throw new Error( `'dotnet-version' was supplied in invalid format: ${this.inputVersion}! Supported syntax: A.B.C, A.B, A.B.x, A, A.x` ); @@ -56,9 +53,9 @@ export class DotnetVersionResolver { } else { const [major, minor] = this.inputVersion.split('.'); - if (this.testTag(major)) { + if (this.isNumericTag(major)) { this.resolvedArgument.type = 'channel'; - if (this.testTag(minor)) { + if (this.isNumericTag(minor)) { this.resolvedArgument.value = `${major}.${minor}`; } else { const httpClient = new hc.HttpClient('actions/setup-dotnet', [], { @@ -75,7 +72,11 @@ export class DotnetVersionResolver { } } - private testTag(versionTag): Boolean { + private isValidVersion(version) { + return semver.valid(version) || semver.validRange(version) ? true : false; + } + + private isNumericTag(versionTag): Boolean { return /^\d+$/.test(versionTag); }