зеркало из https://github.com/golang/pkgsite.git
internal/frontend: add deprecated/retracted info to versions
For golang/go#43265 For golang/go#41321 Change-Id: I1c53af8cd04ec0d3d2b13874cd028a3f97b5101b Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/297509 Trust: Jonathan Amsterdam <jba@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Julie Qiu <julie@golang.org>
This commit is contained in:
Родитель
3848c843bd
Коммит
901f4fe0bf
|
@ -4,6 +4,8 @@
|
|||
license that can be found in the LICENSE file.
|
||||
-->
|
||||
|
||||
{{/* . is internal/frontend.VersionsDetails */}}
|
||||
|
||||
{{define "versions"}}
|
||||
<div class="Versions">
|
||||
<table>
|
||||
|
@ -24,15 +26,24 @@
|
|||
</div>
|
||||
{{end}}
|
||||
|
||||
|
||||
{{/* . is []*internal/frontend.VersionList */}}
|
||||
|
||||
{{define "module_list"}}
|
||||
{{range $major := .}}
|
||||
{{range $i, $v := $major.Versions}}
|
||||
<tr>
|
||||
<td>
|
||||
{{if eq $i 0 }}<div class="Versions-major">{{$major.Major}}</div>{{end}}
|
||||
{{if eq $i 0 }}
|
||||
<div class="Versions-major">
|
||||
{{$major.Major}}
|
||||
{{if $major.Deprecated}}(Deprecated{{with $major.DeprecationComment}}: {{.}}{{end}}){{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
</td>
|
||||
<td>
|
||||
<a href="{{$v.Link}}">{{$v.Version}}</a>
|
||||
{{if $v.Retracted}}(Retracted{{with .RetractionRationale}}: {{.}}){{end}}{{end}}
|
||||
</td>
|
||||
<td>
|
||||
<div class="Versions-commitTime">{{$v.CommitTime}}</div>
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"golang.org/x/mod/module"
|
||||
"golang.org/x/mod/semver"
|
||||
"golang.org/x/pkgsite/internal"
|
||||
"golang.org/x/pkgsite/internal/experiment"
|
||||
"golang.org/x/pkgsite/internal/log"
|
||||
"golang.org/x/pkgsite/internal/postgres"
|
||||
"golang.org/x/pkgsite/internal/stdlib"
|
||||
|
@ -51,6 +52,11 @@ type VersionListKey struct {
|
|||
// Incompatible indicates whether the VersionListKey represents an
|
||||
// incompatible module version.
|
||||
Incompatible bool
|
||||
|
||||
// Deprecated indicates whether the major version is deprecated.
|
||||
Deprecated bool
|
||||
// DeprecationComment holds the reason for deprecation, if any.
|
||||
DeprecationComment string
|
||||
}
|
||||
|
||||
// VersionList holds all versions corresponding to a unique (module path,
|
||||
|
@ -67,8 +73,10 @@ type VersionList struct {
|
|||
type VersionSummary struct {
|
||||
CommitTime string
|
||||
// Link to this version, for use in the anchor href.
|
||||
Link string
|
||||
Version string
|
||||
Link string
|
||||
Version string
|
||||
Retracted bool
|
||||
RetractionRationale string
|
||||
}
|
||||
|
||||
func fetchVersionsDetails(ctx context.Context, ds internal.DataSource, fullPath, modulePath string) (*VersionsDetails, error) {
|
||||
|
@ -92,7 +100,7 @@ func fetchVersionsDetails(ctx context.Context, ds internal.DataSource, fullPath,
|
|||
}
|
||||
return constructUnitURL(versionPath, mi.ModulePath, linkVersion(mi.Version, mi.ModulePath))
|
||||
}
|
||||
return buildVersionDetails(modulePath, versions, linkify), nil
|
||||
return buildVersionDetails(ctx, modulePath, versions, linkify), nil
|
||||
}
|
||||
|
||||
// pathInVersion constructs the full import path of the package corresponding
|
||||
|
@ -119,7 +127,7 @@ func pathInVersion(v1Path string, mi *internal.ModuleInfo) string {
|
|||
// versions tab, organizing major versions into those that have the same module
|
||||
// path as the package version under consideration, and those that don't. The
|
||||
// given versions MUST be sorted first by module path and then by semver.
|
||||
func buildVersionDetails(currentModulePath string, modInfos []*internal.ModuleInfo, linkify func(v *internal.ModuleInfo) string) *VersionsDetails {
|
||||
func buildVersionDetails(ctx context.Context, currentModulePath string, modInfos []*internal.ModuleInfo, linkify func(v *internal.ModuleInfo) string) *VersionsDetails {
|
||||
// lists organizes versions by VersionListKey. Note that major version isn't
|
||||
// sufficient as a key: there are packages contained in the same major
|
||||
// version of different modules, for example github.com/hashicorp/vault/api,
|
||||
|
@ -165,6 +173,12 @@ func buildVersionDetails(currentModulePath string, modInfos []*internal.ModuleIn
|
|||
CommitTime: absoluteTime(mi.CommitTime),
|
||||
Version: linkVersion(mi.Version, mi.ModulePath),
|
||||
}
|
||||
if experiment.IsActive(ctx, internal.ExperimentRetractions) {
|
||||
key.Deprecated = mi.Deprecated
|
||||
key.DeprecationComment = mi.DeprecationComment
|
||||
vs.Retracted = mi.Retracted
|
||||
vs.RetractionRationale = mi.RetractionRationale
|
||||
}
|
||||
if _, ok := lists[key]; !ok {
|
||||
seenLists = append(seenLists, key)
|
||||
}
|
||||
|
|
|
@ -80,6 +80,8 @@ func TestEndToEndProcessing(t *testing.T) {
|
|||
{"example.com/single@v1.0.0/pkg", "hello"},
|
||||
{"example.com/deprecated", "UnitHeader-deprecatedBanner"},
|
||||
{"example.com/retractions@v1.1.0", "UnitHeader-retractedBanner"},
|
||||
{"example.com/deprecated?tab=versions", "Deprecated: use something else"},
|
||||
{"example.com/retractions?tab=versions", "Retracted: bad"},
|
||||
} {
|
||||
t.Run(strings.ReplaceAll(test.url, "/", "_"), func(t *testing.T) {
|
||||
wantKeys = append(wantKeys, "/"+test.url)
|
||||
|
|
Загрузка…
Ссылка в новой задаче