Skip to content

Commit 8e699cf

Browse files
committed
feat(interfaces): Commit
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent 38f794c commit 8e699cf

File tree

3 files changed

+224
-0
lines changed

3 files changed

+224
-0
lines changed
+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* @file Type Tests - Commit
3+
* @module commitlint-config/interfaces/tests/unit-d/Commit
4+
*/
5+
6+
import type { Scope, Type } from '#src/enums'
7+
import type { LiteralUnion, Nullable } from '@flex-development/tutils'
8+
import type TestSubject from '../commit'
9+
import type Note from '../note'
10+
import type Reference from '../reference'
11+
import type Revert from '../revert'
12+
13+
describe('unit-d:interfaces/Commit', () => {
14+
it('should match [body: Nullable<string>]', () => {
15+
expectTypeOf<TestSubject>()
16+
.toHaveProperty('body')
17+
.toEqualTypeOf<Nullable<string>>()
18+
})
19+
20+
it('should match [breaking: Nullable<"!">]', () => {
21+
expectTypeOf<TestSubject>()
22+
.toHaveProperty('breaking')
23+
.toEqualTypeOf<Nullable<'!'>>()
24+
})
25+
26+
it('should match [committerDate: string]', () => {
27+
expectTypeOf<TestSubject>().toHaveProperty('committerDate').toBeString()
28+
})
29+
30+
it('should match [footer: Nullable<string>]', () => {
31+
expectTypeOf<TestSubject>()
32+
.toHaveProperty('footer')
33+
.toEqualTypeOf<Nullable<string>>()
34+
})
35+
36+
it('should match [gitTags: string]', () => {
37+
expectTypeOf<TestSubject>().toHaveProperty('gitTags').toBeString()
38+
})
39+
40+
it('should match [hash: string]', () => {
41+
expectTypeOf<TestSubject>().toHaveProperty('hash').toBeString()
42+
})
43+
44+
it('should match [header: string]', () => {
45+
expectTypeOf<TestSubject>().toHaveProperty('header').toBeString()
46+
})
47+
48+
it('should match [mentions: string[]]', () => {
49+
expectTypeOf<TestSubject>()
50+
.toHaveProperty('mentions')
51+
.toEqualTypeOf<string[]>()
52+
})
53+
54+
it('should match [merge: null]', () => {
55+
expectTypeOf<TestSubject>().toHaveProperty('merge').toBeNull()
56+
})
57+
58+
it('should match [notes: Note[]]', () => {
59+
expectTypeOf<TestSubject>().toHaveProperty('notes').toEqualTypeOf<Note[]>()
60+
})
61+
62+
it('should match [pr: Nullable<string>]', () => {
63+
expectTypeOf<TestSubject>()
64+
.toHaveProperty('pr')
65+
.toEqualTypeOf<Nullable<string>>()
66+
})
67+
68+
it('should match [references: Reference[]]', () => {
69+
expectTypeOf<TestSubject>()
70+
.toHaveProperty('references')
71+
.toEqualTypeOf<Reference[]>()
72+
})
73+
74+
it('should match [revert: Nullable<Revert>]', () => {
75+
expectTypeOf<TestSubject>()
76+
.toHaveProperty('revert')
77+
.toEqualTypeOf<Nullable<Revert>>()
78+
})
79+
80+
it('should match [scope: Nullable<LiteralUnion<Scope, string>>]', () => {
81+
expectTypeOf<TestSubject>()
82+
.toHaveProperty('scope')
83+
.toEqualTypeOf<Nullable<LiteralUnion<Scope, string>>>()
84+
})
85+
86+
it('should match [shortHash: Nullable<string>]', () => {
87+
expectTypeOf<TestSubject>()
88+
.toHaveProperty('shortHash')
89+
.toEqualTypeOf<Nullable<string>>()
90+
})
91+
92+
it('should match [subject: string]', () => {
93+
expectTypeOf<TestSubject>().toHaveProperty('subject').toBeString()
94+
})
95+
96+
it('should match [type: LiteralUnion<Type, string>]', () => {
97+
expectTypeOf<TestSubject>()
98+
.toHaveProperty('type')
99+
.toEqualTypeOf<LiteralUnion<Type, string>>()
100+
})
101+
})

src/interfaces/commit.ts

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/**
2+
* @file Interfaces - Commit
3+
* @module commitlint-config/interfaces/Commit
4+
*/
5+
6+
import type { Scope, Type } from '#src/enums'
7+
import type {
8+
LiteralUnion,
9+
Nullable,
10+
OneOrMany
11+
} from '@flex-development/tutils'
12+
import type Note from './note'
13+
import type Reference from './reference'
14+
import type Revert from './revert'
15+
16+
/**
17+
* Object representing a parsed commit.
18+
*/
19+
interface Commit {
20+
[field: string]: Note[] | Nullable<OneOrMany<string>> | Reference[] | Revert
21+
22+
/**
23+
* Commit body text.
24+
*
25+
* @see https://commitlint.js.org/#/concepts-commit-conventions
26+
*/
27+
body: Nullable<string>
28+
29+
/**
30+
* Breaking change indicator.
31+
*/
32+
breaking: Nullable<'!'>
33+
34+
/**
35+
* Commit date in ISO 8601-like format (`%ci`).
36+
*
37+
* @see https://git-scm.com/docs/pretty-formats/2.21.0
38+
*/
39+
committerDate: string
40+
41+
/**
42+
* Commit footer text.
43+
*
44+
* @see https://commitlint.js.org/#/concepts-commit-conventions
45+
*/
46+
footer: Nullable<string>
47+
48+
/**
49+
* Tags associated with commit.
50+
*/
51+
gitTags: string
52+
53+
/**
54+
* Commit SHA.
55+
*/
56+
hash: string
57+
58+
/**
59+
* Commit {@linkcode type}, {@linkcode scope}, {@linkcode breaking} change
60+
* indicator (if any), and {@linkcode subject}.
61+
*/
62+
header: string
63+
64+
/**
65+
* Users and/or organizations mentioned in commit.
66+
*/
67+
mentions: string[]
68+
69+
/**
70+
* Merge commit data.
71+
*/
72+
merge: null
73+
74+
/**
75+
* Breaking change notes.
76+
*/
77+
notes: Note[]
78+
79+
/**
80+
* Pull request number if commit {@linkcode subject} includes pull request
81+
* reference.
82+
*/
83+
pr: Nullable<string>
84+
85+
/**
86+
* Reference actions parsed from commit.
87+
*/
88+
references: Reference[]
89+
90+
/**
91+
* Reverted commit metadata if {@linkcode type} is {@linkcode Type.REVERT}.
92+
*/
93+
revert: Nullable<Revert>
94+
95+
/**
96+
* Commit scope.
97+
*
98+
* @see https://commitlint.js.org/#/concepts-commit-conventions
99+
*/
100+
scope: Nullable<LiteralUnion<Scope, string>>
101+
102+
/**
103+
* Abbreviated commit SHA.
104+
*/
105+
shortHash: Nullable<string>
106+
107+
/**
108+
* Commit subject.
109+
*
110+
* @see https://commitlint.js.org/#/concepts-commit-conventions
111+
*/
112+
subject: string
113+
114+
/**
115+
* Commit type.
116+
*
117+
* @see https://commitlint.js.org/#/concepts-commit-conventions
118+
*/
119+
type: LiteralUnion<Type, string>
120+
}
121+
122+
export type { Commit as default }

src/interfaces/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* @module commitlint-config/interfaces
44
*/
55

6+
export type { default as Commit } from './commit'
67
export type { default as Config } from './config'
78
export type { default as PromptConfig } from './config-prompt'
89
export type { default as RulesConfig } from './config-rules'

0 commit comments

Comments
 (0)