mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2026-04-08 07:20:05 +00:00
* Initial plan * 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> * feat: add only_update to exclusive modes validation list Co-authored-by: marocchino <128431+marocchino@users.noreply.github.com> * refactor: extract validation logic into src/validate.ts Co-authored-by: marocchino <128431+marocchino@users.noreply.github.com> * refactor: move validateExclusiveModes before getBody in run() Co-authored-by: marocchino <128431+marocchino@users.noreply.github.com> * test: assert getBody is not called when validateExclusiveModes fails Co-authored-by: marocchino <128431+marocchino@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: marocchino <128431+marocchino@users.noreply.github.com>
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
export function validateBody(
|
|
body: string,
|
|
deleteOldComment: boolean,
|
|
hideOldComment: boolean,
|
|
): void {
|
|
if (!deleteOldComment && !hideOldComment && !body) {
|
|
throw new Error("Either message or path input is required")
|
|
}
|
|
}
|
|
|
|
export function validateExclusiveModes(
|
|
deleteOldComment: boolean,
|
|
recreate: boolean,
|
|
onlyCreateComment: boolean,
|
|
onlyUpdateComment: boolean,
|
|
hideOldComment: boolean,
|
|
hideAndRecreate: boolean,
|
|
): void {
|
|
const exclusiveModes: [string, boolean][] = [
|
|
["delete", deleteOldComment],
|
|
["recreate", recreate],
|
|
["only_create", onlyCreateComment],
|
|
["only_update", onlyUpdateComment],
|
|
["hide", hideOldComment],
|
|
["hide_and_recreate", hideAndRecreate],
|
|
]
|
|
const enabledModes = exclusiveModes.filter(([, flag]) => flag).map(([name]) => name)
|
|
if (enabledModes.length > 1) {
|
|
const last = enabledModes[enabledModes.length - 1]
|
|
const rest = enabledModes.slice(0, -1)
|
|
const joined =
|
|
enabledModes.length === 2 ? `${rest[0]} and ${last}` : `${rest.join(", ")}, and ${last}`
|
|
throw new Error(`${joined} cannot be set to true simultaneously`)
|
|
}
|
|
}
|