@@ -2,6 +2,7 @@ import type { GitContributorInfo, KnownGitProvider } from '../shared/index.js'
2
2
import type { ContributorsOptions } from './options.js'
3
3
import type { MergedRawCommit } from './typings.js'
4
4
import {
5
+ checkGithubUsername ,
5
6
digestSHA256 ,
6
7
getContributorInfo ,
7
8
getUserNameWithNoreplyEmail ,
@@ -21,41 +22,48 @@ export const getRawContributors = (
21
22
...commit . coAuthors ,
22
23
]
23
24
24
- for ( const { name : author , email } of authors ) {
25
+ for ( const { name, email } of authors ) {
26
+ const usernameWithNoreplyEmail = getUserNameWithNoreplyEmail ( email )
25
27
const config = getContributorInfo (
26
- getUserNameWithNoreplyEmail ( email ) ?? author ,
28
+ usernameWithNoreplyEmail ?? name ,
27
29
options . info ,
28
30
)
29
- const username = config ?. username ?? author
30
- const name = config ?. name ?? username
31
31
32
- const contributor = contributors . get ( name + email )
32
+ // Only trust the username from `info` and `noreply email`.
33
+ const username = config ?. username ?? usernameWithNoreplyEmail
34
+
35
+ const contributor = contributors . get ( username ?? name )
33
36
34
37
if ( contributor ) {
35
38
contributor . commits ++
36
39
} else {
37
40
const item : GitContributorInfo = {
38
- name,
39
- username,
41
+ name : config ?. name ?? username ?? name ,
42
+ // if `username` not found, check if `name` is a valid github username
43
+ username :
44
+ username ??
45
+ ( gitProvider === 'github' && checkGithubUsername ( name ) ? name : '' ) ,
40
46
email,
41
47
commits : 1 ,
42
48
}
43
49
44
50
if ( options . avatar )
45
51
item . avatar =
46
52
config ?. avatar ??
47
- options . avatarPattern ?. replace ( ':username' , username ) ??
48
- ( gitProvider === 'github'
49
- ? `https://avatars.githubusercontent.com/${ username } ?v=4`
50
- : `https://gravatar.com/avatar/${ digestSHA256 ( email || username ) } ?d=retro` )
53
+ ( item . username
54
+ ? options . avatarPattern ?. replace ( ':username' , item . username )
55
+ : null ) ??
56
+ ( item . username
57
+ ? `https://avatars.githubusercontent.com/${ item . username } ?v=4`
58
+ : `https://gravatar.com/avatar/${ digestSHA256 ( email ) } ?d=retro` )
51
59
52
60
const url =
53
- ( config ?. url ?? gitProvider === 'github' )
54
- ? `https://github.com/${ username } `
55
- : undefined
61
+ config ?. url ??
62
+ ( item . username ? `https://github.com/${ item . username } ` : undefined )
63
+
56
64
if ( url ) item . url = url
57
65
58
- contributors . set ( name + email , item )
66
+ contributors . set ( username ?? name , item )
59
67
}
60
68
}
61
69
}
@@ -87,7 +95,13 @@ export const resolveContributors = (
87
95
88
96
if ( options . info ?. length && extraContributors . length ) {
89
97
for ( const extraContributor of extraContributors ) {
90
- if ( contributors . every ( ( item ) => item . name !== extraContributor ) ) {
98
+ if (
99
+ contributors . every (
100
+ ( item ) =>
101
+ item . username !== extraContributor &&
102
+ item . name !== extraContributor ,
103
+ )
104
+ ) {
91
105
const contributorInfo = getContributorInfo (
92
106
extraContributor ,
93
107
options . info ,
@@ -97,7 +111,7 @@ export const resolveContributors = (
97
111
98
112
const result : GitContributorInfo = {
99
113
name : contributorInfo . name ?? extraContributor ,
100
- username : contributorInfo . name ?? extraContributor ,
114
+ username : contributorInfo . username ,
101
115
email : '' ,
102
116
commits : 0 ,
103
117
}
0 commit comments