Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(internal/godocfx): detect preview versions #4899

Merged
merged 1 commit into from Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions internal/godocfx/pkgload/load.go
Expand Up @@ -158,7 +158,7 @@ func Load(glob, workingDir string, filter []string) ([]Info, error) {
Doc: docPkg,
Fset: fset,
ImportRenames: imports,
Status: pkgStatus(pkgPath, docPkg.Doc),
Status: pkgStatus(pkgPath, docPkg.Doc, idToPkg[pkgPath].Module.Version),
})
}

Expand All @@ -170,8 +170,11 @@ func Load(glob, workingDir string, filter []string) ([]Info, error) {
//
// pkgStatus does not use repo-metadata-full.json because it's
// not available for all modules nor all versions.
func pkgStatus(importPath, doc string) string {
func pkgStatus(importPath, doc, version string) string {
switch {
case strings.Contains(version, "-"):
return "preview"

case strings.Contains(doc, "\nDeprecated:"):
return "deprecated"
case strings.Contains(doc, "This package is in alpha"):
Expand Down
13 changes: 11 additions & 2 deletions internal/godocfx/pkgload/load_test.go
Expand Up @@ -20,6 +20,7 @@ func TestPkgStatus(t *testing.T) {
tests := []struct {
importPath string
doc string
version string
want string
}{
{
Expand Down Expand Up @@ -56,10 +57,18 @@ func TestPkgStatus(t *testing.T) {
doc: "Package foo is great\nDeprecated: not anymore",
want: "deprecated", // Deprecated comes before alpha and beta.
},
{
version: "v0.1.0",
want: "",
},
{
version: "v2.1.0-alpha",
want: "preview", // Preview comes before alpha and beta.
},
}
for _, test := range tests {
if got := pkgStatus(test.importPath, test.doc); got != test.want {
t.Errorf("pkgStatus(%q, %q) got %q, want %q", test.importPath, test.doc, got, test.want)
if got := pkgStatus(test.importPath, test.doc, test.version); got != test.want {
t.Errorf("pkgStatus(%q, %q, %q) got %q, want %q", test.importPath, test.doc, test.version, got, test.want)
}
}
}