Skip to content

Commit

Permalink
move RegistryVersionDeprecation to sourcebundle package
Browse files Browse the repository at this point in the history
  • Loading branch information
Maed223 committed Jun 6, 2024
1 parent e1d3105 commit 3914531
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 20 deletions.
6 changes: 0 additions & 6 deletions sourceaddrs/source_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ type RegistrySource struct {
subPath string
}

type RegistryVersionDeprecation struct {
Version string
Reason string
Link string
}

// sourceSigil implements Source
func (s RegistrySource) sourceSigil() {}

Expand Down
8 changes: 4 additions & 4 deletions sourcebundle/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type Builder struct {
// selected version of each module registry package.
resolvedRegistry map[registryPackageVersion]sourceaddrs.RemoteSource

resolvedRegistryVersionDeprecations map[registryPackageVersion]*sourceaddrs.RegistryVersionDeprecation
resolvedRegistryVersionDeprecations map[registryPackageVersion]*RegistryVersionDeprecation

// registryPackageVersions caches responses from module registry calls to
// look up the available versions for a particular module package. Although
Expand Down Expand Up @@ -109,7 +109,7 @@ func NewBuilder(targetDir string, fetcher PackageFetcher, registryClient Registr
remotePackageDirs: make(map[sourceaddrs.RemotePackage]string),
remotePackageMeta: make(map[sourceaddrs.RemotePackage]*PackageMeta),
resolvedRegistry: make(map[registryPackageVersion]sourceaddrs.RemoteSource),
resolvedRegistryVersionDeprecations: make(map[registryPackageVersion]*sourceaddrs.RegistryVersionDeprecation),
resolvedRegistryVersionDeprecations: make(map[registryPackageVersion]*RegistryVersionDeprecation),
registryPackageVersions: make(map[regaddr.ModulePackage][]ModulePackageInfo),
}, nil
}
Expand Down Expand Up @@ -407,11 +407,11 @@ func (b *Builder) findRegistryPackageSource(ctx context.Context, sourceAddr sour
realSourceAddr = resp.SourceAddr
b.resolvedRegistry[pkgVer] = realSourceAddr

var deprecation *sourceaddrs.RegistryVersionDeprecation
var deprecation *RegistryVersionDeprecation
versionDeprecations := extractVersionDeprecationsFromResponse(availablePackageInfos)
versionDeprecation := versionDeprecations[selectedVersion]
if versionDeprecation != nil {
deprecation = &sourceaddrs.RegistryVersionDeprecation{
deprecation = &RegistryVersionDeprecation{
Version: selectedVersion.String(),
Reason: versionDeprecation.Reason,
Link: versionDeprecation.Link,
Expand Down
4 changes: 2 additions & 2 deletions sourcebundle/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ func TestBuilderRegistryVersionDeprecation(t *testing.T) {
version, _ := versions.ParseVersion("1.0.0")
pkgAddr, _ := sourceaddrs.ParseRegistryPackage("example.com/foo/bar/baz")

wantDeprecations := map[regaddr.ModulePackage]map[versions.Version]*sourceaddrs.RegistryVersionDeprecation{
wantDeprecations := map[regaddr.ModulePackage]map[versions.Version]*RegistryVersionDeprecation{
pkgAddr: {
version: &sourceaddrs.RegistryVersionDeprecation{
version: &RegistryVersionDeprecation{
Version: "1.0.0",
Reason: "test reason",
Link: "test link",
Expand Down
8 changes: 4 additions & 4 deletions sourcebundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Bundle struct {
remotePackageMeta map[sourceaddrs.RemotePackage]*PackageMeta

registryPackageSources map[regaddr.ModulePackage]map[versions.Version]sourceaddrs.RemoteSource
registryPackageVersionDeprecations map[regaddr.ModulePackage]map[versions.Version]*sourceaddrs.RegistryVersionDeprecation
registryPackageVersionDeprecations map[regaddr.ModulePackage]map[versions.Version]*RegistryVersionDeprecation
}

// OpenDir opens a bundle rooted at the given base directory.
Expand All @@ -56,7 +56,7 @@ func OpenDir(baseDir string) (*Bundle, error) {
remotePackageDirs: make(map[sourceaddrs.RemotePackage]string),
remotePackageMeta: make(map[sourceaddrs.RemotePackage]*PackageMeta),
registryPackageSources: make(map[regaddr.ModulePackage]map[versions.Version]sourceaddrs.RemoteSource),
registryPackageVersionDeprecations: make(map[regaddr.ModulePackage]map[versions.Version]*sourceaddrs.RegistryVersionDeprecation),
registryPackageVersionDeprecations: make(map[regaddr.ModulePackage]map[versions.Version]*RegistryVersionDeprecation),
}

manifestSrc, err := os.ReadFile(filepath.Join(rootDir, manifestFilename))
Expand Down Expand Up @@ -112,7 +112,7 @@ func OpenDir(baseDir string) (*Bundle, error) {
}
deprecations := ret.registryPackageVersionDeprecations[pkgAddr]
if deprecations == nil {
deprecations = make(map[versions.Version]*sourceaddrs.RegistryVersionDeprecation)
deprecations = make(map[versions.Version]*RegistryVersionDeprecation)
ret.registryPackageVersionDeprecations[pkgAddr] = deprecations
}
for versionStr, mv := range rpm.Versions {
Expand Down Expand Up @@ -362,7 +362,7 @@ func (b *Bundle) RegistryPackageVersions(pkgAddr regaddr.ModulePackage) versions
return ret
}

func (b *Bundle) RegistryPackageVersionDeprecation(pkgAddr regaddr.ModulePackage, version versions.Version) *sourceaddrs.RegistryVersionDeprecation {
func (b *Bundle) RegistryPackageVersionDeprecation(pkgAddr regaddr.ModulePackage, version versions.Version) *RegistryVersionDeprecation {
deprecation := b.registryPackageVersionDeprecations[pkgAddr][version]
return deprecation
}
Expand Down
6 changes: 2 additions & 4 deletions sourcebundle/manifest_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

package sourcebundle

import "github.com/hashicorp/go-slug/sourceaddrs"

// This file contains some internal-only types used to help with marshalling
// and unmarshalling our manifest file format. The manifest format is not
// itself a public interface, so these should stay unexported and any caller
Expand Down Expand Up @@ -45,8 +43,8 @@ type manifestRegistryVersion struct {
// This SourceAddr is a full source address, so it might potentially
// have a sub-path portion. If it does then it must be combined with
// any sub-path included in the user's registry module source address.
SourceAddr string `json:"source"`
Deprecation *sourceaddrs.RegistryVersionDeprecation `json:"deprecation"`
SourceAddr string `json:"source"`
Deprecation *RegistryVersionDeprecation `json:"deprecation"`
}

type manifestPackageMeta struct {
Expand Down
6 changes: 6 additions & 0 deletions sourcebundle/package_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ type PackageMeta struct {
gitCommitMessage string
}

type RegistryVersionDeprecation struct {
Version string
Reason string
Link string
}

// PackageMetaWithGitMetadata returns a [PackageMeta] object with a Git Commit
// ID and message tracked.
//
Expand Down

0 comments on commit 3914531

Please sign in to comment.