generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #219 Add argument to allow only updating drafts and prereleases
- Loading branch information
Showing
14 changed files
with
192 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import {ReleaseValidator} from "../src/ReleaseValidator"; | ||
|
||
describe("validateReleaseUpdate", () => { | ||
describe("updateOnlyUnreleased is disabled", () => { | ||
const validator = new ReleaseValidator(false) | ||
it('should not throw', () => { | ||
const releaseResponse = { | ||
draft: false, | ||
prerelease: false, | ||
name: "Name" | ||
} | ||
expect(() => { | ||
validator.validateReleaseUpdate(releaseResponse) | ||
}).not.toThrow() | ||
}) | ||
}) | ||
describe("updateOnlyUnreleased is enabled", () => { | ||
const validator = new ReleaseValidator(true) | ||
it('should throw if neither draft or prerelease are enabled', () => { | ||
const releaseResponse = { | ||
draft: false, | ||
prerelease: false, | ||
name: "Name" | ||
} | ||
expect(() => { | ||
validator.validateReleaseUpdate(releaseResponse) | ||
}).toThrow() | ||
}) | ||
|
||
it('should not throw if draft is enabled', () => { | ||
const releaseResponse = { | ||
draft: true, | ||
prerelease: false, | ||
name: "Name" | ||
} | ||
expect(() => { | ||
validator.validateReleaseUpdate(releaseResponse) | ||
}).not.toThrow() | ||
}) | ||
|
||
it('should not throw if prerelease is enabled', () => { | ||
const releaseResponse = { | ||
draft: false, | ||
prerelease: true, | ||
name: "Name" | ||
} | ||
expect(() => { | ||
validator.validateReleaseUpdate(releaseResponse) | ||
}).not.toThrow() | ||
}) | ||
|
||
it('should not throw if draft & prerelease is enabled', () => { | ||
const releaseResponse = { | ||
draft: true, | ||
prerelease: true, | ||
name: "Name" | ||
} | ||
expect(() => { | ||
validator.validateReleaseUpdate(releaseResponse) | ||
}).not.toThrow() | ||
}) | ||
|
||
it('should default error message release name to release', () => { | ||
const releaseResponse = { | ||
draft: false, | ||
prerelease: false, | ||
name: null | ||
} | ||
expect(() => { | ||
validator.validateReleaseUpdate(releaseResponse) | ||
}).toThrow(`Tried to update "release" which is neither a draft or prerelease. (updateOnlyUnreleased is on)`) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ReleaseValidator = void 0; | ||
class ReleaseValidator { | ||
constructor(updateOnlyUnreleased) { | ||
this.updateOnlyUnreleased = updateOnlyUnreleased; | ||
} | ||
validateReleaseUpdate(releaseResponse) { | ||
var _a; | ||
if (!this.updateOnlyUnreleased) { | ||
return; | ||
} | ||
if (!releaseResponse.draft && !releaseResponse.prerelease) { | ||
throw new Error(`Tried to update "${(_a = releaseResponse.name) !== null && _a !== void 0 ? _a : "release"}" which is neither a draft or prerelease. (updateOnlyUnreleased is on)`); | ||
} | ||
} | ||
} | ||
exports.ReleaseValidator = ReleaseValidator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export class ReleaseValidator { | ||
constructor(private updateOnlyUnreleased: boolean) { | ||
} | ||
|
||
validateReleaseUpdate(releaseResponse: ReleaseStageArguments) { | ||
if (!this.updateOnlyUnreleased) { | ||
return | ||
} | ||
|
||
if (!releaseResponse.draft && !releaseResponse.prerelease) { | ||
throw new Error(`Tried to update "${releaseResponse.name ?? "release"}" which is neither a draft or prerelease. (updateOnlyUnreleased is on)`) | ||
} | ||
} | ||
} | ||
|
||
export type ReleaseStageArguments = { | ||
draft: boolean | ||
name: string | null | ||
prerelease: boolean | ||
} |