feat(worker): expose MergeTask and GetMergeTargets on WorkerHub

This commit is contained in:
Mika Kuns
2026-04-22 09:44:22 +02:00
parent c13ae437f7
commit c53b5878cf

View File

@@ -22,6 +22,8 @@ public record AppSettingsDto(
public record WorktreeCleanupDto(int Removed); public record WorktreeCleanupDto(int Removed);
public record WorktreeResetDto(int Removed, int TasksAffected, bool Blocked, int RunningTasks); public record WorktreeResetDto(int Removed, int TasksAffected, bool Blocked, int RunningTasks);
public record MergeResultDto(string Status, IReadOnlyList<string> ConflictFiles, string? ErrorMessage);
public record MergeTargetsDto(string DefaultBranch, IReadOnlyList<string> LocalBranches);
public sealed class WorkerHub : Microsoft.AspNetCore.SignalR.Hub public sealed class WorkerHub : Microsoft.AspNetCore.SignalR.Hub
{ {
@@ -34,6 +36,7 @@ public sealed class WorkerHub : Microsoft.AspNetCore.SignalR.Hub
private readonly IDbContextFactory<ClaudeDoDbContext> _dbFactory; private readonly IDbContextFactory<ClaudeDoDbContext> _dbFactory;
private readonly WorktreeMaintenanceService _wtMaintenance; private readonly WorktreeMaintenanceService _wtMaintenance;
private readonly TaskResetService _resetService; private readonly TaskResetService _resetService;
private readonly TaskMergeService _mergeService;
public WorkerHub( public WorkerHub(
QueueService queue, QueueService queue,
@@ -41,7 +44,8 @@ public sealed class WorkerHub : Microsoft.AspNetCore.SignalR.Hub
HubBroadcaster broadcaster, HubBroadcaster broadcaster,
IDbContextFactory<ClaudeDoDbContext> dbFactory, IDbContextFactory<ClaudeDoDbContext> dbFactory,
WorktreeMaintenanceService wtMaintenance, WorktreeMaintenanceService wtMaintenance,
TaskResetService resetService) TaskResetService resetService,
TaskMergeService mergeService)
{ {
_queue = queue; _queue = queue;
_agentService = agentService; _agentService = agentService;
@@ -49,6 +53,7 @@ public sealed class WorkerHub : Microsoft.AspNetCore.SignalR.Hub
_dbFactory = dbFactory; _dbFactory = dbFactory;
_wtMaintenance = wtMaintenance; _wtMaintenance = wtMaintenance;
_resetService = resetService; _resetService = resetService;
_mergeService = mergeService;
} }
public string Ping() => $"pong v{Version}"; public string Ping() => $"pong v{Version}";
@@ -160,4 +165,44 @@ public sealed class WorkerHub : Microsoft.AspNetCore.SignalR.Hub
var result = await _wtMaintenance.ResetAllAsync(); var result = await _wtMaintenance.ResetAllAsync();
return new WorktreeResetDto(result.Removed, result.TasksAffected, result.Blocked, result.RunningTasks); return new WorktreeResetDto(result.Removed, result.TasksAffected, result.Blocked, result.RunningTasks);
} }
public async Task<MergeResultDto> MergeTask(
string taskId, string targetBranch, bool removeWorktree, string commitMessage)
{
try
{
var r = await _mergeService.MergeAsync(
taskId,
targetBranch ?? "",
removeWorktree,
string.IsNullOrWhiteSpace(commitMessage) ? "Merge task" : commitMessage,
CancellationToken.None);
return new MergeResultDto(r.Status, r.ConflictFiles, r.ErrorMessage);
}
catch (KeyNotFoundException)
{
throw new HubException("task not found");
}
catch (InvalidOperationException ex)
{
throw new HubException(ex.Message);
}
}
public async Task<MergeTargetsDto> GetMergeTargets(string taskId)
{
try
{
var t = await _mergeService.GetTargetsAsync(taskId, CancellationToken.None);
return new MergeTargetsDto(t.DefaultBranch, t.LocalBranches);
}
catch (KeyNotFoundException)
{
throw new HubException("task not found");
}
catch (InvalidOperationException ex)
{
throw new HubException(ex.Message);
}
}
} }