@@ -3,6 +3,7 @@ package main
3
3
import (
4
4
"fmt"
5
5
"maps"
6
+ "regexp"
6
7
"slices"
7
8
"strings"
8
9
@@ -11,6 +12,11 @@ import (
11
12
"github.com/golangci/golangci-lint/v2/pkg/lint/lintersdb"
12
13
)
13
14
15
+ const (
16
+ hostGitHub = "github"
17
+ hostGitLab = "gitlab"
18
+ )
19
+
14
20
type authorDetails struct {
15
21
Linters []string
16
22
Profile string
@@ -35,29 +41,29 @@ func getThanksList() string {
35
41
continue
36
42
}
37
43
38
- linterURL := extractLinterURL (lc )
44
+ info := extractInfo (lc )
39
45
40
- if author := extractAuthor (linterURL , "https://github.com/" ); author != "" && author != "golangci" {
41
- if _ , ok := addedAuthors [author ]; ok {
42
- addedAuthors [author ].Linters = append (addedAuthors [author ].Linters , lc .Name ())
46
+ switch {
47
+ case info .FromGitHub ():
48
+ if _ , ok := addedAuthors [info .Author ]; ok {
49
+ addedAuthors [info .Author ].Linters = append (addedAuthors [info .Author ].Linters , lc .Name ())
43
50
} else {
44
- addedAuthors [author ] = & authorDetails {
51
+ addedAuthors [info . Author ] = & authorDetails {
45
52
Linters : []string {lc .Name ()},
46
- Profile : fmt .Sprintf ("[%[1]s](https://github.com/sponsors/%[1]s)" , author ),
47
- Avatar : fmt .Sprintf (`<img src="https://github.com/%[1]s.png" alt="%[1]s" style="max-width: 100%%;" width="20px;" />` , author ),
53
+ Profile : fmt .Sprintf ("[%[1]s](https://github.com/sponsors/%[1]s)" , info . Author ),
54
+ Avatar : fmt .Sprintf (`<img src="https://github.com/%[1]s.png" alt="%[1]s" style="max-width: 100%%;" width="20px;" />` , info . Author ),
48
55
}
49
56
}
50
- } else if author := extractAuthor (linterURL , "https://gitlab.com/" ); author != "" {
51
- if _ , ok := addedAuthors [author ]; ok {
52
- addedAuthors [author ].Linters = append (addedAuthors [author ].Linters , lc .Name ())
57
+
58
+ case info .FromGitLab ():
59
+ if _ , ok := addedAuthors [info .Author ]; ok {
60
+ addedAuthors [info .Author ].Linters = append (addedAuthors [info .Author ].Linters , lc .Name ())
53
61
} else {
54
- addedAuthors [author ] = & authorDetails {
62
+ addedAuthors [info . Author ] = & authorDetails {
55
63
Linters : []string {lc .Name ()},
56
- Profile : fmt .Sprintf ("[%[1]s](https://gitlab.com/%[1]s)" , author ),
64
+ Profile : fmt .Sprintf ("[%[1]s](https://gitlab.com/%[1]s)" , info . Author ),
57
65
}
58
66
}
59
- } else {
60
- continue
61
67
}
62
68
}
63
69
@@ -78,34 +84,65 @@ func getThanksList() string {
78
84
return strings .Join (lines , "\n " )
79
85
}
80
86
81
- func extractLinterURL (lc * linter.Config ) string {
87
+ type authorInfo struct {
88
+ Author string
89
+ Host string
90
+ }
91
+
92
+ func extractInfo (lc * linter.Config ) authorInfo {
93
+ exp := regexp .MustCompile (`https://(github|gitlab)\.com/([^/]+)/.*` )
94
+
82
95
switch lc .Name () {
83
96
case "staticcheck" :
84
- return "https://github.com/dominikh/go-tools"
85
-
86
- case "depguard" :
87
- return "https://github.com/dixonwille/depguard"
97
+ return authorInfo {Author : "dominikh" , Host : hostGitHub }
88
98
89
99
case "misspell" :
90
- return "https://github.com/ client9/misspell"
100
+ return authorInfo { Author : " client9" , Host : hostGitHub }
91
101
92
102
default :
93
- if strings .HasPrefix (lc .OriginalURL , "https://github.com/gostaticanalysis/" ) {
94
- return "https://github.com/tenntenn/gostaticanalysis"
103
+ if strings .HasPrefix (lc .OriginalURL , "https://pkg.go.dev/" ) {
104
+ return authorInfo {Author : "golang" , Host : hostGitHub }
105
+ }
106
+
107
+ if ! exp .MatchString (lc .OriginalURL ) {
108
+ return authorInfo {}
95
109
}
96
110
97
- if strings .HasPrefix (lc .OriginalURL , "https://github.com/go-simpler/" ) {
98
- return "https://github.com/tmzane/go-simpler"
111
+ submatch := exp .FindAllStringSubmatch (lc .OriginalURL , - 1 )
112
+
113
+ info := authorInfo {
114
+ Author : submatch [0 ][2 ],
115
+ Host : submatch [0 ][1 ],
116
+ }
117
+
118
+ switch info .Author {
119
+ case "gostaticanalysis" :
120
+ info .Author = "tenntenn"
121
+
122
+ case "go-simpler" :
123
+ info .Author = "tmzane"
124
+
125
+ case "curioswitch" :
126
+ info .Author = "chokoswitch"
127
+
128
+ case "GaijinEntertainment" :
129
+ info .Author = "xobotyi"
130
+
131
+ case "OpenPeeDeeP" :
132
+ info .Author = "dixonwille"
133
+
134
+ case "golangci" :
135
+ return authorInfo {}
99
136
}
100
137
101
- return lc . OriginalURL
138
+ return info
102
139
}
103
140
}
104
141
105
- func extractAuthor (originalURL , prefix string ) string {
106
- if ! strings .HasPrefix (originalURL , prefix ) {
107
- return ""
108
- }
142
+ func (i authorInfo ) FromGitHub () bool {
143
+ return i .Host == hostGitHub
144
+ }
109
145
110
- return strings .SplitN (strings .TrimPrefix (originalURL , prefix ), "/" , 2 )[0 ]
146
+ func (i authorInfo ) FromGitLab () bool {
147
+ return i .Host == hostGitLab
111
148
}
0 commit comments