We heavily use the c# Octopus.Client package to re-release deployments to servers, normally we calculate the latest release using:
var dashboard = Repository.Dashboards.GetDynamicDashboard(new string[] { project.Id }, new string[] { deployEnvo.Id });
var latestDeployment = deploymentInfo.Where(r => r.IsCurrent ).FirstOrDefault();
But we need to now expand this to the latest release per channel. From the forum a year or two ago it was recommended to use: Repository.Client.Get($"/api/progression/{project.Id}") but it only marks the one release for an environment across all channels as IsCurrent. What’s the best way to calculate the latest release for a channel or is there a better method to work this out?
Thanks for getting in touch! This is a great question, and after some research I think a good sample script to get you at least part of the way there is the following. This uses the progression API as well like you’ve mentioned in a thread you came across (is this the same one?) to retrieve releases based on channel specified that can be promoted.
var project = repository.Projects.FindByName("MyProject");
var progressions = repository.Projects.GetProgression(project)
.Releases
.Where(r => r.Channel.Id == "Channels-1");
var canPromoteToEnv2 = progressions.Where(r => r.NextDeployments.Contains("Environments-2"));
You can reference the full context of the thread where I pulled this sample script from here.
Had a play with the code but I am not seeing isCurrent being populated for any other channels. The isCurrent is only populating for a different channel.
var progressions = Repository.Projects.GetProgression(project).Releases.Where(r => r.Channel.Id == channel.Id && r.NextDeployments.Contains(deployEnvo.Id));
var isCurrent = progressions.SelectMany(v => v.Deployments).SelectMany(a => a.Value).Where(v => v.IsCurrent);