Skip to content

Commit

Permalink
Merge pull request #186 from mittwald/fix/return-artifact-with-labels
Browse files Browse the repository at this point in the history
always return labels when listing artifacts
  • Loading branch information
elenz97 authored Feb 9, 2024
2 parents 17f5762 + 2c2d827 commit ebbfe43
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion apiv2/pkg/clients/artifact/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package artifact
import (
"context"
"fmt"

"github.com/go-openapi/runtime"
v2client "github.com/mittwald/goharbor-client/v5/apiv2/internal/api/client"
"github.com/mittwald/goharbor-client/v5/apiv2/internal/api/client/artifact"
"github.com/mittwald/goharbor-client/v5/apiv2/model"
"github.com/mittwald/goharbor-client/v5/apiv2/pkg/config"
"github.com/mittwald/goharbor-client/v5/apiv2/pkg/util"
)

// RESTClient is a subclient for handling artifact related actions.
Expand Down Expand Up @@ -164,6 +164,7 @@ func (c *RESTClient) GetArtifact(ctx context.Context, projectName, repositoryNam
params.WithRepositoryName(repositoryName)
params.WithReference(reference)
params.WithContext(ctx)
params.WithWithLabel(util.BoolPtr(true))

resp, err := c.V2Client.Artifact.GetArtifact(params, c.AuthInfo)
if err != nil {
Expand Down Expand Up @@ -202,6 +203,7 @@ func (c *RESTClient) ListArtifacts(ctx context.Context, projectName, repositoryN
params.Sort = &c.Options.Sort
params.WithProjectName(projectName)
params.WithRepositoryName(repositoryName)
params.WithWithLabel(util.BoolPtr(true))

for {
resp, err := c.V2Client.Artifact.ListArtifacts(params, c.AuthInfo)
Expand Down
3 changes: 3 additions & 0 deletions apiv2/pkg/clients/artifact/artifact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package artifact

import (
"context"
"github.com/mittwald/goharbor-client/v5/apiv2/pkg/util"
"testing"

"github.com/mittwald/goharbor-client/v5/apiv2/internal/api/client/artifact"
Expand Down Expand Up @@ -223,6 +224,7 @@ func TestRESTClient_GetArtifact(t *testing.T) {
getParams.WithRepositoryName(repositoryName)
getParams.WithReference(reference)
getParams.WithContext(ctx)
getParams.WithWithLabel(util.BoolPtr(true))

getParams.WithTimeout(apiClient.Options.Timeout)

Expand All @@ -248,6 +250,7 @@ func TestRESTClient_ListArtifacts(t *testing.T) {
listParams.WithSort(&apiClient.Options.Sort)
listParams.WithQ(&apiClient.Options.Query)
listParams.WithTimeout(apiClient.Options.Timeout)
listParams.WithWithLabel(util.BoolPtr(true))

mockClient.Artifact.On("ListArtifacts", listParams, mock.AnythingOfType("runtime.ClientAuthInfoWriterFunc")).
Return(&artifact.ListArtifactsOK{Payload: []*model.Artifact{}}, nil)
Expand Down
4 changes: 4 additions & 0 deletions apiv2/pkg/util/pointer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ func Int64Ptr(in int64) *int64 {
func StringPtr(in string) *string {
return &in
}

func BoolPtr(in bool) *bool {
return &in
}

0 comments on commit ebbfe43

Please sign in to comment.