Skip to content

Commit e90f28c

Browse files
committed
feat(interfaces): [Commit] add Commit as index type
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent db33bd5 commit e90f28c

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

config/changelog.config.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import type {
2222
CommitGroup,
2323
GeneratedContext
2424
} from 'conventional-changelog-writer'
25-
import type { ICommit } from 'conventional-commits-parser'
2625
import dateformat from 'dateformat'
2726
import type mri from 'mri'
2827
import {
@@ -38,6 +37,16 @@ import semver from 'semver'
3837
import tempfile from 'tempfile'
3938
import pkg from '../package.json' assert { type: 'json' }
4039

40+
/**
41+
* Parsed commit with additional fields.
42+
*
43+
* @extends {Commit}
44+
*/
45+
interface CommitEnhanced extends Commit {
46+
raw: Commit
47+
version?: string
48+
}
49+
4150
/**
4251
* CLI flags.
4352
*/
@@ -235,11 +244,11 @@ sade('changelog', true)
235244
*
236245
* @see https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-writer#commitssort
237246
*
238-
* @param {ICommit} a - Commit object
239-
* @param {ICommit} b - Commit object to compare to `b`
247+
* @param {Commit} a - Commit object
248+
* @param {Commit} b - Commit object to compare to `b`
240249
* @return {number} Compare result
241250
*/
242-
commitsSort(a: ICommit, b: ICommit): number {
251+
commitsSort(a: Commit, b: Commit): number {
243252
/**
244253
* Compare result for {@linkcode b.committerDate} and
245254
* {@linkcode a.committerDate}.
@@ -269,32 +278,32 @@ sade('changelog', true)
269278
*
270279
* @param {GeneratedContext} context - Generated changelog context
271280
* @param {Options} options - `conventional-changelog-core` options
272-
* @param {ICommit[]} commits - Commits for release
273-
* @param {ICommit | undefined} key - Release commit
281+
* @param {CommitEnhanced[]} commits - Commits for release
282+
* @param {CommitEnhanced?} key - Release commit
274283
* @return {GeneratedContext} Final changelog context
275284
*/
276285
finalizeContext(
277286
context: GeneratedContext,
278287
options: Options,
279-
commits: ICommit[],
280-
key: ICommit | undefined
288+
commits: CommitEnhanced[],
289+
key?: CommitEnhanced
281290
): GeneratedContext {
282291
const { gitSemverTags = [], isPatch, linkCompare, version } = context
283292
let { currentTag, previousTag } = context
284293

285294
/**
286295
* First commit in release.
287296
*
288-
* @const {ICommit | undefined} first_commit
297+
* @const {CommitEnhanced?} first_commit
289298
*/
290-
const first_commit: ICommit | undefined = commits.at(0)
299+
const first_commit: CommitEnhanced | undefined = commits.at(0)
291300

292301
/**
293302
* Last commit in release.
294303
*
295-
* @const {ICommit | undefined} last_commit
304+
* @const {CommitEnhanced?} last_commit
296305
*/
297-
const last_commit: ICommit | undefined = commits.at(-1)
306+
const last_commit: CommitEnhanced | undefined = commits.at(-1)
298307

299308
// set current and previous tags
300309
if (key && (!currentTag || !previousTag)) {

src/interfaces/commit.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ import type Revert from './revert'
1717
* Object representing a parsed commit.
1818
*/
1919
interface Commit {
20-
[field: string]: Note[] | Nullable<OneOrMany<string>> | Reference[] | Revert
20+
[field: string]:
21+
| Commit
22+
| Note[]
23+
| Nullable<OneOrMany<string>>
24+
| Reference[]
25+
| Revert
2126

2227
/**
2328
* Commit body text.

typings/conventional-commits-parser/index.d.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,5 @@ import type { Commit } from '@flex-development/commitlint-config'
22
import {} from 'conventional-commits-parser'
33

44
declare module 'conventional-commits-parser' {
5-
export interface CommitBase extends Commit {}
6-
7-
export interface ICommit extends CommitBase {
8-
raw: CommitBase
9-
version?: string | undefined
10-
}
5+
interface CommitBase extends Commit {}
116
}

0 commit comments

Comments
 (0)