Skip to content

Move validateExclusiveModes before getBody for fail-fast validation#1663

Merged
marocchino merged 6 commits into
mainfrom
copilot/improve-validate-options
Mar 13, 2026
Merged

Move validateExclusiveModes before getBody for fail-fast validation#1663
marocchino merged 6 commits into
mainfrom
copilot/improve-validate-options

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 13, 2026

Conflicting mode flags (e.g. delete + recreate) were previously detected only after getBody() completed its file I/O. Reorder so validation fails immediately, before any I/O.

Changes

  • src/main.ts: move validateExclusiveModes(...) above const body = await getBody()
  • __tests__/main.test.ts: add expect(mockConfig.getBody).not.toHaveBeenCalled() to all six exclusive-mode failure tests — without this, a regression in call order would go undetected
// before
const body = await getBody()
validateExclusiveModes(...)

// after
validateExclusiveModes(...)        // ← throws immediately on bad config
const body = await getBody()       // ← only reached with valid config
Original prompt

This section details on the original issue you should resolve

<issue_title>Improve validate options</issue_title>
<issue_description>src/main.ts:67

delete is now rejected when combined with recreate/only_create/hide, but it can still be combined with hide_and_recreate (in which case the code will delete and return, silently ignoring hide_and_recreate). Consider adding an explicit validation error for deleteOldComment && hideAndRecreate to avoid ambiguous/ignored inputs.
    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")
    }

</issue_description>

<agent_instructions>이 옵션들은 동시에 어사인 되면 안돼니 리스트에서 true것을 찾아 2개이상이면 에러를 반환하는 방식으로 리팩토링이 가능 할것 같습니다.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copilot AI changed the title [WIP] Fix validation for delete and hide options Refactor mutually exclusive option validation to list-based approach Mar 13, 2026
Copilot AI requested a review from marocchino March 13, 2026 11:47
Copilot AI changed the title Refactor mutually exclusive option validation to list-based approach Refactor mutually exclusive option validation to unified list-based approach Mar 13, 2026
Copilot AI changed the title Refactor mutually exclusive option validation to unified list-based approach Separate validation logic into dedicated module Mar 13, 2026
Copilot AI changed the title Separate validation logic into dedicated module Extract validation logic into src/validate.ts; run exclusive-mode check before getBody Mar 13, 2026
Copilot AI changed the title Extract validation logic into src/validate.ts; run exclusive-mode check before getBody Move validateExclusiveModes before getBody for fail-fast validation Mar 13, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 13, 2026

Output of npm run all
> [email protected] all
> npm run build && npm run format && npm run lint && npm run package && npm run test


> [email protected] build
> tsc


> [email protected] format
> biome format --write .

Formatted 5 files in 4ms. No fixes applied.

> [email protected] lint
> biome check .

Checked 5 files in 8ms. No fixes applied.

> [email protected] package
> npx rimraf ./dist && npx rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript

�[36m
�[1msrc/main.ts�[22m → �[1mdist/index.js�[22m...�[39m
�[1m�[33m(!) "this" has been rewritten to "undefined"�[39m�[22m
�[90mhttps://rollupjs.org/troubleshooting/#error-this-is-undefined�[39m
�[1mnode_modules/@actions/core/lib/core.js�[22m
�[90m1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
                    ^
2:     function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3:     return new (P || (P = Promise))(function (resolve, reject) {�[39m
...and 1 other occurrence
�[1mnode_modules/@actions/glob/lib/glob.js�[22m
�[90m1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
                    ^
2:     function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3:     return new (P || (P = Promise))(function (resolve, reject) {�[39m
...and 1 other occurrence
�[1mnode_modules/@actions/core/lib/oidc-utils.js�[22m
�[90m1: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
                    ^
2:     function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3:     return new (P || (P = Promise))(function (resolve, reject) {�[39m
...and 1 other occurrence

...and 11 other files
�[1m�[33m(!) Circular dependency�[39m�[22m
node_modules/@actions/core/lib/core.js -> node_modules/@actions/core/lib/oidc-utils.js -> node_modules/@actions/core/lib/core.js
�[32mcreated �[1mdist/index.js�[22m in �[1m3.5s�[22m�[39m

> [email protected] test
> vitest run


�[1m�[46m RUN �[49m�[22m �[36mv4.1.0 �[39m�[90m/home/runner/work/sticky-pull-request-comment/sticky-pull-request-comment�[39m

 �[32m✓�[39m __tests__/config.test.ts �[2m(�[22m�[2m15 tests�[22m�[2m)�[22m�[32m 21�[2mms�[22m�[39m
 �[32m✓�[39m __tests__/main.test.ts �[2m(�[22m�[2m22 tests�[22m�[2m)�[22m�[32m 139�[2mms�[22m�[39m
 �[32m✓�[39m __tests__/comment.test.ts �[2m(�[22m�[2m19 tests�[22m�[2m)�[22m�[32m 20�[2mms�[22m�[39m
 �[32m✓�[39m __tests__/validate.test.ts �[2m(�[22m�[2m14 tests�[22m�[2m)�[22m�[32m 9�[2mms�[22m�[39m

�[2m Test Files �[22m �[1m�[32m4 passed�[39m�[22m�[90m (4)�[39m
�[2m      Tests �[22m �[1m�[32m70 passed�[39m�[22m�[90m (70)�[39m
�[2m   Start at �[22m 12:05:24
�[2m   Duration �[22m 542ms�[2m (transform 274ms, setup 0ms, import 524ms, tests 188ms, environment 0ms)�[22m

The build is over.

@marocchino marocchino marked this pull request as ready for review March 13, 2026 12:05
@marocchino marocchino merged commit 14d4f1e into main Mar 13, 2026
2 checks passed
@marocchino marocchino deleted the copilot/improve-validate-options branch March 13, 2026 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve validate options

2 participants