Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChannelsQuery needs ProjectId filter or Project object needs channel list #72

Open
twerthi opened this issue Jul 20, 2021 · 0 comments
Open

Comments

@twerthi
Copy link

twerthi commented Jul 20, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant