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

support start playground offline when specify version #1553

Merged
merged 3 commits into from
Sep 7, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 27 additions & 22 deletions pkg/repository/v1_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,31 @@ func (r *V1Repository) FetchComponentManifest(id string, withYanked bool) (com *
return r.updateComponentManifest(id, withYanked)
}

// LocalComponentManifest load the component manifest from local.
func (r *V1Repository) LocalComponentManifest(id string, withYanked bool) (com *v1manifest.Component, err error) {
index := v1manifest.Index{}
_, exists, err := r.Local().LoadManifest(&index)
if err != nil {
return nil, err
}
if !exists {
err = r.ensureManifests()
if err != nil {
return nil, err
}
_, _, err := r.Local().LoadManifest(&index)

if err != nil {
return nil, err
}
}

components := index.ComponentList()
comp := components[id]
filename := v1manifest.ComponentManifestFilename(id)
return r.Local().LoadComponentManifest(&comp, filename)
}

// ComponentVersion returns version item of a component
func (r *V1Repository) ComponentVersion(id, ver string, includeYanked bool) (*v1manifest.VersionItem, error) {
manifest, err := r.FetchComponentManifest(id, includeYanked)
Expand Down Expand Up @@ -758,27 +783,7 @@ func (r *V1Repository) ComponentVersion(id, ver string, includeYanked bool) (*v1

// LocalComponentVersion returns version item of a component from local manifest file
func (r *V1Repository) LocalComponentVersion(id, ver string, includeYanked bool) (*v1manifest.VersionItem, error) {
index := v1manifest.Index{}
_, exists, err := r.Local().LoadManifest(&index)
if err != nil {
return nil, err
}
if !exists {
err = r.ensureManifests()
if err != nil {
return nil, err
}
_, _, err := r.Local().LoadManifest(&index)

if err != nil {
return nil, err
}
}

components := index.ComponentList()
comp := components[id]
filename := v1manifest.ComponentManifestFilename(id)
manifest, err := r.Local().LoadComponentManifest(&comp, filename)
manifest, err := r.LocalComponentManifest(id, includeYanked)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -806,7 +811,7 @@ func (r *V1Repository) LocalComponentVersion(id, ver string, includeYanked bool)

// ResolveComponentVersionWithPlatform resolves the latest version of a component that satisfies the constraint
func (r *V1Repository) ResolveComponentVersionWithPlatform(id, constraint, platform string) (utils.Version, error) {
manifest, err := r.FetchComponentManifest(id, false)
manifest, err := r.LocalComponentManifest(id, false)
if err != nil {
return "", err
}
Expand Down