Skip to content

Commit

Permalink
Use PATCH method to update channels (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
divolgin authored Sep 17, 2024
1 parent da9bb16 commit c93479b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
12 changes: 5 additions & 7 deletions pkg/kotsclient/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,16 @@ func (c *VendorV3Client) ArchiveChannel(appID, channelID string) error {
}

func (c *VendorV3Client) UpdateSemanticVersioning(appID string, channel *types.Channel, enableSemver bool) error {
request := types.UpdateChannelRequest{
Name: channel.Name,
SemverRequired: enableSemver,
request := types.PatchChannelRequest{
SemverRequired: &enableSemver,
}

type updateChannelResponse struct {
response := struct {
Channel types.KotsChannel `json:"channel"`
}
var response updateChannelResponse
}{}

url := fmt.Sprintf("/v3/app/%s/channel/%s", appID, channel.ID)
err := c.DoJSON("PUT", url, http.StatusOK, request, &response)
err := c.DoJSON("PATCH", url, http.StatusOK, request, &response)
if err != nil {
return errors.Wrap(err, "edit semantic versioning for channel")
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/kotsclient/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,13 @@ func Test_AddRemoveSemver(t *testing.T) {
Given("Add Semver to a KOTS app channel").
UponReceiving("A request to add semver to kots app channel").
WithRequest(dsl.Request{
Method: "PUT",
Method: "PATCH",
Path: dsl.String("/v3/app/replicated-cli-semver-channel-app/channel/replicated-cli-semver-channel-unstable"),
Headers: dsl.MapMatcher{
"Authorization": dsl.String("replicated-cli-semver-channel-token"),
"Content-Type": dsl.String("application/json"),
},
Body: map[string]interface{}{
"name": "Unstable",
"semverRequired": true,
},
}).
Expand Down
6 changes: 2 additions & 4 deletions pkg/types/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,8 @@ type CreateChannelRequest struct {
Name string `json:"name"`
}

type UpdateChannelRequest struct {
// Description of the channel that is to be created.
Name string `json:"name"`
SemverRequired bool `json:"semverRequired,omitempty"`
type PatchChannelRequest struct {
SemverRequired *bool `json:"semverRequired,omitempty"`
}

type Channel struct {
Expand Down

0 comments on commit c93479b

Please sign in to comment.