Skip to content

Commit 9b60844

Browse files
authored
feat(internal/godocfx): detect preview versions (#4899)
1 parent 88bfa64 commit 9b60844

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

internal/godocfx/pkgload/load.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func Load(glob, workingDir string, filter []string) ([]Info, error) {
158158
Doc: docPkg,
159159
Fset: fset,
160160
ImportRenames: imports,
161-
Status: pkgStatus(pkgPath, docPkg.Doc),
161+
Status: pkgStatus(pkgPath, docPkg.Doc, idToPkg[pkgPath].Module.Version),
162162
})
163163
}
164164

@@ -170,8 +170,11 @@ func Load(glob, workingDir string, filter []string) ([]Info, error) {
170170
//
171171
// pkgStatus does not use repo-metadata-full.json because it's
172172
// not available for all modules nor all versions.
173-
func pkgStatus(importPath, doc string) string {
173+
func pkgStatus(importPath, doc, version string) string {
174174
switch {
175+
case strings.Contains(version, "-"):
176+
return "preview"
177+
175178
case strings.Contains(doc, "\nDeprecated:"):
176179
return "deprecated"
177180
case strings.Contains(doc, "This package is in alpha"):

internal/godocfx/pkgload/load_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func TestPkgStatus(t *testing.T) {
2020
tests := []struct {
2121
importPath string
2222
doc string
23+
version string
2324
want string
2425
}{
2526
{
@@ -56,10 +57,18 @@ func TestPkgStatus(t *testing.T) {
5657
doc: "Package foo is great\nDeprecated: not anymore",
5758
want: "deprecated", // Deprecated comes before alpha and beta.
5859
},
60+
{
61+
version: "v0.1.0",
62+
want: "",
63+
},
64+
{
65+
version: "v2.1.0-alpha",
66+
want: "preview", // Preview comes before alpha and beta.
67+
},
5968
}
6069
for _, test := range tests {
61-
if got := pkgStatus(test.importPath, test.doc); got != test.want {
62-
t.Errorf("pkgStatus(%q, %q) got %q, want %q", test.importPath, test.doc, got, test.want)
70+
if got := pkgStatus(test.importPath, test.doc, test.version); got != test.want {
71+
t.Errorf("pkgStatus(%q, %q, %q) got %q, want %q", test.importPath, test.doc, test.version, got, test.want)
6372
}
6473
}
6574
}

0 commit comments

Comments
 (0)