mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2026-04-19 20:45:43 +00:00
Move validateExclusiveModes before getBody for fail-fast validation (#1663)
* 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>
This commit is contained in:
parent
70d2764d1a
commit
14d4f1e429
4 changed files with 151 additions and 28 deletions
34
src/main.ts
34
src/main.ts
|
|
@ -27,6 +27,7 @@ import {
|
|||
repo,
|
||||
skipUnchanged,
|
||||
} from "./config"
|
||||
import {validateBody, validateExclusiveModes} from "./validate"
|
||||
|
||||
async function run(): Promise<undefined> {
|
||||
if (Number.isNaN(pullRequestNumber) || pullRequestNumber < 1) {
|
||||
|
|
@ -35,6 +36,15 @@ async function run(): Promise<undefined> {
|
|||
}
|
||||
|
||||
try {
|
||||
validateExclusiveModes(
|
||||
deleteOldComment,
|
||||
recreate,
|
||||
onlyCreateComment,
|
||||
onlyUpdateComment,
|
||||
hideOldComment,
|
||||
hideAndRecreate,
|
||||
)
|
||||
|
||||
const body = await getBody()
|
||||
|
||||
if (!body && ignoreEmpty) {
|
||||
|
|
@ -42,29 +52,7 @@ async function run(): Promise<undefined> {
|
|||
return
|
||||
}
|
||||
|
||||
if (!deleteOldComment && !hideOldComment && !body) {
|
||||
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")
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
validateBody(body, deleteOldComment, hideOldComment)
|
||||
|
||||
const octokit = github.getOctokit(githubToken)
|
||||
const previous = await findPreviousComment(octokit, repo, pullRequestNumber, header)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue