@@ -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,31 +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"
97
+ return authorInfo { Author : " dominikh" , Host : hostGitHub }
85
98
86
- case "depguard " :
87
- return "https://github.com/dixonwille/depguard"
99
+ case "misspell " :
100
+ return authorInfo { Author : "client9" , Host : hostGitHub }
88
101
89
102
default :
90
- if strings .HasPrefix (lc .OriginalURL , "https://github.com/gostaticanalysis /" ) {
91
- return "https://github.com/tenntenn/gostaticanalysis"
103
+ if strings .HasPrefix (lc .OriginalURL , "https://pkg.go.dev /" ) {
104
+ return authorInfo { Author : "golang" , Host : hostGitHub }
92
105
}
93
106
94
- if strings .HasPrefix (lc .OriginalURL , "https://github.com/go-simpler/" ) {
95
- return "https://github.com/tmzane/go-simpler"
107
+ if ! exp .MatchString (lc .OriginalURL ) {
108
+ return authorInfo {}
109
+ }
110
+
111
+ submatch := exp .FindAllStringSubmatch (lc .OriginalURL , - 1 )
112
+
113
+ info := authorInfo {
114
+ Author : submatch [0 ][2 ],
115
+ Host : submatch [0 ][1 ],
96
116
}
97
117
98
- return lc .OriginalURL
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 {}
136
+ }
137
+
138
+ return info
99
139
}
100
140
}
101
141
102
- func extractAuthor (originalURL , prefix string ) string {
103
- if ! strings .HasPrefix (originalURL , prefix ) {
104
- return ""
105
- }
142
+ func (i authorInfo ) FromGitHub () bool {
143
+ return i .Host == hostGitHub
144
+ }
106
145
107
- return strings .SplitN (strings .TrimPrefix (originalURL , prefix ), "/" , 2 )[0 ]
146
+ func (i authorInfo ) FromGitLab () bool {
147
+ return i .Host == hostGitLab
108
148
}
0 commit comments