refactor: centralize close-flow logic into shared createCloseEntityHandler factory#25628
refactor: centralize close-flow logic into shared createCloseEntityHandler factory#25628
createCloseEntityHandler factory#25628Conversation
…ctory (#close-issue-close-pr-duplication) - Add createCloseEntityHandler() to close_entity_helpers.cjs handling the common pipeline: max-count gating, comment body resolution, sanitization, label/title-prefix filtering, staged-mode preview, comment posting with configurable error handling, entity close, and success result construction - Refactor close_issue.cjs to delegate to createCloseEntityHandler with issue-specific callbacks (cross-repo, all-labels-must-match, no footer, state_reason support) - Refactor close_pull_request.cjs to delegate to createCloseEntityHandler, removing duplicate local checkLabelFilter, checkTitlePrefixFilter and buildCommentBody (now imported from close_entity_helpers.cjs) - Update close_pull_request.test.cjs title-prefix error assertion to match the aligned error message format Agent-Logs-Url: https://github.com/github/gh-aw/sessions/d384dacd-9154-4360-9586-b607087672e9 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
createCloseEntityHandler factory
🧪 Test Quality Sentinel ReportTest Quality Score: 100/100✅ Excellent test quality
Test Classification Details
Change SummaryThis PR modifies exactly one assertion in one test file: - expect(result.error).toContain("does not start with required prefix");
+ expect(result.error).toContain("doesn't start with");The change keeps the assertion synchronized with the now-shared error message format introduced by the No new test functions were added or removed. No Go test files were changed. The single modified test is an error-path case (tests a failure scenario), carries two Test inflation: test file changed by 1 line vs. 350 lines added/removed across production files — well within acceptable bounds. Language SupportTests analyzed:
Verdict
📖 Understanding Test ClassificationsDesign Tests (High Value) verify what the system does:
Implementation Tests (Low Value) verify how the system does it:
Goal: Shift toward tests that describe the system's behavioral contract — the promises it makes to its users and collaborators.
|
There was a problem hiding this comment.
✅ Test Quality Sentinel: 100/100. Test quality is excellent — 0% of modified tests are implementation tests (threshold: 30%). The single changed assertion correctly tracks the refactored shared error-message format from the createCloseEntityHandler factory.
There was a problem hiding this comment.
Pull request overview
Refactors the close-flow logic for issues and pull requests by centralizing the shared pipeline into a new createCloseEntityHandler factory, reducing duplication and aligning shared validation/error behavior across handlers.
Changes:
- Added
createCloseEntityHandlerto unify the close pipeline (max gating, sanitization, filters, staged-mode preview, comment+close, result shaping). - Refactored
close_issue.cjsandclose_pull_request.cjsto use the shared factory with entity-specific callbacks. - Updated a PR title-prefix assertion in
close_pull_request.test.cjsto match the shared error message format.
Show a summary per file
| File | Description |
|---|---|
| actions/setup/js/close_entity_helpers.cjs | Introduces createCloseEntityHandler and exports it for reuse across close handlers. |
| actions/setup/js/close_issue.cjs | Replaces inline close pipeline with the shared factory, preserving issue-specific semantics (label matching, state_reason override, no footer). |
| actions/setup/js/close_pull_request.cjs | Replaces inline close pipeline with the shared factory and removes duplicated helper logic in favor of shared helpers. |
| actions/setup/js/close_pull_request.test.cjs | Adjusts test expectation for the updated, shared title-prefix error message wording. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 4/4 changed files
- Comments generated: 1
| buildCommentBody(sanitizedBody) { | ||
| const triggeringPRNumber = context.payload?.pull_request?.number; | ||
| const triggeringIssueNumber = context.payload?.issue?.number; | ||
| return buildCommentBody(sanitizedBody, triggeringIssueNumber, triggeringPRNumber); | ||
| }, |
There was a problem hiding this comment.
createCloseEntityHandler sanitizes the comment body before invoking callbacks.buildCommentBody, but in the PR handler the callback delegates to buildCommentBody from close_entity_helpers.cjs, which sanitizes internally as well. This results in double-sanitization of the user-provided comment for PRs (potentially altering output and doing extra work). Consider making the helper buildCommentBody assume input is already sanitized (and update other call sites accordingly), or bypass it here and only apply sanitization once in the shared pipeline.
|
Hey The PR is well-structured, laser-focused on one thing, has a thorough description, includes a test update (and the Test Quality Sentinel gave it 100/100 🎉), adds no new dependencies, and the net change is a healthy net reduction of ~103 lines of code. This looks ready for maintainer review! ✅
|
close_issue.cjsandclose_pull_request.cjseach implemented an identical ~100-line close-flow pipeline inline, whileclose_pull_request.cjsalso duplicatedcheckLabelFilter,checkTitlePrefixFilter, andbuildCommentBodythat already existed inclose_entity_helpers.cjs.Changes
close_entity_helpers.cjs— newcreateCloseEntityHandlerfactoryCentralises the shared 11-step pipeline: max-count gating → comment body resolution → sanitization → target resolution → entity details fetch → label filter → title-prefix filter → staged-mode preview → comment posting → entity close → result construction.
Entity-specific behaviour is injected via a
CloseEntityHandlerCallbacksobject:close_issue.cjsReduced from ~305 lines to ~80 lines of logic. Preserves: cross-repo support, all-labels-must-match semantics, raw comment body (no footer), per-item
state_reasonoverride, fails-on-comment-error.close_pull_request.cjsReduced from ~355 lines to ~90 lines of logic. Removes local duplicates of
checkLabelFilter,checkTitlePrefixFilter, andbuildCommentBody(now imported from helpers). Preserves: any-label-match semantics, footer-enhanced comment body,continueOnCommentError: truewithcommentPostedtracking.close_pull_request.test.cjsUpdated one title-prefix error assertion to match the now-shared error message format (
"doesn't start with"— same formatclose_issuealready used).Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/repos/github/gh-aw/contents/.github%2Fworkflows%2Faudit-workflows.md/opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --experimental-import-meta-resolve --require /home/REDACTED/work/gh-aw/gh-aw/actions/setup/js/node_modules/vitest/suppress-warnings.cjs --conditions node --conditions development /home/REDACTED/work/gh-aw/gh-aw/actions/setup/js/node_modules/vitest/dist/workers/forks.js(http block)invalid.example.invalid/usr/lib/git-core/git-remote-https /usr/lib/git-core/git-remote-https origin https://invalid.example.invalid/nonexistent-repo.git git conf�� user.name Test User _modules/.bin/git -M main t git init�� --bare --initial-branch=main 86_64/git -b main modules/@npmcli/agent-change.txt git(dns block)If you need me to access, download, or install something from one of these locations, you can either: