fix(commit-parser): fall back to header-only parsing when body is unparseable#2790
Open
narhen wants to merge 1 commit into
Open
fix(commit-parser): fall back to header-only parsing when body is unparseable#2790narhen wants to merge 1 commit into
narhen wants to merge 1 commit into
Conversation
…arseable When the @conventional-commits/parser grammar throws on a commit body (commonly an unbalanced `(` from GitHub's line-wrap of a PR body), parseConventionalCommits currently logs at debug and skips the commit entirely, so the entry never reaches the release PR changelog. Retry the parse with just the first line; if the header parses, push it as a ConventionalCommit and log a warn. If the header also fails, fall through to the existing debug log. Preserved on the fallback path: type, scope, bareMessage, header-level breaking marker, header references, pullRequest, sha, files. Lost: body-derived BREAKING CHANGE notes, body references, footer trailers. Refs googleapis#2564
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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.
Fixes #2564 🦕
Problem
parseConventionalCommitssilently drops commits whose body trips the@conventional-commits/parsergrammar. The grammar requires that any(on a body line have its matching)on the same line. GitHub's PR-body line-wrap routinely produces commits that violate this — e.g. a function call whose closing paren ends up on the next line:This throws
unexpected token '\n' at LINE:COL, valid tokens [)]from inside the parser'sscope()rule. The header itself parses fine; only the body is broken.The existing
catchinparseConventionalCommits(src/commit.ts) logs at debug level and skips the commit, so the entry never reaches the release PR's changelog. #2564 is the canonical bug report for this symptom.Root cause
Upstream in
@conventional-commits/parser,scope()throws on a newline before)rather than returning a recoverable error. An open PR (conventional-commits/parser#48) targets this exact case but has been stalled since March 2024; the parser has not had an npm release since January 2021. We can't realistically wait for an upstream fix.Fix
When full-message parsing throws, retry with just the first line of the commit message. If the header parses, push it as a
ConventionalCommitand log awarnso users know the body was discarded. If the header also fails to parse, fall through to the existing debug log and skip the commit (unchanged behavior).Preserved on the fallback path:
type,scope,bareMessage,breaking(via!in the header),referencesfrom the header,pullRequest,sha,files.Lost on the fallback path: body-derived
BREAKING CHANGEnotes, body-derived references, footer trailers. The user-visible improvement is "commit appears in the changelog" rather than "commit silently vanishes."Test
Added a
parseConventionalCommitstest with a body that wraps a function call across lines. Without the fix it returns[]; with the fix it returns one parsed commit with the correct type/scope/subject.Checklist
npm test: 1101 passing, 0 failing;npm run lint: no new errors)