Fix review points and refactor code

This commit is contained in:
IvanZosimov 2022-09-16 16:54:17 +02:00
parent 48a8ae427d
commit f32e21fe46
3 changed files with 16 additions and 13 deletions

12
dist/index.js vendored
View File

@ -212,8 +212,7 @@ class DotnetVersionResolver {
} }
resolveVersionInput() { resolveVersionInput() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
if (!semver_1.default.valid(this.inputVersion) && if (!this.isValidVersion(this.inputVersion)) {
!semver_1.default.validRange(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`); 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)) { if (semver_1.default.valid(this.inputVersion)) {
@ -222,9 +221,9 @@ class DotnetVersionResolver {
} }
else { else {
const [major, minor] = this.inputVersion.split('.'); const [major, minor] = this.inputVersion.split('.');
if (this.testTag(major)) { if (this.isNumericTag(major)) {
this.resolvedArgument.type = 'channel'; this.resolvedArgument.type = 'channel';
if (this.testTag(minor)) { if (this.isNumericTag(minor)) {
this.resolvedArgument.value = `${major}.${minor}`; this.resolvedArgument.value = `${major}.${minor}`;
} }
else { 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); return /^\d+$/.test(versionTag);
} }
createDotNetVersion() { createDotNetVersion() {

View File

@ -42,10 +42,7 @@ export class DotnetVersionResolver {
} }
private async resolveVersionInput(): Promise<void> { private async resolveVersionInput(): Promise<void> {
if ( if (!this.isValidVersion(this.inputVersion)) {
!semver.valid(this.inputVersion) &&
!semver.validRange(this.inputVersion)
) {
throw new Error( 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` `'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 { } else {
const [major, minor] = this.inputVersion.split('.'); const [major, minor] = this.inputVersion.split('.');
if (this.testTag(major)) { if (this.isNumericTag(major)) {
this.resolvedArgument.type = 'channel'; this.resolvedArgument.type = 'channel';
if (this.testTag(minor)) { if (this.isNumericTag(minor)) {
this.resolvedArgument.value = `${major}.${minor}`; this.resolvedArgument.value = `${major}.${minor}`;
} else { } else {
const httpClient = new hc.HttpClient('actions/setup-dotnet', [], { 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); return /^\d+$/.test(versionTag);
} }