public async Task Handle(HealthCheckRequest <VSTSRelease_v1> request, CancellationToken cancellationToken) { var widget = request.DataContext ?? throw new InvalidOperationException(); var client = new VSTS(); widget.MapTo(client); if (widget.ReleaseId == null) { var definition = await client .GetReleaseDefinitionAsync(widget.ReleaseDefinitionName) .ConfigureAwait(false); widget.ReleaseId = definition.Id; } var lastRelease = await client .GetLastReleaseAsync(widget.ReleaseId.Value) .ConfigureAwait(false); var releaseDetails = await client .GetReleaseDetailsAsync(lastRelease.Id) .ConfigureAwait(false); RemoveEnvironments(widget, releaseDetails.Environments); AddEnvironments(widget, releaseDetails); }
public async Task Handle(HealthCheckRequest <VSTSBuild_v1> request, CancellationToken cancellationToken) { var vsts = new VSTS(); request.DataContext.MapTo(vsts); if (request.DataContext.DefinitionId == null) { var definition = await vsts.GetBuildDefinitionAsync(request.DataContext.DefinitionName).ConfigureAwait(false); request.DataContext.DefinitionId = definition.Id; } var builds = await vsts.Request <Collection <VSTSBuild> >($"build/builds?definitions={request.DataContext.DefinitionId}&$top=1&api-version=2.0").ConfigureAwait(false); var build = builds?.Value?.FirstOrDefault(); if (build != null) { request.DataContext.State = build.State; } else { request.DataContext.State = State.Unknown; _logger.Error($"VSTS build definition \"{request.DataContext.DefinitionName}\" no builds were found."); } }