Skip to content

Commit 8411157

Browse files
authored
dev: rewrite and simplify thanks page generation (#5662)
1 parent 45bd17c commit 8411157

File tree

3 files changed

+211
-29
lines changed

3 files changed

+211
-29
lines changed

pkg/lint/lintersdb/builder_linter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
450450
linter.NewConfig(misspell.New(&cfg.Linters.Settings.Misspell)).
451451
WithSince("v1.8.0").
452452
WithAutoFix().
453-
WithURL("https://github.com/client9/misspell"),
453+
WithURL("https://github.com/golangci/misspell"),
454454

455455
linter.NewConfig(musttag.New(&cfg.Linters.Settings.MustTag)).
456456
WithSince("v1.51.0").

scripts/website/expand_templates/thanks.go

+68-28
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
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+
1420
type 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
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
9+
"github.com/golangci/golangci-lint/v2/pkg/lint/linter"
10+
"github.com/golangci/golangci-lint/v2/pkg/result"
11+
)
12+
13+
type FakeLinter struct {
14+
name string
15+
}
16+
17+
func (*FakeLinter) Run(_ context.Context, _ *linter.Context) ([]result.Issue, error) {
18+
return nil, nil
19+
}
20+
21+
func (f *FakeLinter) Name() string {
22+
return f.name
23+
}
24+
25+
func (*FakeLinter) Desc() string {
26+
return "fake linter"
27+
}
28+
29+
func Test_extractInfo(t *testing.T) {
30+
testCases := []struct {
31+
desc string
32+
lc *linter.Config
33+
expected authorInfo
34+
}{
35+
{
36+
desc: "from GitHub",
37+
lc: &linter.Config{
38+
Linter: &FakeLinter{name: "fake"},
39+
OriginalURL: "https://github.com/owner/linter",
40+
},
41+
expected: authorInfo{Author: "owner", Host: "github"},
42+
},
43+
{
44+
desc: "from GitLab",
45+
lc: &linter.Config{
46+
Linter: &FakeLinter{name: "fake"},
47+
OriginalURL: "https://gitlab.com/owner/linter",
48+
},
49+
expected: authorInfo{Author: "owner", Host: "gitlab"},
50+
},
51+
{
52+
desc: "staticcheck",
53+
lc: &linter.Config{
54+
Linter: &FakeLinter{name: "staticcheck"},
55+
OriginalURL: "https://github.com/owner/linter",
56+
},
57+
expected: authorInfo{Author: "dominikh", Host: "github"},
58+
},
59+
{
60+
desc: "gostaticanalysis",
61+
lc: &linter.Config{
62+
Linter: &FakeLinter{name: "fake"},
63+
OriginalURL: "https://github.com/gostaticanalysis/linter",
64+
},
65+
expected: authorInfo{Author: "tenntenn", Host: "github"},
66+
},
67+
{
68+
desc: "go-simpler",
69+
lc: &linter.Config{
70+
Linter: &FakeLinter{name: "fake"},
71+
OriginalURL: "https://github.com/go-simpler/linter",
72+
},
73+
expected: authorInfo{Author: "tmzane", Host: "github"},
74+
},
75+
{
76+
desc: "curioswitch",
77+
lc: &linter.Config{
78+
Linter: &FakeLinter{name: "fake"},
79+
OriginalURL: "https://github.com/curioswitch/linter",
80+
},
81+
expected: authorInfo{Author: "chokoswitch", Host: "github"},
82+
},
83+
{
84+
desc: "GaijinEntertainment",
85+
lc: &linter.Config{
86+
Linter: &FakeLinter{name: "fake"},
87+
OriginalURL: "https://github.com/GaijinEntertainment/linter",
88+
},
89+
expected: authorInfo{Author: "xobotyi", Host: "github"},
90+
},
91+
{
92+
desc: "OpenPeeDeeP",
93+
lc: &linter.Config{
94+
Linter: &FakeLinter{name: "fake"},
95+
OriginalURL: "https://github.com/OpenPeeDeeP/linter",
96+
},
97+
expected: authorInfo{Author: "dixonwille", Host: "github"},
98+
},
99+
{
100+
desc: "misspell",
101+
lc: &linter.Config{
102+
Linter: &FakeLinter{name: "misspell"},
103+
OriginalURL: "https://github.com/myorg/linter",
104+
},
105+
expected: authorInfo{Author: "client9", Host: "github"},
106+
},
107+
{
108+
desc: "pkg.go.dev",
109+
lc: &linter.Config{
110+
Linter: &FakeLinter{name: "fake"},
111+
OriginalURL: "https://pkg.go.dev/linter",
112+
},
113+
expected: authorInfo{Author: "golang", Host: "github"},
114+
},
115+
{
116+
desc: "golangci",
117+
lc: &linter.Config{
118+
Linter: &FakeLinter{name: "fake"},
119+
OriginalURL: "https://github.com/golangci/linter",
120+
},
121+
expected: authorInfo{},
122+
},
123+
{
124+
desc: "invalid",
125+
lc: &linter.Config{
126+
Linter: &FakeLinter{name: "fake"},
127+
OriginalURL: "https://example.com/linter",
128+
},
129+
expected: authorInfo{},
130+
},
131+
}
132+
133+
for _, test := range testCases {
134+
t.Run(test.desc, func(t *testing.T) {
135+
t.Parallel()
136+
137+
info := extractInfo(test.lc)
138+
139+
assert.Equal(t, test.expected, info)
140+
})
141+
}
142+
}

0 commit comments

Comments
 (0)