Skip to content

Commit f9bb0ce

Browse files
fix: Change create release to upsert
1 parent d4ba3df commit f9bb0ce

File tree

4 files changed

+100
-61
lines changed

4 files changed

+100
-61
lines changed

cmd/ctrlc/root/api/create/create.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package create
33
import (
44
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/create/environment"
55
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/create/relationship"
6-
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/create/release"
76
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/create/releasechannel"
87
"github.com/spf13/cobra"
98
)
@@ -18,7 +17,6 @@ func NewCreateCmd() *cobra.Command {
1817
},
1918
}
2019

21-
cmd.AddCommand(release.NewCreateReleaseCmd())
2220
cmd.AddCommand(releasechannel.NewCreateReleaseChannelCmd())
2321
cmd.AddCommand(environment.NewCreateEnvironmentCmd())
2422
cmd.AddCommand(relationship.NewRelationshipCmd())

cmd/ctrlc/root/api/create/release/release.go renamed to cmd/ctrlc/root/api/upsert/release/release.go

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"net/http"
7+
"strings"
78
"time"
89

910
"github.com/MakeNowJust/heredoc/v2"
@@ -13,28 +14,47 @@ import (
1314
"github.com/spf13/viper"
1415
)
1516

16-
func NewCreateReleaseCmd() *cobra.Command {
17+
func safeConvertToReleaseStatus(status string) (*api.UpsertReleaseJSONBodyStatus, error) {
18+
statusLower := strings.ToLower(status)
19+
if statusLower == "ready" || statusLower == "" {
20+
s := api.Ready
21+
return &s, nil
22+
}
23+
if statusLower == "building" {
24+
s := api.Building
25+
return &s, nil
26+
}
27+
if statusLower == "failed" {
28+
s := api.Failed
29+
return &s, nil
30+
}
31+
return nil, fmt.Errorf("invalid release status: %s", status)
32+
}
33+
34+
func NewUpsertReleaseCmd() *cobra.Command {
1735
var versionFlag string
1836
var deploymentID []string
1937
var metadata map[string]string
2038
var configArray map[string]string
2139
var links map[string]string
2240
var createdAt string
2341
var name string
42+
var status string
43+
var message string
2444

2545
cmd := &cobra.Command{
2646
Use: "release [flags]",
27-
Short: "Create a new release",
28-
Long: `Create a new release with the specified version and configuration.`,
47+
Short: "Upsert a release",
48+
Long: `Upsert a release with the specified version and configuration.`,
2949
Example: heredoc.Doc(`
30-
# Create a new release
31-
$ ctrlc create release --version v1.0.0 --deployment 1234567890
50+
# Upsert a release
51+
$ ctrlc upsert release --version v1.0.0 --deployment 1234567890
3252
33-
# Create a new release using Go template syntax
34-
$ ctrlc create release --version v1.0.0 --deployment 1234567890 --template='{{.status.phase}}'
53+
# Upsert a release using Go template syntax
54+
$ ctrlc upsert release --version v1.0.0 --deployment 1234567890 --template='{{.status.phase}}'
3555
36-
# Create a new release for multiple deployments
37-
$ ctrlc create release --version v1.0.0 --deployment 1234567890 --deployment 0987654321
56+
# Upsert a new release for multiple deployments
57+
$ ctrlc upsert release --version v1.0.0 --deployment 1234567890 --deployment 0987654321
3858
`),
3959
RunE: func(cmd *cobra.Command, args []string) error {
4060
apiURL := viper.GetString("url")
@@ -61,16 +81,23 @@ func NewCreateReleaseCmd() *cobra.Command {
6181
metadata["ctrlplane/links"] = string(linksJSON)
6282
}
6383

84+
stat, err := safeConvertToReleaseStatus(status)
85+
if err != nil {
86+
return fmt.Errorf("failed to convert release status: %w", err)
87+
}
88+
6489
config := cliutil.ConvertConfigArrayToNestedMap(configArray)
6590
var response *http.Response
6691
for _, id := range deploymentID {
67-
resp, err := client.CreateRelease(cmd.Context(), api.CreateReleaseJSONRequestBody{
92+
resp, err := client.UpsertRelease(cmd.Context(), api.UpsertReleaseJSONRequestBody{
6893
Version: versionFlag,
6994
DeploymentId: id,
7095
Metadata: &metadata,
7196
CreatedAt: parsedTime,
7297
Config: &config,
7398
Name: &name,
99+
Status: stat,
100+
Message: &message,
74101
})
75102
if err != nil {
76103
return fmt.Errorf("failed to create release: %w", err)
@@ -90,6 +117,8 @@ func NewCreateReleaseCmd() *cobra.Command {
90117
cmd.Flags().StringToStringVarP(&links, "link", "l", make(map[string]string), "Links key-value pairs (can be specified multiple times)")
91118
cmd.Flags().StringVarP(&createdAt, "created-at", "t", "", "Created at timestamp (e.g. --created-at 2024-01-01T00:00:00Z) for the release channel")
92119
cmd.Flags().StringVarP(&name, "name", "n", "", "Name of the release channel")
120+
cmd.Flags().StringVarP(&status, "status", "s", string(api.Ready), "Status of the release channel (one of: ready, building, failed)")
121+
cmd.Flags().StringVar(&message, "message", "", "Message of the release channel")
93122

94123
cmd.MarkFlagRequired("version")
95124
cmd.MarkFlagRequired("deployment")

cmd/ctrlc/root/api/upsert/upsert.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package upsert
22

33
import (
4+
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/upsert/release"
45
"github.com/ctrlplanedev/cli/cmd/ctrlc/root/api/upsert/resource"
56
"github.com/spf13/cobra"
67
)
@@ -16,6 +17,7 @@ func NewUpsertCmd() *cobra.Command {
1617
}
1718

1819
cmd.AddCommand(resource.NewUpsertResourceCmd())
20+
cmd.AddCommand(release.NewUpsertReleaseCmd())
1921

2022
return cmd
2123
}

internal/api/client.gen.go

Lines changed: 59 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)