feat(worker): expose PreviewMerge hub method and merge-on-approve

This commit is contained in:
mika kuns
2026-06-04 23:29:05 +02:00
parent f1cf29b58d
commit 43f8f7f7d8

View File

@@ -54,6 +54,7 @@ public record WorktreeOverviewDto(
public record ForceRemoveResultDto(bool Removed, string? Reason); public record ForceRemoveResultDto(bool Removed, string? Reason);
public record MergeResultDto(string Status, IReadOnlyList<string> ConflictFiles, string? ErrorMessage); public record MergeResultDto(string Status, IReadOnlyList<string> ConflictFiles, string? ErrorMessage);
public record MergePreviewDto(string Status, IReadOnlyList<string> ConflictFiles, int ChangedFileCount);
public record MergeTargetsDto(string DefaultBranch, IReadOnlyList<string> LocalBranches); public record MergeTargetsDto(string DefaultBranch, IReadOnlyList<string> LocalBranches);
public record UpdateListDto(string Id, string Name, string? WorkingDir, string DefaultCommitType); public record UpdateListDto(string Id, string Name, string? WorkingDir, string DefaultCommitType);
public record UpdateListConfigDto(string ListId, string? Model, string? SystemPrompt, string? AgentPath, int? MaxTurns = null); public record UpdateListConfigDto(string ListId, string? Model, string? SystemPrompt, string? AgentPath, int? MaxTurns = null);
@@ -320,6 +321,13 @@ public sealed class WorkerHub : Microsoft.AspNetCore.SignalR.Hub
return new MergeTargetsDto(t.DefaultBranch, t.LocalBranches); return new MergeTargetsDto(t.DefaultBranch, t.LocalBranches);
}); });
public Task<MergePreviewDto> PreviewMerge(string taskId, string targetBranch)
=> HubGuard(async () =>
{
var p = await _mergeService.PreviewAsync(taskId, targetBranch ?? "", CancellationToken.None);
return new MergePreviewDto(p.Status, p.ConflictFiles, p.ChangedFileCount);
});
public async Task UpdateList(UpdateListDto dto) public async Task UpdateList(UpdateListDto dto)
{ {
using var ctx = _dbFactory.CreateDbContext(); using var ctx = _dbFactory.CreateDbContext();
@@ -384,11 +392,14 @@ public sealed class WorkerHub : Microsoft.AspNetCore.SignalR.Hub
if (!result.Ok) throw new HubException(result.Reason ?? "set status failed"); if (!result.Ok) throw new HubException(result.Reason ?? "set status failed");
} }
public async Task ApproveReview(string taskId) public Task<MergeResultDto> ApproveReview(string taskId, string targetBranch)
{ => HubGuard(async () =>
var result = await _state.ApproveReviewAsync(taskId, Context.ConnectionAborted); {
if (!result.Ok) throw new HubException(result.Reason ?? "approve failed"); var r = await _mergeService.ApproveAndMergeAsync(taskId, targetBranch ?? "", CancellationToken.None);
} if (r.Status == TaskMergeService.StatusBlocked)
throw new HubException(r.ErrorMessage ?? "approve failed");
return new MergeResultDto(r.Status, r.ConflictFiles, r.ErrorMessage);
});
public async Task RejectReviewToQueue(string taskId, string feedback) public async Task RejectReviewToQueue(string taskId, string feedback)
{ {