Skip to content

fix(read): update git-raw-commits to v5 API#4638

Merged
escapedcat merged 3 commits intoconventional-changelog:masterfrom
Tamas-hi:fix-git-raw-commits-v5
Mar 10, 2026
Merged

fix(read): update git-raw-commits to v5 API#4638
escapedcat merged 3 commits intoconventional-changelog:masterfrom
Tamas-hi:fix-git-raw-commits-v5

Conversation

@Tamas-hi
Copy link
Copy Markdown
Contributor

@Tamas-hi Tamas-hi commented Mar 9, 2026

Description

Renovate PR #4065 bumps git-raw-commits from ^4.0.0 → ^5.0.0 and @types/git-raw-commits from ^2.0.3 → ^5.0.0. The v5 release is ESM-only and has breaking API changes. The CI currently fails because the code still uses the old v4 API.
This PR updates @commitlint/read to use the new v5 named exports (getRawCommits, GitOptions). It also fixes a bug where v5 silently drops arbitrary git log arguments (like --skip) by handling the skip option manually in getHistoryCommits.

Motivation and Context

Git-raw-commits v4 is now deprecated so an upgrade is needed. Resolves #4065.

Usage examples

No changes to public usage. Only internal API usage of git-raw-commits was updated.

How Has This Been Tested?

Run yarn test. Specifically ensured that the previously failing get edit commit message while skipping first commit test now passes since the --skip argument is handled internally.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@qodo-code-review
Copy link
Copy Markdown

Review Summary by Qodo

Update git-raw-commits to v5 API with manual skip handling

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Update git-raw-commits dependency from v4 to v5 with ESM-only API
• Replace default import with named exports getRawCommits and GitOptions
• Implement manual skip option handling in async iterator pattern
• Remove deprecated streamToPromise utility function
Diagram
flowchart LR
  A["git-raw-commits v4<br/>Default import"] -->|"Upgrade to v5"| B["git-raw-commits v5<br/>Named exports"]
  B -->|"Use getRawCommits<br/>async iterator"| C["getHistoryCommits<br/>Manual skip handling"]
  D["streamToPromise<br/>utility"] -->|"Remove"| E["Inline async<br/>iteration"]
Loading

Grey Divider

File Changes

1. @commitlint/read/src/get-history-commits.ts 🐞 Bug fix +12/-5

Migrate to git-raw-commits v5 API with skip handling

• Changed from default import gitRawCommits to named exports getRawCommits and GitOptions type
• Replaced stream-based approach with async iterator pattern using for await...of
• Implemented manual skip option handling by slicing returned data array
• Updated function signature to use imported GitOptions type instead of namespaced type

@commitlint/read/src/get-history-commits.ts


2. @commitlint/read/src/stream-to-promise.ts Miscellaneous +0/-11

Delete deprecated stream utility function

• Removed entire file as it is no longer needed
• Functionality replaced by inline async iterator pattern in getHistoryCommits

@commitlint/read/src/stream-to-promise.ts


3. @commitlint/read/package.json Dependencies +2/-2

Bump git-raw-commits to v5 with types

• Updated git-raw-commits dependency from ^4.0.0 to ^5.0.0
• Updated @types/git-raw-commits from ^2.0.3 to ^5.0.0

@commitlint/read/package.json


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown

qodo-code-review Bot commented Mar 9, 2026

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Action required

1. Unvalidated skip value 🐞 Bug ✓ Correctness
Description
getHistoryCommits() passes options.skip directly to Array.slice() without validating it is a
finite non-negative integer, so a boolean/string skip value coming from --git-log-args parsing
can change which commits are linted (e.g. true becomes 1) instead of failing fast.
Code

@commitlint/read/src/get-history-commits.ts[R9-16]

+	const { skip, ...gitOptions } = options as GitOptions & { skip?: number };
+	const data: string[] = [];
+	for await (const commit of getRawCommits({ ...gitOptions, cwd: opts.cwd })) {
+		data.push(commit);
+	}
+	if (skip) {
+		return data.slice(skip);
+	}
Evidence
skip is only type-asserted (not validated) and then used as the slice index. The caller builds
GitOptions by spreading the untyped minimist() output from the user-provided gitLogArgs
string, and the CLI explicitly exposes this as “additional git log arguments”, meaning invalid
values can realistically reach this codepath.

