@@ -3,6 +3,7 @@ package main
33import (
44 "fmt"
55 "maps"
6+ "regexp"
67 "slices"
78 "strings"
89
@@ -11,6 +12,11 @@ import (
1112 "github.com/golangci/golangci-lint/v2/pkg/lint/lintersdb"
1213)
1314
15+ const (
16+ hostGitHub = "github"
17+ hostGitLab = "gitlab"
18+ )
19+
1420type authorDetails struct {
1521 Linters []string
1622 Profile string
@@ -35,29 +41,29 @@ func getThanksList() string {
3541 continue
3642 }
3743
38- linterURL := extractLinterURL (lc )
44+ info := extractInfo (lc )
3945
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 ())
4350 } else {
44- addedAuthors [author ] = & authorDetails {
51+ addedAuthors [info . Author ] = & authorDetails {
4552 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 ),
4855 }
4956 }
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 ())
5361 } else {
54- addedAuthors [author ] = & authorDetails {
62+ addedAuthors [info . Author ] = & authorDetails {
5563 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 ),
5765 }
5866 }
59- } else {
60- continue
6167 }
6268 }
6369
@@ -78,31 +84,65 @@ func getThanksList() string {
7884 return strings .Join (lines , "\n " )
7985}
8086
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+
8295 switch lc .Name () {
8396 case "staticcheck" :
84- return "https://github.com/ dominikh/go-tools"
97+ return authorInfo { Author : " dominikh" , Host : hostGitHub }
8598
86- case "depguard " :
87- return "https://github.com/dixonwille/depguard"
99+ case "misspell " :
100+ return authorInfo { Author : "client9" , Host : hostGitHub }
88101
89102 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 }
92105 }
93106
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 ],
96116 }
97117
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
99139 }
100140}
101141
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+ }
106145
107- return strings .SplitN (strings .TrimPrefix (originalURL , prefix ), "/" , 2 )[0 ]
146+ func (i authorInfo ) FromGitLab () bool {
147+ return i .Host == hostGitLab
108148}
0 commit comments