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

adding IsLatestReleaseUsingBuildDefinitionArtifact #25

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 49 additions & 4 deletions src/Tool/src/Boost.AzureDevOps/AzureDevOpsPipelinesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ private Pipeline ToPipeline(

private Pipeline ToPipeline(
AzureDevOpsConnectedService service,
ReleaseDefinitionShallowReference definition)
ReleaseDefinitionShallowReference definition,
bool isReleaseUsingBuildArtifacts)
{
return new Pipeline
{
Expand All @@ -169,7 +170,8 @@ private Pipeline ToPipeline(
WebUrl = definition.Links.GetLink("web"),
Properties = new List<PipelineProperty>
{
new("ProjectId", definition.ProjectReference.Id.ToString())
new("ProjectId", definition.ProjectReference.Id.ToString()),
new("IsReleaseUsingBuildArtifacts", isReleaseUsingBuildArtifacts.ToString())
}
};
}
Expand Down Expand Up @@ -216,16 +218,59 @@ public async Task<IEnumerable<Pipeline>> GetReleasesAsync(

if ( definition is { })
{
bool isReleaseUsingBuildArtifacts =
await IsLatestReleaseUsingBuildDefinitionArtifact(serviceId, teamProjectId, buildDefinitionId, definition.Id);
definition.ProjectReference = release.ProjectReference;
return ToPipeline(ClientFactory.Connections[serviceId].Service, definition);

return ToPipeline(
ClientFactory.Connections[serviceId].Service,
definition,
isReleaseUsingBuildArtifacts);
}
}

return null;
}

public async Task<bool> IsLatestReleaseUsingBuildDefinitionArtifact(
Guid serviceId,
Guid teamProjectId,
int buildDefinitionId,
int ReleaseDefinitionId)
{
ReleaseHttpClient client = ClientFactory.CreateClient<ReleaseHttpClient>(serviceId);

ReleaseDefinition ReleaseDefinition =
await client.GetReleaseDefinitionAsync(
project: teamProjectId,
definitionId: ReleaseDefinitionId
);

if (ReleaseDefinition != null)
{
List<Release> latestReleases =
await client.GetReleasesAsync(
project: teamProjectId,
definitionId: ReleaseDefinition.Id,
top: 1);
Release? latestRelease = latestReleases.FirstOrDefault();

if (latestRelease != null)
{
// Check if the latest release is using artifacts from the target build definition
Artifact? buildDefinitionArtifact =
latestRelease.Artifacts.FirstOrDefault(
a => a.DefinitionReference.ContainsKey("definition") &&
a.DefinitionReference["definition"].Id == buildDefinitionId.ToString());

return buildDefinitionArtifact != null;
}
}

return false;
}

public async Task<IEnumerable<Build>> GetRunsAsync(
public async Task<IEnumerable<Build>> GetRunsAsync(
Guid serviceId,
Guid projectId,
int id,
Expand Down