summaryrefslogtreecommitdiff
path: root/src/marlin.web/Controllers/JobsController.cs
diff options
context:
space:
mode:
authorMelodi <62381002+Melodi17@users.noreply.github.com>2026-09-13 13:22:20 +1000
committerMelodi <62381002+Melodi17@users.noreply.github.com>2026-09-13 13:22:20 +1000
commitdf0737e55afeb5c01eb39909605970d1d3a73ffc (patch)
tree09823eaa310c60eefd2420dc305acae45c81900f /src/marlin.web/Controllers/JobsController.cs
parentee69ce25b2fba871920260028bb10c2d6b62b26f (diff)
refactor: cleanup; feat: connection to agent
Diffstat (limited to 'src/marlin.web/Controllers/JobsController.cs')
-rw-r--r--src/marlin.web/Controllers/JobsController.cs35
1 files changed, 24 insertions, 11 deletions
diff --git a/src/marlin.web/Controllers/JobsController.cs b/src/marlin.web/Controllers/JobsController.cs
index c86cb2d..552b56c 100644
--- a/src/marlin.web/Controllers/JobsController.cs
+++ b/src/marlin.web/Controllers/JobsController.cs
@@ -4,25 +4,29 @@ using core.models;
using Data;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
+using Models;
using Util;
[Route("jobs")]
public class JobsController(ApplicationDbContext dbContext) : Controller
{
-
// list jobs (pending, active, cancelled, success, failed), filter to vcs, filter to recipe
- public record JobListFilter(JobStatus? Status = null, Guid? Vcs = null, string? Ref = null, string? Recipe = null);
-
+ public record JobListFilter(JobStatus? Status = null, Guid? Vcs = null, Guid? Branch = null, string? Recipe = null, Guid? Agent = null);
+
[HttpGet("list")]
public async Task<IActionResult> List([FromQuery] JobListFilter filter, CancellationToken ct)
{
- var results = await dbContext.Jobs
+ var results = await dbContext
+ .Jobs
.WhereIf(filter.Status != null, x => x.Status == filter.Status)
.WhereIf(filter.Vcs != null, x => x.SourceId == filter.Vcs)
- .WhereIf(filter.Ref != null, x => x.Ref == filter.Ref)
+ .WhereIf(filter.Branch != null, x => x.BranchId == filter.Branch)
.WhereIf(filter.Recipe != null, x => x.Recipe == filter.Recipe)
+ .WhereIf(filter.Agent != null, x => x.AgentId == filter.Agent)
.OrderByDescending(x => x.CreatedAt)
-
+
+ .Include(x => x.Commit)
+ .Include(x => x.Branch)
.Include(x => x.Source)
.Include(x => x.Agent)
.ToListAsync(ct);
@@ -40,25 +44,34 @@ public class JobsController(ApplicationDbContext dbContext) : Controller
[HttpGet("spawn")]
public async Task<IActionResult> Spawn(CancellationToken ct)
{
- var sources = await dbContext.Sources
+ var sources = await dbContext
+ .Sources
.Include(x => x.Branches)
.ThenInclude(x => x.Commit)
+ .ThenInclude(x => x.WorkflowSnapshot)
.ToListAsync(ct);
var details = new JobSpawnDetails(sources);
return this.View(details);
}
- public record JobSpawnRequest(Guid Vcs, string Ref, string Commit, string Recipe);
+ public record JobSpawnRequest(Guid Vcs, Guid Branch, string Recipe);
[HttpPost("spawn")]
public async Task<IActionResult> SpawnPost(JobSpawnRequest request, CancellationToken ct)
{
+ var branch = await dbContext
+ .SourceBranches
+ .FirstOrDefaultAsync(x => x.Id == request.Branch, ct);
+
+ if (branch == null)
+ return this.NotFound();
+
Job job = new()
{
- SourceId = request.Vcs,
- Ref = request.Ref,
- Commit = request.Commit,
+ SourceId = branch.SourceId,
+ BranchId = branch.Id,
+ CommitId = branch.CommitId,
Recipe = request.Recipe,
CreatedAt = DateTime.UtcNow,