fix: handle missing prompts in commitlint config and OCO_ONE_LINE_COMMIT for split diffs#554
Open
octo-patch wants to merge 1 commit intodi-sukharev:masterfrom
Conversation
…MIT for split diffs
Owner
|
@octo-patch please fix the tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
This PR fixes two bugs:
Bug 1 — Fixes #482:
TypeError: Cannot read properties of undefined (reading 'join')with@commitlintWhen the
.opencommit-commitlintcache file exists but is missing thepromptsfield (e.g. generated by an older version of opencommit or manually edited),INIT_MAIN_PROMPTinsrc/modules/commitlint/prompts.tscrashes trying to call.join()onundefined.Steps to reproduce:
Bug 2 — Fixes #474:
OCO_ONE_LINE_COMMIT=truehas no effect on large diffsWhen a staged diff exceeds the context window it gets split into chunks, each generating its own commit message. These messages were then joined with
\n\n, producing a multi-line result regardless ofOCO_ONE_LINE_COMMIT=true.Solution
Fix 1: After reading the cached commitlint config, check whether
promptsis a valid array. If not (outdated/corrupted file), force a regeneration of the config before proceeding. This recovers gracefully instead of crashing.Fix 2: When
OCO_ONE_LINE_COMMITis enabled and the diff was split into multiple chunks, extract the first line from each chunk's commit message and join them with'; 'to produce a single-line result.Testing
tsc --noEmit)Array.isArray()so valid configs are not affectedOCO_ONE_LINE_COMMIT=trueand the diff was large enough to be split