From 2d087468d76e4ff4aa8c94b1d7981ca71383d467 Mon Sep 17 00:00:00 2001 From: ezmcdja Date: Tue, 22 Oct 2024 16:17:48 +0100 Subject: [PATCH] #814 - move directory matching alignment to Git side instead of PackageRevisionKey - in Git-side CloseDraft method, trim directory path off full package path before listing PackageRevisions - ensuring only the package name will be used when matching PackageRevisions to filter out, whether or not the repo has a directory set https://github.com/nephio-project/nephio/issues/814 --- pkg/git/git.go | 4 +++- pkg/git/package.go | 1 - pkg/repository/repository.go | 14 +++++--------- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/pkg/git/git.go b/pkg/git/git.go index 0276c23d..985085b9 100644 --- a/pkg/git/git.go +++ b/pkg/git/git.go @@ -1493,8 +1493,10 @@ func (r *gitRepository) CloseDraft(ctx context.Context, d *gitPackageDraft) (*gi switch d.lifecycle { case v1alpha1.PackageRevisionLifecyclePublished, v1alpha1.PackageRevisionLifecycleDeletionProposed: // Finalize the package revision. Assign it a revision number of latest + 1. + packageDirectory := d.parent.directory + packageName := strings.TrimPrefix(d.path, packageDirectory+"/") revisions, err := r.listPackageRevisions(ctx, repository.ListPackageRevisionFilter{ - Package: d.path, + Package: packageName, }) if err != nil { return nil, err diff --git a/pkg/git/package.go b/pkg/git/package.go index 551701fe..b23c05f0 100644 --- a/pkg/git/package.go +++ b/pkg/git/package.go @@ -102,7 +102,6 @@ func (p *gitPackageRevision) Key() repository.PackageRevisionKey { return repository.PackageRevisionKey{ Repository: p.repo.name, - Directory: p.repo.directory, Package: packageName, Revision: p.revision, WorkspaceName: p.workspaceName, diff --git a/pkg/repository/repository.go b/pkg/repository/repository.go index 30e040a1..d36dd783 100644 --- a/pkg/repository/repository.go +++ b/pkg/repository/repository.go @@ -17,7 +17,6 @@ package repository import ( "context" "fmt" - "strings" "github.com/go-git/go-git/v5/plumbing/transport" "github.com/nephio-project/porch/api/porch/v1alpha1" @@ -32,13 +31,13 @@ type PackageResources struct { } type PackageRevisionKey struct { - Repository, Directory, Package, Revision string - WorkspaceName v1alpha1.WorkspaceName + Repository, Package, Revision string + WorkspaceName v1alpha1.WorkspaceName } func (n PackageRevisionKey) String() string { - return fmt.Sprintf("Repository: %q, Directory: %q, Package: %q, Revision: %q, WorkspaceName: %q", - n.Repository, n.Directory, n.Package, n.Revision, string(n.WorkspaceName)) + return fmt.Sprintf("Repository: %q, Package: %q, Revision: %q, WorkspaceName: %q", + n.Repository, n.Package, n.Revision, string(n.WorkspaceName)) } type PackageKey struct { @@ -152,10 +151,7 @@ type ListPackageRevisionFilter struct { func (f *ListPackageRevisionFilter) Matches(p PackageRevision) bool { packageKey := p.Key() - fullPackagePath := strings.TrimPrefix( - fmt.Sprintf("%s/%s", packageKey.Directory, packageKey.Package), - "/") - if f.Package != "" && f.Package != fullPackagePath { + if f.Package != "" && f.Package != packageKey.Package { return false } if f.Revision != "" && f.Revision != packageKey.Revision {