Skip to content

Commit

Permalink
Merge pull request #317 from somtochiama/sourceignore
Browse files Browse the repository at this point in the history
[pkg/oci] Export fields in ListOptions
  • Loading branch information
stefanprodan authored Aug 17, 2022
2 parents 63d691c + ede70c3 commit b3a659d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
20 changes: 11 additions & 9 deletions oci/client/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ import (
"github.com/fluxcd/pkg/version"
)

// ListOptions contains options for listing tags from an OCI repository
// ListOptions contains options for listing tags from an OCI repository.
type ListOptions struct {
semverFilter string
regexFilter string
// SemverFilter contains semver for filtering tags.
SemverFilter string
// RegexFilter contains a regex that tags will be filtered by.
RegexFilter string
}

// List fetches the tags and their manifests for a given OCI repository.
Expand All @@ -48,18 +50,18 @@ func (c *Client) List(ctx context.Context, url string, opts ListOptions) ([]Meta
sort.Slice(tags, func(i, j int) bool { return tags[i] > tags[j] })

var constraint *semver.Constraints
if opts.semverFilter != "" {
constraint, err = semver.NewConstraint(opts.semverFilter)
if opts.SemverFilter != "" {
constraint, err = semver.NewConstraint(opts.SemverFilter)
if err != nil {
return nil, fmt.Errorf("semver '%s' parse error: %w", opts.semverFilter, err)
return nil, fmt.Errorf("semver '%s' parse error: %w", opts.SemverFilter, err)
}
}

var re *regexp.Regexp
if opts.regexFilter != "" {
re, err = regexp.Compile(opts.regexFilter)
if opts.RegexFilter != "" {
re, err = regexp.Compile(opts.RegexFilter)
if err != nil {
return nil, fmt.Errorf("regex '%s' parse error: %w", opts.regexFilter, err)
return nil, fmt.Errorf("regex '%s' parse error: %w", opts.RegexFilter, err)
}
}

Expand Down
4 changes: 2 additions & 2 deletions oci/client/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func Test_List(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
g := NewWithT(t)
metadata, err := c.List(ctx, fmt.Sprintf("%s/%s", dockerReg, repo), ListOptions{
semverFilter: tt.semverFilter,
regexFilter: tt.regexFilter,
SemverFilter: tt.semverFilter,
RegexFilter: tt.regexFilter,
})
g.Expect(err).ToNot(HaveOccurred())

Expand Down

0 comments on commit b3a659d

Please sign in to comment.