Skip to content

Commit 2260a14

Browse files
authored
Merge pull request #190 from replicatedhq/kiraboyle/sc-42504/add-or-remove-semantic-versioning-attribute
Kiraboyle/sc 42504/add or remove semantic versioning attribute
2 parents 104fc18 + 415f865 commit 2260a14

File tree

6 files changed

+119
-0
lines changed

6 files changed

+119
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package cmd
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
func (r *runners) InitChannelDisableSemanticVersioning(parent *cobra.Command) {
10+
cmd := &cobra.Command{
11+
Use: "disable-semantic-versioning CHANNEL_ID",
12+
Short: "Disable semantic versioning for CHANNEL_ID",
13+
Long: `Disable semantic versioning for the CHANNEL_ID.
14+
15+
Example:
16+
replicated channel disable-semantic-versioning CHANNEL_ID`,
17+
}
18+
cmd.Hidden = true // Not supported in KOTS
19+
parent.AddCommand(cmd)
20+
cmd.RunE = r.channelDisableSemanticVersioning
21+
}
22+
23+
func (r *runners) channelDisableSemanticVersioning(cmd *cobra.Command, args []string) error {
24+
if len(args) != 1 {
25+
return errors.New("channel ID is required")
26+
}
27+
chanID := args[0]
28+
if err := r.api.UpdateSemanticVersioningForChannel(r.appType, r.appID, chanID, false); err != nil {
29+
return err
30+
}
31+
32+
fmt.Fprintf(r.w, "Semver successfully disabled for channel %s\n", chanID)
33+
r.w.Flush()
34+
35+
return nil
36+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package cmd
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
func (r *runners) InitChannelEnableSemanticVersioning(parent *cobra.Command) {
10+
cmd := &cobra.Command{
11+
Use: "enable-semantic-versioning CHANNEL_ID",
12+
Short: "Enable semantic versioning for CHANNEL_ID",
13+
Long: `Enable semantic versioning for the CHANNEL_ID.
14+
15+
Example:
16+
replicated channel enable-semantic-versioning CHANNEL_ID`,
17+
}
18+
cmd.Hidden = true // Not supported in KOTS
19+
parent.AddCommand(cmd)
20+
cmd.RunE = r.channelEnableSemanticVersioning
21+
}
22+
23+
func (r *runners) channelEnableSemanticVersioning(cmd *cobra.Command, args []string) error {
24+
if len(args) != 1 {
25+
return errors.New("channel ID is required")
26+
}
27+
chanID := args[0]
28+
if err := r.api.UpdateSemanticVersioningForChannel(r.appType, r.appID, chanID, true); err != nil {
29+
return err
30+
}
31+
32+
fmt.Fprintf(r.w, "Semver successfully enabled for channel %s\n", chanID)
33+
r.w.Flush()
34+
35+
return nil
36+
}

cli/cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ func Execute(rootCmd *cobra.Command, stdin io.Reader, stdout io.Writer, stderr i
134134
runCmds.InitChannelCounts(channelCmd)
135135
runCmds.InitChannelList(channelCmd)
136136
runCmds.InitChannelRemove(channelCmd)
137+
runCmds.InitChannelEnableSemanticVersioning(channelCmd)
138+
runCmds.InitChannelDisableSemanticVersioning(channelCmd)
137139

138140
runCmds.rootCmd.AddCommand(releaseCmd)
139141
err := runCmds.InitReleaseCreate(releaseCmd)

client/channel.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ func (c *Client) GetOrCreateChannelByName(appID string, appType string, appSlug
127127
}
128128

129129
func (c *Client) GetChannelByName(appID string, appType string, appSlug string, name string) (*types.Channel, error) {
130+
130131
return c.GetOrCreateChannelByName(appID, appType, appSlug, name, "", false)
131132
}
132133

@@ -147,3 +148,21 @@ func (c *Client) findChannel(channels []types.Channel, name string) (*types.Chan
147148
}
148149
return matchingChannels[0], 1, nil
149150
}
151+
152+
func (c *Client) UpdateSemanticVersioningForChannel(appType string, appID string, chanID string, enableSemver bool) error {
153+
154+
if appType == "platform" {
155+
return errors.New("This feature is not currently supported for Platform applications.")
156+
} else if appType == "ship" {
157+
return errors.New("This feature is not currently supported for Ship applications.")
158+
} else if appType == "kots" {
159+
channel, _, err := c.KotsClient.GetChannel(appID, chanID)
160+
if err != nil {
161+
return err
162+
}
163+
err = c.KotsClient.UpdateSemanticVersioning(appID, channel, enableSemver)
164+
return err
165+
}
166+
167+
return errors.New("unknown app type")
168+
}

pkg/kotsclient/channel.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,23 @@ func (c *VendorV3Client) ArchiveChannel(appID, channelID string) error {
160160

161161
return nil
162162
}
163+
164+
func (c *VendorV3Client) UpdateSemanticVersioning(appID string, channel *channels.AppChannel, enableSemver bool) error {
165+
request := types.UpdateChannelRequest{
166+
Name: channel.Name,
167+
SemverRequired: enableSemver,
168+
}
169+
170+
type updateChannelResponse struct {
171+
Channel types.KotsChannel `json:"channel"`
172+
}
173+
var response updateChannelResponse
174+
175+
url := fmt.Sprintf("/v3/app/%s/channel/%s", appID, channel.Id)
176+
err := c.DoJSON("PUT", url, http.StatusOK, request, &response)
177+
if err != nil {
178+
return errors.Wrap(err, "edit semantic versioning for channel")
179+
}
180+
181+
return nil
182+
}

pkg/types/channel.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ type CreateChannelRequest struct {
5959
Name string `json:"name"`
6060
}
6161

62+
type UpdateChannelRequest struct {
63+
// Description of the channel that is to be created.
64+
Name string `json:"name"`
65+
SemverRequired bool `json:"semverRequired,omitempty"`
66+
}
67+
6268
type Channel struct {
6369
ID string
6470
Name string

0 commit comments

Comments
 (0)