Skip to content

Commit

Permalink
#814 - move directory matching alignment to Git side instead of Packa…
Browse files Browse the repository at this point in the history
…geRevisionKey

- 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

nephio-project/nephio#814
  • Loading branch information
JamesMcDermott committed Oct 22, 2024
1 parent 76b9a2e commit 2d08746
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
4 changes: 3 additions & 1 deletion pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion pkg/git/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 5 additions & 9 deletions pkg/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 2d08746

Please sign in to comment.