feat(worker): name task branches <type>/<number>-<slug>
This commit is contained in:
@@ -5,6 +5,7 @@ using ClaudeDo.Data.Repositories;
|
||||
using ClaudeDo.Worker.Config;
|
||||
using ClaudeDo.Worker.Git;
|
||||
using ClaudeDo.Worker.Hub;
|
||||
using ClaudeDo.Worker.Tickets;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ClaudeDo.Worker.Runner;
|
||||
@@ -76,7 +77,9 @@ public sealed class WorktreeManager
|
||||
_logger.LogInformation("Repository at {Dir} had no commits; created an empty bootstrap commit", workingDir);
|
||||
|
||||
var baseCommit = await ResolveBaseCommitAsync(task, workingDir, ct);
|
||||
var name = NameFor(task, null, false);
|
||||
var isCompany = await CompanyRepo.IsCompanyAsync(_git, workingDir, _cfg.CompanyRemotePattern, ct);
|
||||
var name = NameFor(task, await ResolveTicketIdAsync(task, ct), isCompany);
|
||||
var branchType = BranchTypeFor(task.CommitType);
|
||||
var slug = CommitMessageBuilder.ToSlug(list.Name);
|
||||
|
||||
string strategy;
|
||||
@@ -94,16 +97,16 @@ public sealed class WorktreeManager
|
||||
? Path.Combine(centralRoot ?? _cfg.CentralWorktreeRoot, slug)
|
||||
: Path.Combine(WorktreeRootResolver.ResolveSiblingRoot(workingDir), ".claudedo-worktrees", slug);
|
||||
|
||||
// Numbers restart after a DB reset: a taken name may be another task's unmerged branch,
|
||||
// which the self-heal below would force-delete — the id suffix keeps it untouched.
|
||||
// Numbers restart after a DB reset, and without the claudedo/ prefix a taken name may also be
|
||||
// the user's own branch — the self-heal below would force-delete it, the id suffix keeps it untouched.
|
||||
if (Directory.Exists(Path.Combine(parentDir, name))
|
||||
|| (await _git.ListLocalBranchesAsync(workingDir, ct)).Contains($"claudedo/{name}"))
|
||||
|| (await _git.ListLocalBranchesAsync(workingDir, ct)).Contains($"{branchType}/{name}"))
|
||||
{
|
||||
var id = task.Id.Replace("-", "");
|
||||
name = $"{name}-{id[..Math.Min(8, id.Length)]}";
|
||||
}
|
||||
|
||||
var branchName = $"claudedo/{name}";
|
||||
var branchName = $"{branchType}/{name}";
|
||||
var worktreePath = Path.GetFullPath(Path.Combine(parentDir, name));
|
||||
WorktreeRootResolver.EnsureOutsideWorkingDir(worktreePath, workingDir);
|
||||
|
||||
@@ -243,6 +246,19 @@ public sealed class WorktreeManager
|
||||
// Improvement children (parent is a non-planning task with its own worktree) branch
|
||||
// from the parent's recorded HEAD so they build on the parent's not-yet-merged work.
|
||||
// Planning children and standalone tasks base off the list's current HEAD.
|
||||
/// <summary>Ticket-Id des Tasks, sonst die seines Parents (Children erben das Ticket ihrer Unit).</summary>
|
||||
private async Task<int?> ResolveTicketIdAsync(TaskEntity task, CancellationToken ct)
|
||||
{
|
||||
var own = TicketStatusMap.ParseBandelTicketId(task.TicketRef);
|
||||
if (own is not null || task.ParentTaskId is null) return own;
|
||||
using var ctx = _dbFactory.CreateDbContext();
|
||||
var parentRef = await ctx.Tasks.AsNoTracking()
|
||||
.Where(t => t.Id == task.ParentTaskId)
|
||||
.Select(t => t.TicketRef)
|
||||
.FirstOrDefaultAsync(ct);
|
||||
return TicketStatusMap.ParseBandelTicketId(parentRef);
|
||||
}
|
||||
|
||||
private async Task<string> ResolveBaseCommitAsync(TaskEntity task, string workingDir, CancellationToken ct)
|
||||
{
|
||||
if (task.ParentTaskId is not null)
|
||||
|
||||
Reference in New Issue
Block a user