diff --git a/pkg/runbooks/runbook_service.go b/pkg/runbooks/runbook_service.go index f3306b96..e60a32f7 100644 --- a/pkg/runbooks/runbook_service.go +++ b/pkg/runbooks/runbook_service.go @@ -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) { @@ -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 == "" { diff --git a/uritemplates/links.go b/uritemplates/links.go index 871ba9c8..6d728b00 100644 --- a/uritemplates/links.go +++ b/uritemplates/links.go @@ -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 @@ -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" -) +) \ No newline at end of file