@commitlint/read/src/get-history-commits.ts[5-17]
@commitlint/read/src/read.ts[72-79]
@commitlint/cli/src/cli.ts[99-103]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`getHistoryCommits()` reads `skip` out of the options object and uses it as an `Array.slice()` index without runtime validation. Since `gitLogArgs` is user-provided and parsed via `minimist`, `skip` can become a boolean/string and be coerced by `slice()` (e.g. `true` -&gt; 1), changing which commits are linted.

### Issue Context
- `gitLogArgs` is explicitly an &quot;additional git log arguments&quot; escape hatch exposed by the CLI.
- The code currently relies on a TypeScript assertion (`{ skip?: number }`) but performs no runtime checks.

### Fix Focus Areas
- @commitlint/read/src/get-history-commits.ts[9-16]
- @commitlint/read/src/read.ts[72-79]

### Suggested approach
- Extract `skipRaw` from options.
- Compute `skipNum` safely (e.g. if number use it; if string try `Number(...)`; otherwise invalid).
- If `skipRaw` is defined but `skipNum` is not a finite integer &gt;= 0, throw an error.
- Use `skipNum` for skipping logic (see also the memory optimization in the second finding).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Skip wastes memory 🐞 Bug ➹ Performance
Description
When skip is set, getHistoryCommits() still stores the skipped commits in data and only removes
them afterward via slice(), causing unnecessary memory/time overhead for large skip values or
large commit ranges.
Code

@commitlint/read/src/get-history-commits.ts[R10-16]

+	const data: string[] = [];
+	for await (const commit of getRawCommits({ ...gitOptions, cwd: opts.cwd })) {
+		data.push(commit);
+	}
+	if (skip) {
+		return data.slice(skip);
+	}
Evidence
The function buffers all commits into data unconditionally, then discards the first skip
elements by slicing. This means skipped commits are still retained in memory even though they are
never returned.

@commitlint/read/src/get-history-commits.ts[9-16]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
When `skip` is provided, `getHistoryCommits()` currently buffers all commits (including the ones to be skipped) and then drops them with `data.slice(skip)`. This retains unnecessary data in memory and does extra work.

### Issue Context
- `getRawCommits()` is iterated as an async iterable, so commits can be skipped on the fly.
- This optimization is independent of the correctness validation (but pairs well with it).

### Fix Focus Areas
- @commitlint/read/src/get-history-commits.ts[9-16]

### Suggested approach
- After validating/coercing `skip`, do something like:
 - `let remainingToSkip = skipNum ?? 0;`
 - In the loop, if `remainingToSkip &gt; 0`, decrement and `continue` without pushing.
 - Otherwise `data.push(commit)`.
- Return `data` directly (no slicing), and avoid allocating/retaining skipped commits.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci Bot commented Mar 9, 2026

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Comment thread @commitlint/read/src/get-history-commits.ts Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates @commitlint/read to use the git-raw-commits v5 API, which is ESM-only and has breaking changes. It replaces the old default import and stream-based approach with the new named exports (getRawCommits, GitOptions) and async iterables, and manually handles the --skip option that v5 no longer passes through to git log.

Changes:

  • Updated git-raw-commits from ^4.0.0 to ^5.0.0 and @types/git-raw-commits from ^2.0.3 to ^5.0.0, with corresponding yarn.lock updates (adding @conventional-changelog/git-client transitive dependency, removing dargs, split2@^4, meow@^12).
  • Rewrote get-history-commits.ts to use v5's getRawCommits async iterable API and manually implement skip behavior via Array.slice, since v5 no longer passes arbitrary git log args through.
  • Removed the now-unnecessary stream-to-promise.ts helper.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

File Description
@commitlint/read/package.json Bumps git-raw-commits and @types/git-raw-commits to v5
@commitlint/read/src/get-history-commits.ts Migrates to v5 named exports and async iterable; handles skip manually
@commitlint/read/src/stream-to-promise.ts Removed — no longer needed with async iterable API
yarn.lock Reflects dependency tree changes for v5 migration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread @commitlint/read/src/get-history-commits.ts
@escapedcat escapedcat merged commit bd6ab41 into conventional-changelog:master Mar 10, 2026
12 checks passed
@escapedcat
Copy link
Copy Markdown
Member

Thanks

This was referenced Mar 12, 2026
This was referenced Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants