Skip to content

Support annotate command for release bundle #1110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3003,6 +3003,43 @@ resp, err := serviceManager.RemoteDeleteReleaseBundle(params, dryRun)
exists, err := serviceManager.ReleaseBundleExists(rbName, rbVersion, projectKey)
```

#### Annotate Release Bundle
```go
rbDetails := ReleaseBundleDetails{"rbName", "rbVersion"}
queryParams := CommonOptionalQueryParams{}
queryParams.ProjectKey = "project"

cmd := NewReleaseBundleAnnotateCommand()
serverDetails := &config.ServerDetails{
ArtifactoryUrl: "https://artifactory.example.com",
}
cmd.SetServerDetails(serverDetails)
annotateParams := lifecycle.AnnotateOperationParams{
RbTag: lifecycle.RbAnnotationTag{
Tag: "bundle-tag",
Exist: true,
},
RbProps: lifecycle.RbAnnotationProps{
Properties:props.ToMap(),
Exists: false,
},
RbDelProps: services.RbDelProps{
Keys: "key1,key2",
Exist: false,
},
RbDetails: rbDetails,
QueryParams: queryParams,
PropertyParams: lifecycle.CommonPropParams{
Path: "manifest-path",
Recursive: false,
},
ArtifactoryUrl: services.ArtCommonParams{
Url: cmd.ServerDetails().ArtifactoryUrl,
},
}

resp, err := serviceManager.AnnotateReleaseBundle(params)
```
## Evidence APIs

### Creating Evidence Service Manager
Expand Down
124 changes: 124 additions & 0 deletions lifecycle/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package lifecycle

import (
"encoding/json"
"fmt"
artifactoryAuth "github.com/jfrog/jfrog-client-go/artifactory/auth"
"github.com/jfrog/jfrog-client-go/artifactory/services/utils"
"github.com/jfrog/jfrog-client-go/http/jfroghttpclient"
lifecycle "github.com/jfrog/jfrog-client-go/lifecycle/services"
"github.com/stretchr/testify/assert"
Expand All @@ -12,6 +14,11 @@ import (
"time"
)

const (
rbManifestName = "release-bundle.json.evd"
releaseBundlesV2 = "release-bundles-v2"
)

var testRb = lifecycle.ReleaseBundleDetails{
ReleaseBundleName: "bundle-test",
ReleaseBundleVersion: "1.2.3",
Expand Down Expand Up @@ -285,3 +292,120 @@ func TestIsReleaseBundleExistWithProject(t *testing.T) {
assert.NoError(t, err)
assert.False(t, exist)
}

func TestReleaseBundleAnnotate(t *testing.T) {
mockServer, rbService := createMockServer(t, func(w http.ResponseWriter, r *http.Request) {
if r.RequestURI == "/"+lifecycle.GetReleaseBundleSetTagApi(testRb) {
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte(`{
{
"repository_key": "release-bundles-v2",
"release_bundle_name": "bundle-test",
"release_bundle_version": "1.2.3",
"release_bundle_tag" : "bundle-tag"
}
}`))
assert.NoError(t, err)
}
if r.RequestURI == "/artifactory/"+lifecycle.PropertiesBaseApi {
w.WriteHeader(http.StatusOK) // Status 201
writeMockStatusResponse(t, w, map[string]interface{}{"message": "Created", "status": "201"})
}
})
defer mockServer.Close()
properties := "environment=qa335;buildNumber=335"
annotateOperationParams := buildAnnotationOperationParams(testRb, "default", "bundle-tag", properties,
"environment", mockServer.URL)
err := rbService.AnnotateReleaseBundle(annotateOperationParams)
assert.NoError(t, err)
}

func testAnnotate(t *testing.T, projectKey, tag, properties, delProperties string, expectError bool) {
mockServer, rbService := createMockServer(t, func(w http.ResponseWriter, r *http.Request) {
if r.RequestURI == "/"+lifecycle.GetReleaseBundleSetTagApi(testRb) {
w.WriteHeader(http.StatusOK)
}
if r.RequestURI == "/artifactory/"+lifecycle.PropertiesBaseApi {
w.WriteHeader(http.StatusNoContent) // Status 204
writeMockStatusResponse(t, w, map[string]interface{}{"message": "Created", "status": "201"})
}
if r.RequestURI == "/artifactory/"+lifecycle.PropertiesBaseApi {
w.WriteHeader(http.StatusNoContent) // Status 200
}
})
defer mockServer.Close()
annotateOperationParams := buildAnnotationOperationParams(testRb, projectKey, tag, properties, delProperties,
mockServer.URL)
err := rbService.AnnotateReleaseBundle(annotateOperationParams)
if expectError {
assert.Error(t, err)
return
}
assert.NoError(t, err)
}

func TestReleaseBundleAnnotationCases(t *testing.T) {
testCases := []struct {
name string
projectKey string
tag string
properties string
delProperties string
expectError bool
}{
{"tag, properties, del-prop are not empty, project are empty", "", "bundle-tag", "prop1=1;prop2=2", "prop1", false},
{"tag, property, del-prop are not empty, project is default", "default", "bundle-tag", "prop1=1;prop2=2", "prop1", false},
{"tag is empty, del-prop is empty", "default", "", "prop1=1;prop2=2", "", false},
{"property is empty, del-prop is empty, tag isn't empty, project is default", "default", "bundle-tag", "", "", false},
{"property is empty", "project", "bundle-tag", "", "", false},
{"property is one pair, tag isn't empty", "project", "bundle-tag", "prop1=1", "prop1", false},
{"property is one pair, tag is empty", "project", "", "prop1=1", "", false},
}

for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
testAnnotate(t, test.projectKey, test.tag, test.properties, test.delProperties, test.expectError)
})
}
}

func buildAnnotationOperationParams(rbDetails lifecycle.ReleaseBundleDetails, projectKey, bundleTag, properties, delProperties,
artUrl string) lifecycle.AnnotateOperationParams {
props, _ := utils.ParseProperties(properties)
annotateOperationParams := lifecycle.AnnotateOperationParams{
RbTag: lifecycle.RbAnnotationTag{
Tag: bundleTag,
Exist: true,
},
RbProps: lifecycle.RbAnnotationProps{
Properties: props.ToMap(),
Exist: true,
},
RbDetails: rbDetails,
QueryParams: lifecycle.CommonOptionalQueryParams{
ProjectKey: projectKey,
},
PropertyParams: lifecycle.CommonPropParams{
Path: resolveManifestPath(projectKey, rbDetails.ReleaseBundleName, rbDetails.ReleaseBundleVersion),
Recursive: false,
},
RbDelProps: lifecycle.RbDelProps{
Keys: delProperties,
Exist: true,
},
ArtifactoryUrl: lifecycle.ArtCommonParams{
Url: artUrl + "/artifactory/",
},
}
return annotateOperationParams
}

func resolveManifestPath(projectKey, bundleName, bundleVersion string) string {
return fmt.Sprintf("%s/%s/%s/%s", resolveRepoKey(projectKey), bundleName, bundleVersion, rbManifestName)
}
func resolveRepoKey(project string) string {
if project == "" || project == "default" {
return releaseBundlesV2
}
return fmt.Sprintf("%s-%s", project, releaseBundlesV2)
}
5 changes: 5 additions & 0 deletions lifecycle/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,8 @@ func (lcs *LifecycleServicesManager) IsReleaseBundleExist(rbName, rbVersion, pro
rbService := lifecycle.NewReleaseBundlesService(lcs.config.GetServiceDetails(), lcs.client)
return rbService.ReleaseBundleExists(rbName, rbVersion, projectKey)
}

func (lcs *LifecycleServicesManager) AnnotateReleaseBundle(params lifecycle.AnnotateOperationParams) error {
rbService := lifecycle.NewReleaseBundlesService(lcs.config.GetServiceDetails(), lcs.client)
return rbService.AnnotateReleaseBundle(params)
}
Loading
Loading