@@ -5,12 +5,11 @@ import (
55 "strings"
66
77 "github.com/pkg/errors"
8- channels "github.com/replicatedhq/replicated/gen/go/v1"
98 "github.com/replicatedhq/replicated/pkg/platformclient"
109 "github.com/replicatedhq/replicated/pkg/types"
1110)
1211
13- func (c * Client ) ListChannels (appID string , appType string , appSlug string , channelName string ) ([]types.Channel , error ) {
12+ func (c * Client ) ListChannels (appID string , appType string , channelName string ) ([]types.Channel , error ) {
1413
1514 if appType == "platform" {
1615 platformChannels , err := c .PlatformClient .ListChannels (appID )
@@ -35,22 +34,32 @@ func (c *Client) ListChannels(appID string, appType string, appSlug string, chan
3534 } else if appType == "ship" {
3635 return c .ShipClient .ListChannels (appID )
3736 } else if appType == "kots" {
38- return c .KotsClient .ListChannels (appID , appSlug , channelName )
37+ return c .KotsClient .ListChannels (appID , channelName )
3938 }
4039
4140 return nil , errors .New ("unknown app type" )
4241}
4342
44- func (c * Client ) GetChannel (appID string , appType string , channelID string ) (* channels. AppChannel , []channels. ChannelRelease , error ) {
43+ func (c * Client ) GetChannel (appID string , appType string , channelID string ) (* types. Channel , error ) {
4544 if appType == "platform" {
46- return c .PlatformClient .GetChannel (appID , channelID )
45+ platformChannel , _ , err := c .PlatformClient .GetChannel (appID , channelID )
46+ if err != nil {
47+ return nil , err
48+ }
49+ channel := types.Channel {
50+ ID : platformChannel .Id ,
51+ Name : platformChannel .Name ,
52+ Description : platformChannel .Description ,
53+ ReleaseSequence : platformChannel .ReleaseSequence ,
54+ ReleaseLabel : platformChannel .ReleaseLabel ,
55+ }
56+ return & channel , nil
4757 } else if appType == "ship" {
4858 return c .ShipClient .GetChannel (appID , channelID )
4959 } else if appType == "kots" {
5060 return c .KotsClient .GetChannel (appID , channelID )
5161 }
52- return nil , nil , errors .New ("unknown app type" )
53-
62+ return nil , errors .New ("unknown app type" )
5463}
5564
5665func (c * Client ) ArchiveChannel (appID string , appType string , channelID string ) error {
@@ -65,13 +74,13 @@ func (c *Client) ArchiveChannel(appID string, appType string, channelID string)
6574
6675}
6776
68- func (c * Client ) CreateChannel (appID string , appType string , appSlug string , name string , description string ) ([]types.Channel , error ) {
77+ func (c * Client ) CreateChannel (appID string , appType string , name string , description string ) ([]types.Channel , error ) {
6978
7079 if appType == "platform" {
7180 if err := c .PlatformClient .CreateChannel (appID , name , description ); err != nil {
7281 return nil , err
7382 }
74- return c .ListChannels (appID , appType , appSlug , name )
83+ return c .ListChannels (appID , appType , name )
7584 } else if appType == "ship" {
7685 if _ , err := c .ShipClient .CreateChannel (appID , name , description ); err != nil {
7786 return nil , err
@@ -81,36 +90,30 @@ func (c *Client) CreateChannel(appID string, appType string, appSlug string, nam
8190 if _ , err := c .KotsClient .CreateChannel (appID , name , description ); err != nil {
8291 return nil , err
8392 }
84- return c .KotsClient .ListChannels (appID , appSlug , name )
93+ return c .KotsClient .ListChannels (appID , name )
8594 }
8695
8796 return nil , errors .New ("unknown app type" )
8897}
8998
90- func (c * Client ) GetOrCreateChannelByName (appID string , appType string , appSlug string , nameOrID string , description string , createIfAbsent bool ) (* types.Channel , error ) {
99+ func (c * Client ) GetOrCreateChannelByName (appID string , appType string , nameOrID string , description string , createIfAbsent bool ) (* types.Channel , error ) {
91100 gqlNotFoundErr := fmt .Sprintf ("channel %s not found" , nameOrID )
92- channel , _ , err := c .GetChannel (appID , appType , nameOrID )
101+ channel , err := c .GetChannel (appID , appType , nameOrID )
93102 if err == nil {
94- return & types.Channel {
95- ID : channel .Id ,
96- Name : channel .Name ,
97- Description : channel .Description ,
98- ReleaseSequence : channel .ReleaseSequence ,
99- ReleaseLabel : channel .ReleaseLabel ,
100- }, nil
103+ return channel , nil
101104 } else if ! strings .Contains (err .Error (), gqlNotFoundErr ) && ! errors .Is (err , platformclient .ErrNotFound ) {
102105 return nil , errors .Wrap (err , "get channel" )
103106 }
104107
105- allChannels , err := c .ListChannels (appID , appType , appSlug , nameOrID )
108+ allChannels , err := c .ListChannels (appID , appType , nameOrID )
106109 if err != nil {
107110 return nil , err
108111 }
109112
110113 foundChannel , numMatching , err := c .findChannel (allChannels , nameOrID )
111114
112115 if numMatching == 0 && createIfAbsent {
113- updatedListOfChannels , err := c .CreateChannel (appID , appType , appSlug , nameOrID , description )
116+ updatedListOfChannels , err := c .CreateChannel (appID , appType , nameOrID , description )
114117 if err != nil {
115118 return nil , errors .Wrapf (err , "create channel %q " , nameOrID )
116119 }
@@ -123,8 +126,8 @@ func (c *Client) GetOrCreateChannelByName(appID string, appType string, appSlug
123126 return foundChannel , errors .Wrapf (err , "find channel %q" , nameOrID )
124127}
125128
126- func (c * Client ) GetChannelByName (appID string , appType string , appSlug string , name string ) (* types.Channel , error ) {
127- return c .GetOrCreateChannelByName (appID , appType , appSlug , name , "" , false )
129+ func (c * Client ) GetChannelByName (appID string , appType string , name string ) (* types.Channel , error ) {
130+ return c .GetOrCreateChannelByName (appID , appType , name , "" , false )
128131}
129132
130133func (c * Client ) findChannel (channels []types.Channel , name string ) (* types.Channel , int , error ) {
@@ -150,7 +153,7 @@ func (c *Client) UpdateSemanticVersioningForChannel(appType string, appID string
150153 } else if appType == "ship" {
151154 return errors .New ("This feature is not currently supported for Ship applications." )
152155 } else if appType == "kots" {
153- channel , _ , err := c .KotsClient .GetChannel (appID , chanID )
156+ channel , err := c .KotsClient .GetChannel (appID , chanID )
154157 if err != nil {
155158 return err
156159 }
0 commit comments