go-octopusdeploy icon indicating copy to clipboard operation
go-octopusdeploy copied to clipboard

ChannelsQuery needs ProjectId filter or Project object needs channel list

Open twerthi opened this issue 4 years ago • 0 comments

Is your feature request related to a problem? Please describe. The project object doesn't contain a list of channels associated with the project. The ChannelQuery struct only allows for ID or Partial Name, without having the list associated to the project, you're forced to use Partial Name. This can lead to a lot of results and you need to loop to retrieve all of them, then iterate through them until you find the one you're looking for.

Describe the solution you'd like Two solutions could resolve this issue:

  • Include associated channel references on the project object
  • Include ProjectId in the ChannelQuery struct so you can limit results to channels pertinent to the project in question

Describe alternatives you've considered This works, but has to retrieve all channels with the matching partial name

func GetChannel(client *octopusdeploy.Client, project *octopusdeploy.Project, ChannelName string) *octopusdeploy.Channel {
	channelQuery := octopusdeploy.ChannelsQuery{
		PartialName: ChannelName,
		Skip:        0,
	}

	results := []*octopusdeploy.Channel{}

	for true {
		// Call for results
		channels, err := client.Channels.Get(channelQuery)

		if err != nil {
			log.Println(err)
		}

		// Check returned number of items
		if len(channels.Items) == 0 {
			break
		}

		// append items to results
		results = append(results, channels.Items...)

		// Update query
		channelQuery.Skip += len(channels.Items)
	}

	for i := 0; i < len(results); i++ {
		if results[i].ProjectID == project.ID && results[i].Name == ChannelName {
			return results[i]
		}
	}

	return nil
}

Additional context Add any other context or screenshots about the feature request here.

twerthi avatar Jul 20 '21 22:07 twerthi