OPC # 0006: Build monitor grid, CI SolutionBuild rows, by-sha endpoint, dashboard SHA badge
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using ControlPlane.Api.Services;
|
||||
using ControlPlane.Core.Models;
|
||||
using ControlPlane.Core.Services;
|
||||
using System.Text.Json;
|
||||
|
||||
@@ -16,6 +17,7 @@ public static class ProjectBuildEndpoints
|
||||
var group = app.MapGroup("/api/builds").WithTags("Builds");
|
||||
group.MapGet("/projects", GetProjects);
|
||||
group.MapGet("/history", GetHistory);
|
||||
group.MapGet("/by-sha", GetBySha);
|
||||
group.MapPost("/{projectName}", TriggerProjectBuild);
|
||||
return app;
|
||||
}
|
||||
@@ -27,6 +29,31 @@ public static class ProjectBuildEndpoints
|
||||
private static async Task<IResult> GetHistory(BuildHistoryService history) =>
|
||||
Results.Ok(await history.GetBuildsAsync());
|
||||
|
||||
/// <summary>
|
||||
/// Returns the latest SolutionBuild record for the given commit SHA, or null if none exists.
|
||||
/// Used by the OPC CommitsTab to render per-commit CI status dots.
|
||||
/// </summary>
|
||||
private static async Task<IResult> GetBySha(string sha, BuildHistoryService history)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(sha))
|
||||
return Results.BadRequest("sha is required");
|
||||
|
||||
var builds = await history.GetBuildsByShaAsync(sha);
|
||||
var latest = builds
|
||||
.Where(b => b.Kind == BuildKind.SolutionBuild)
|
||||
.MaxBy(b => b.StartedAt);
|
||||
|
||||
return Results.Ok(latest is null ? null : new
|
||||
{
|
||||
latest.Id,
|
||||
latest.Status,
|
||||
latest.StartedAt,
|
||||
latest.FinishedAt,
|
||||
latest.DurationMs,
|
||||
latest.CommitSha,
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triggers a build for a named project and streams SSE output.
|
||||
/// projectName must match one of the names returned by GET /api/builds/projects.
|
||||
|
||||
Reference in New Issue
Block a user