mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2026-04-09 07:50:04 +00:00
feat: refactor option validation to list-based approach and add delete+hide_and_recreate check
Co-authored-by: marocchino <128431+marocchino@users.noreply.github.com>
This commit is contained in:
parent
30b108bb4e
commit
da6fd3b3a2
2 changed files with 23 additions and 18 deletions
|
|
@ -115,7 +115,7 @@ describe("run", () => {
|
|||
mockConfig.recreate = true
|
||||
const {core} = await runMain()
|
||||
expect(core.setFailed).toHaveBeenCalledWith(
|
||||
"delete and recreate cannot be both set to true",
|
||||
"delete and recreate cannot be set to true simultaneously",
|
||||
)
|
||||
})
|
||||
|
||||
|
|
@ -124,7 +124,7 @@ describe("run", () => {
|
|||
mockConfig.onlyCreateComment = true
|
||||
const {core} = await runMain()
|
||||
expect(core.setFailed).toHaveBeenCalledWith(
|
||||
"delete and only_create cannot be both set to true",
|
||||
"delete and only_create cannot be set to true simultaneously",
|
||||
)
|
||||
})
|
||||
|
||||
|
|
@ -133,7 +133,7 @@ describe("run", () => {
|
|||
mockConfig.hideOldComment = true
|
||||
const {core} = await runMain()
|
||||
expect(core.setFailed).toHaveBeenCalledWith(
|
||||
"delete and hide cannot be both set to true",
|
||||
"delete and hide cannot be set to true simultaneously",
|
||||
)
|
||||
})
|
||||
|
||||
|
|
@ -151,7 +151,16 @@ describe("run", () => {
|
|||
mockConfig.hideAndRecreate = true
|
||||
const {core} = await runMain()
|
||||
expect(core.setFailed).toHaveBeenCalledWith(
|
||||
"hide and hide_and_recreate cannot be both set to true",
|
||||
"hide and hide_and_recreate cannot be set to true simultaneously",
|
||||
)
|
||||
})
|
||||
|
||||
test("fails when deleteOldComment and hideAndRecreate are both true", async () => {
|
||||
mockConfig.deleteOldComment = true
|
||||
mockConfig.hideAndRecreate = true
|
||||
const {core} = await runMain()
|
||||
expect(core.setFailed).toHaveBeenCalledWith(
|
||||
"delete and hide_and_recreate cannot be set to true simultaneously",
|
||||
)
|
||||
})
|
||||
|
||||
|
|
|
|||
24
src/main.ts
24
src/main.ts
|
|
@ -46,26 +46,22 @@ async function run(): Promise<undefined> {
|
|||
throw new Error("Either message or path input is required")
|
||||
}
|
||||
|
||||
if (deleteOldComment && recreate) {
|
||||
throw new Error("delete and recreate cannot be both set to true")
|
||||
}
|
||||
|
||||
if (deleteOldComment && onlyCreateComment) {
|
||||
throw new Error("delete and only_create cannot be both set to true")
|
||||
}
|
||||
|
||||
if (deleteOldComment && hideOldComment) {
|
||||
throw new Error("delete and hide cannot be both set to true")
|
||||
const exclusiveModes: [string, boolean][] = [
|
||||
["delete", deleteOldComment],
|
||||
["recreate", recreate],
|
||||
["only_create", onlyCreateComment],
|
||||
["hide", hideOldComment],
|
||||
["hide_and_recreate", hideAndRecreate],
|
||||
]
|
||||
const enabledModes = exclusiveModes.filter(([, flag]) => flag).map(([name]) => name)
|
||||
if (enabledModes.length > 1) {
|
||||
throw new Error(`${enabledModes.join(" and ")} cannot be set to true simultaneously`)
|
||||
}
|
||||
|
||||
if (onlyCreateComment && onlyUpdateComment) {
|
||||
throw new Error("only_create and only_update cannot be both set to true")
|
||||
}
|
||||
|
||||
if (hideOldComment && hideAndRecreate) {
|
||||
throw new Error("hide and hide_and_recreate cannot be both set to true")
|
||||
}
|
||||
|
||||
const octokit = github.getOctokit(githubToken)
|
||||
const previous = await findPreviousComment(octokit, repo, pullRequestNumber, header)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue