Skip to content
Open
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
24 changes: 24 additions & 0 deletions pkg/releases/release_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,30 @@ func GetReleaseDeploymentTemplate(client newclient.Client, spaceID string, relea
return res, nil
}

// SnapshotVariables refreshes (re-snapshots) the variable snapshot for an existing release.
// It POSTs to /api/{spaceId}/releases/{releaseId}/snapshot-variables and returns the updated release.
func SnapshotVariables(client newclient.Client, spaceID string, releaseID string) (*Release, error) {
if client == nil {
return nil, internal.CreateInvalidParameterError("SnapshotVariables", "client")
}
if spaceID == "" {
return nil, internal.CreateInvalidParameterError("SnapshotVariables", "spaceID")
}
if releaseID == "" {
return nil, internal.CreateInvalidParameterError("SnapshotVariables", "releaseID")
}

expandedUri, err := client.URITemplateCache().Expand(uritemplates.ReleaseSnapshotVariables, map[string]any{
"spaceId": spaceID,
"releaseId": releaseID,
})
if err != nil {
return nil, err
}

return newclient.Post[Release](client.HttpSession(), expandedUri, nil)
}

// ----- Experimental ---------------------------------------------------------

// GetReleasesInProjectChannel is EXPERIMENTAL
Expand Down
22 changes: 22 additions & 0 deletions pkg/releases/release_service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package releases

import (
"testing"

"github.com/OctopusDeploy/go-octopusdeploy/v2/internal"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/newclient"
"github.com/stretchr/testify/assert"
)

func TestReleaseSnapshotVariablesValidation(t *testing.T) {
_, err := SnapshotVariables(nil, "Spaces-1", "Releases-1")
assert.Equal(t, internal.CreateInvalidParameterError("SnapshotVariables", "client"), err)

client := newclient.NewClient(&newclient.HttpSession{})

_, err = SnapshotVariables(client, "", "Releases-1")
assert.Equal(t, internal.CreateInvalidParameterError("SnapshotVariables", "spaceID"), err)

_, err = SnapshotVariables(client, "Spaces-1", "")
assert.Equal(t, internal.CreateInvalidParameterError("SnapshotVariables", "releaseID"), err)
}
24 changes: 24 additions & 0 deletions pkg/runbooks/runbook_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,30 @@ func GetSnapshot(client newclient.Client, spaceID string, projectID string, snap
return newclient.Get[RunbookSnapshot](client.HttpSession(), expandedUri)
}

// SnapshotVariables refreshes (re-snapshots) the variable snapshot for an existing runbook snapshot.
// It POSTs to /api/{spaceId}/runbookSnapshots/{snapshotId}/snapshot-variables and returns the updated snapshot.
func SnapshotVariables(client newclient.Client, spaceID string, snapshotID string) (*RunbookSnapshot, error) {
if client == nil {
return nil, internal.CreateRequiredParameterIsEmptyOrNilError("client")
}
if spaceID == "" {
return nil, internal.CreateRequiredParameterIsEmptyOrNilError("spaceID")
}
if snapshotID == "" {
return nil, internal.CreateRequiredParameterIsEmptyOrNilError("snapshotID")
}

expandedUri, err := client.URITemplateCache().Expand(uritemplates.RunbookSnapshotVariables, map[string]any{
"spaceId": spaceID,
"snapshotId": snapshotID,
})
if err != nil {
return nil, err
}

return newclient.Post[RunbookSnapshot](client.HttpSession(), expandedUri, nil)
}

// ListEnvironments returns the list of valid environments for a given runbook
func ListEnvironments(client newclient.Client, spaceID string, projectID string, runbookID string) ([]*environments.Environment, error) {
if spaceID == "" {
Expand Down
14 changes: 14 additions & 0 deletions pkg/runbooks/runbook_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/OctopusDeploy/go-octopusdeploy/v2/internal"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/constants"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/newclient"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/services"
"github.com/dghubble/sling"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -54,3 +55,16 @@ func TestRunbookServiceNew(t *testing.T) {
})
}
}

func TestRunbookSnapshotVariablesValidation(t *testing.T) {
_, err := SnapshotVariables(nil, "Spaces-1", "RunbookSnapshots-1")
assert.Equal(t, internal.CreateRequiredParameterIsEmptyOrNilError("client"), err)

client := newclient.NewClient(&newclient.HttpSession{})

_, err = SnapshotVariables(client, "", "RunbookSnapshots-1")
assert.Equal(t, internal.CreateRequiredParameterIsEmptyOrNilError("spaceID"), err)

_, err = SnapshotVariables(client, "Spaces-1", "")
assert.Equal(t, internal.CreateRequiredParameterIsEmptyOrNilError("snapshotID"), err)
}
2 changes: 2 additions & 0 deletions uritemplates/links.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
ReleasesByProject = "/api/{spaceId}/projects/{projectId}/releases{/version}{?skip,take,searchByVersion}" // GET
ReleasesByProjectAndChannel = "/api/{spaceId}/projects/{projectId}/channels/{channelId}/releases{?skip,take,searchByVersion}" // GET
ReleaseDeploymentTemplate = "/api/{spaceId}/releases/{releaseId}/deployments/template" // GET
ReleaseSnapshotVariables = "/api/{spaceId}/releases/{releaseId}/snapshot-variables" // POST

Runbooks = "/api/{spaceId}/runbooks{/id}{?skip,take,ids,partialName,clone,projectIds}" // GET
RunbooksByProject = "/api/{spaceId}/projects/{projectId}/runbooks{?skip,take,partialName}" // GET
Expand All @@ -43,6 +44,7 @@ const (
RunbookSnapshotsByProject = "/api/{spaceId}/projects/{projectId}/runbookSnapshots{/name}{?skip,take,searchByName}" // GET
RunbookSnapshotRunPreview = "/api/{spaceId}/runbookSnapshots/{snapshotId}/runbookRuns/preview/{environmentId}{?includeDisabledSteps}" // GET
RunbookRunTenantPreview = "/api/{spaceId}/projects/{projectId}/runbooks/{runbookId}/runbookRuns/previews" // POST
RunbookSnapshotVariables = "/api/{spaceId}/runbookSnapshots/{snapshotId}/snapshot-variables" // POST

GitRunbookById = "/api/{spaceId}/projects/{projectId}/{gitRef}/runbooks/{id}" // GET, DELETE
GitRunbooksByProject = "/api/{spaceId}/projects/{projectId}/{gitRef}/runbooks{?skip,take,partialName}" // GET
Expand Down