Skip to content

Commit

Permalink
feat: Adds support for deleting Git runbooks (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
geofflamrock authored Nov 22, 2024
1 parent 2cac917 commit 2d95b7e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
55 changes: 55 additions & 0 deletions pkg/runbooks/runbook_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,34 @@ func ListGitRunbooks(client newclient.Client, spaceID string, projectID string,
return newclient.Get[resources.Resources[*Runbook]](client.HttpSession(), expandedUri)
}

// GetGitRunbookByID returns the runbook that matches the input ID and GitRef. If one cannot be
// found, it returns nil and an error.
func GetGitRunbookByID(client newclient.Client, spaceID string, projectID string, gitRef string, ID string) (*Runbook, error) {
if spaceID == "" {
return nil, internal.CreateRequiredParameterIsEmptyOrNilError("spaceID")
}
if projectID == "" {
return nil, internal.CreateRequiredParameterIsEmptyOrNilError("projectID")
}
if gitRef == "" {
return nil, internal.CreateRequiredParameterIsEmptyOrNilError("gitRef")
}
if ID == "" {
return nil, internal.CreateRequiredParameterIsEmptyOrNilError("ID")
}
templateParams := map[string]any{"spaceId": spaceID, "projectId": projectID, "gitRef": gitRef, "id": ID}
expandedUri, err := client.URITemplateCache().Expand(uritemplates.GitRunbookById, templateParams)
if err != nil {
return nil, err
}
runbook, err := newclient.Get[Runbook](client.HttpSession(), expandedUri)
if err != nil {
return nil, err
}

return runbook, nil
}

// GetGitRunbookByName searches for a single runbook with name of 'name'.
// If no such runbook can be found, will return nil, nil
func GetGitRunbookByName(client newclient.Client, spaceID string, projectID string, gitRef string, name string) (*Runbook, error) {
Expand Down Expand Up @@ -408,6 +436,33 @@ func GetGitRunbookByName(client newclient.Client, spaceID string, projectID stri
return nil, nil
}

// DeleteGitRunbook deletes the runbook that matches the input ID and GitRef.
func DeleteGitRunbook(client newclient.Client, spaceID string, projectID string, gitRef string, ID string) error {
if spaceID == "" {
return internal.CreateRequiredParameterIsEmptyOrNilError("spaceID")
}
if projectID == "" {
return internal.CreateRequiredParameterIsEmptyOrNilError("projectID")
}
if gitRef == "" {
return internal.CreateRequiredParameterIsEmptyOrNilError("gitRef")
}
if ID == "" {
return internal.CreateRequiredParameterIsEmptyOrNilError("ID")
}
templateParams := map[string]any{"spaceId": spaceID, "projectId": projectID, "gitRef": gitRef, "id": ID}
expandedUri, err := client.URITemplateCache().Expand(uritemplates.GitRunbookById, templateParams)
if err != nil {
return err
}
err = newclient.Delete(client.HttpSession(), expandedUri)
if err != nil {
return err
}

return nil
}

// ListEnvironmentsForGitRunbook returns the list of valid environments for a given runbook stored in Git
func ListEnvironmentsForGitRunbook(client newclient.Client, spaceID string, projectID string, runbookID string, gitRef string) ([]*environments.Environment, error) {
if spaceID == "" {
Expand Down
3 changes: 2 additions & 1 deletion uritemplates/links.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
RunbookSnapshotRunPreview = "/api/{spaceId}/runbookSnapshots/{snapshotId}/runbookRuns/preview/{environmentId}{?includeDisabledSteps}" // GET
RunbookRunTenantPreview = "/api/{spaceId}/projects/{projectId}/runbooks/{runbookId}/runbookRuns/previews" // POST

GitRunbookById = "/api/{spaceId}/projects/{projectId}/{gitRef}/runbooks/{id}" // GET, DELETE
GitRunbooksByProject = "/api/{spaceId}/projects/{projectId}/{gitRef}/runbooks{?skip,take,partialName}" // GET
GitRunbookEnvironments = "/api/{spaceId}/projects/{projectId}/{gitRef}/runbooks/{runbookId}/environments" // GET
GitRunbookProcess = "/api/{spaceId}/projects/{projectId}/{gitRef}/runbookProcesses/{id}" // GET
Expand All @@ -52,4 +53,4 @@ const (
ProjectVariablesByGitRef = "/api/{spaceId}/projects/{projectId}/{gitRef}/variables"
ProjectBranchesV2 = "/api/{spaceId}/projects/{projectId}/git/branches/v2"
ProjectBranches = "/api/{spaceId}/projects/{projectId}/git/branches"
)
)

0 comments on commit 2d95b7e

Please sign in to comment.