Skip to content

Commit

Permalink
Add check for empty version in git CloseDraft
Browse files Browse the repository at this point in the history
  • Loading branch information
kushnaidu committed Nov 4, 2024
1 parent 3eed742 commit 5acb87c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 2 additions & 4 deletions pkg/cache/memory/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/nephio-project/porch/pkg/cache"
"github.com/nephio-project/porch/pkg/repository"
"go.opentelemetry.io/otel/trace"
"k8s.io/klog/v2"
)

type cachedDraft struct {
Expand All @@ -44,7 +43,6 @@ func (cd *cachedDraft) Close(ctx context.Context, version string) (repository.Pa
if err != nil {
return nil, err
}
klog.Infof("Pkgrev version mismatch in cache and repo - Refreshing cache.")
}

revisions, err := cd.cache.ListPackageRevisions(ctx, repository.ListPackageRevisionFilter{
Expand All @@ -61,12 +59,12 @@ func (cd *cachedDraft) Close(ctx context.Context, version string) (repository.Pa
}
}

v, err = repository.NextRevisionNumber(revs)
nextVersion, err := repository.NextRevisionNumber(revs)
if err != nil {
return nil, err
}

if closed, err := cd.PackageDraft.Close(ctx, v); err != nil {
if closed, err := cd.PackageDraft.Close(ctx, nextVersion); err != nil {
return nil, err
} else {
return cd.cache.update(ctx, closed)
Expand Down
3 changes: 3 additions & 0 deletions pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,9 @@ func (r *gitRepository) CloseDraft(ctx context.Context, version string, d *gitPa
switch d.lifecycle {
case v1alpha1.PackageRevisionLifecyclePublished, v1alpha1.PackageRevisionLifecycleDeletionProposed:

if version == "" {
return nil, errors.New("Version cannot be empty for the next package revision")
}
d.revision = version

// Finalize the package revision. Commit it to main branch.
Expand Down

0 comments on commit 5acb87c

Please sign in to comment.