mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2026-05-03 10:38:52 +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
|
mockConfig.recreate = true
|
||||||
const {core} = await runMain()
|
const {core} = await runMain()
|
||||||
expect(core.setFailed).toHaveBeenCalledWith(
|
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
|
mockConfig.onlyCreateComment = true
|
||||||
const {core} = await runMain()
|
const {core} = await runMain()
|
||||||
expect(core.setFailed).toHaveBeenCalledWith(
|
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
|
mockConfig.hideOldComment = true
|
||||||
const {core} = await runMain()
|
const {core} = await runMain()
|
||||||
expect(core.setFailed).toHaveBeenCalledWith(
|
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
|
mockConfig.hideAndRecreate = true
|
||||||
const {core} = await runMain()
|
const {core} = await runMain()
|
||||||
expect(core.setFailed).toHaveBeenCalledWith(
|
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")
|
throw new Error("Either message or path input is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deleteOldComment && recreate) {
|
const exclusiveModes: [string, boolean][] = [
|
||||||
throw new Error("delete and recreate cannot be both set to true")
|
["delete", deleteOldComment],
|
||||||
}
|
["recreate", recreate],
|
||||||
|
["only_create", onlyCreateComment],
|
||||||
if (deleteOldComment && onlyCreateComment) {
|
["hide", hideOldComment],
|
||||||
throw new Error("delete and only_create cannot be both set to true")
|
["hide_and_recreate", hideAndRecreate],
|
||||||
}
|
]
|
||||||
|
const enabledModes = exclusiveModes.filter(([, flag]) => flag).map(([name]) => name)
|
||||||
if (deleteOldComment && hideOldComment) {
|
if (enabledModes.length > 1) {
|
||||||
throw new Error("delete and hide cannot be both set to true")
|
throw new Error(`${enabledModes.join(" and ")} cannot be set to true simultaneously`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (onlyCreateComment && onlyUpdateComment) {
|
if (onlyCreateComment && onlyUpdateComment) {
|
||||||
throw new Error("only_create and only_update cannot be both set to true")
|
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 octokit = github.getOctokit(githubToken)
|
||||||
const previous = await findPreviousComment(octokit, repo, pullRequestNumber, header)
|
const previous = await findPreviousComment(octokit, repo, pullRequestNumber, header)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue