1
1
import type { App } from 'vuepress'
2
2
import type { GitChangelogInfo } from '../shared/index.js'
3
3
import type { ChangelogOptions , ContributorInfo } from './options.js'
4
- import type { KnownGitProvider , MergedRawCommit } from './typings.js'
4
+ import type { MergedRawCommit } from './typings.js'
5
5
import {
6
6
getContributorInfo ,
7
7
getUserNameWithNoreplyEmail ,
8
8
} from './utils/index.js'
9
9
10
- interface Pattern {
11
- issue ?: string
12
- tag ?: string
13
- commit ?: string
14
- }
15
-
16
- const RE_ISSUE = / # ( \d + ) / g
17
10
const RE_CLEAN_REFS = / [ ( ) ] / g
18
11
19
- const patterns : Record < KnownGitProvider , Pattern > = {
20
- github : {
21
- issue : ':repo/issues/:issue' ,
22
- tag : ':repo/releases/tag/:tag' ,
23
- commit : ':repo/commit/:hash' ,
24
- } ,
25
- gitlab : {
26
- issue : ':repo/-/issues/:issue' ,
27
- tag : ':repo/-/releases/:tag' ,
28
- commit : ':repo/-/commit/:hash' ,
29
- } ,
30
- gitee : {
31
- issue : ':repo/issues/:issue' ,
32
- tag : ':repo/releases/tag/:tag' ,
33
- commit : ':repo/commit/:hash' ,
34
- } ,
35
- bitbucket : {
36
- issue : ':repo/issues/:issue' ,
37
- tag : ':repo/src/:hash' ,
38
- commit : ':repo/commits/:hash' ,
39
- } ,
40
- }
41
-
42
- const getPattern = (
43
- { commitUrlPattern, issueUrlPattern, tagUrlPattern } : ChangelogOptions ,
44
- provider : KnownGitProvider | null ,
45
- ) : Pattern => {
46
- const fallback = provider ? patterns [ provider ] : { }
47
-
48
- return {
49
- commit : commitUrlPattern ?? fallback . commit ,
50
- issue : issueUrlPattern ?? fallback . issue ,
51
- tag : tagUrlPattern ?? fallback . tag ,
52
- }
53
- }
54
-
55
12
const parseTagName = ( refs : string ) : string | undefined => {
56
13
if ( ! refs ) return
57
14
@@ -67,11 +24,8 @@ export const resolveChangelog = (
67
24
app : App ,
68
25
commits : MergedRawCommit [ ] ,
69
26
options : ChangelogOptions ,
70
- gitProvider : KnownGitProvider | null ,
71
27
contributors : ContributorInfo [ ] ,
72
28
) : GitChangelogInfo [ ] => {
73
- const pattern = getPattern ( options , gitProvider )
74
- const repo = options . repoUrl
75
29
const result : GitChangelogInfo [ ] = [ ]
76
30
77
31
const sliceCommits = options . maxCount
@@ -95,28 +49,8 @@ export const resolveChangelog = (
95
49
96
50
if ( coAuthors . length ) resolved . coAuthors = coAuthors
97
51
98
- if ( pattern . issue && repo ) {
99
- resolved . message = resolved . message . replace (
100
- RE_ISSUE ,
101
- ( matched , issue : string ) => {
102
- const url = pattern
103
- . issue ! . replace ( ':issue' , issue )
104
- . replace ( ':repo' , repo )
105
- return `<a href="${ url } " target="_blank" rel="noopener noreferrer">${ matched } </a>`
106
- } ,
107
- )
108
- }
109
-
110
- if ( pattern . commit && repo )
111
- resolved . commitUrl = pattern . commit
112
- . replace ( ':hash' , hash )
113
- . replace ( ':repo' , repo )
114
-
115
52
if ( tag ) resolved . tag = tag
116
53
117
- if ( pattern . tag && repo && tag )
118
- resolved . tagUrl = pattern . tag . replace ( ':tag' , tag ) . replace ( ':repo' , repo )
119
-
120
54
result . push ( resolved )
121
55
}
122
56
0 commit comments