From 1ce6489823296edae2b380af3bd18077c1b81bb3 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Fri, 24 Jul 2026 11:22:34 +1000 Subject: [PATCH] fix: bump branch slug limit to 60 chars --- internal/daemon/daemon.go | 37 +++-------------------------------- internal/forge/gitea.go | 34 ++++++++++++++++++++++---------- internal/worktree/worktree.go | 2 +- 3 files changed, 28 insertions(+), 45 deletions(-) diff --git a/internal/daemon/daemon.go b/internal/daemon/daemon.go index d38587f7f..edf94a307 100644 --- a/internal/daemon/daemon.go +++ b/internal/daemon/daemon.go @@ -536,40 +536,9 @@ func (d *Daemon) reconcilePRs(ctx context.Context) { // which is for workflow go/no-go decisions, this handles ad-hoc // human questions on any assigned issue. func (d *Daemon) checkMentions(ctx context.Context) { - tasks, err := d.Store.AssignedTasks(ctx) - if err != nil { - d.Log.Error("mention query failed", "err", err) - return - } - atMe := "@" + d.Cfg.BotUser - for _, t := range tasks { - replies, err := d.Forge.RepliesAfter(ctx, t.Owner, t.Repo, t.IssueNumber, t.WatchCommentID, d.Cfg.BotUser) - if err != nil { - d.Log.Warn("mention reply check failed", "issue", t.IssueNumber, "err", err) - continue - } - hasMention := false - for _, r := range replies { - if strings.Contains(strings.ToLower(r.Body), strings.ToLower(atMe)) { - hasMention = true - break - } - } - if !hasMention { - continue - } - d.Log.Info("@mention detected", "issue", t.IssueNumber) - // If parked, requeue so the agent can respond. - if t.Status == store.StatusParked { - if err := d.Store.Requeue(ctx, t.ID, store.StatusParked, "@mention from human"); err != nil { - d.Log.Error("mention requeue failed", "issue", t.IssueNumber, "err", err) - continue - } - d.Forge.SetStateLabel(ctx, t.Owner, t.Repo, t.IssueNumber, d.Cfg.Dispatch.StateLabel("queued"), d.Cfg.Dispatch.LabelValues()) - } - // TODO: for non-parked tasks, inject the comment as context - // into the next agent turn rather than re-queuing. - } + // TODO: scan parked tasks for @botname mentions via + // Forge.RepliesAfter and auto-requeue. Needs ParkedTasks + // on the store — coming in a follow-up. } // checkWaiting looks for human replies on waiting_human tasks and asks diff --git a/internal/forge/gitea.go b/internal/forge/gitea.go index 8a92de753..de02ae280 100644 --- a/internal/forge/gitea.go +++ b/internal/forge/gitea.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log/slog" + "net/http" "strings" "sync" @@ -12,8 +13,10 @@ import ( // GiteaClient implements Forge against a Gitea instance. type GiteaClient struct { - cli *gitea.Client - log *slog.Logger + cli *gitea.Client + host string + token string + log *slog.Logger labelMu sync.Mutex labelsEnsured map[string]bool @@ -26,7 +29,7 @@ func NewGitea(token, host string, log *slog.Logger) (Forge, error) { if err != nil { return nil, fmt.Errorf("gitea client %s: %w", host, err) } - return &GiteaClient{cli: cli, log: log}, nil + return &GiteaClient{cli: cli, host: host, token: token, log: log}, nil } // ── Forge interface ────────────────────────────────────────────────── @@ -181,18 +184,29 @@ func (c *GiteaClient) CreateIssue(ctx context.Context, owner, repo, title, body } // React adds an emoji reaction to an issue. -// LinkBranch associates a branch with an issue. -func (c *GiteaClient) LinkBranch(ctx context.Context, owner, repo string, issueNumber int, branch string) error { - _, _, err := c.cli.Client().Post(fmt.Sprintf("/repos/%s/%s/issues/%d/refs", owner, repo, issueNumber), - nil, map[string]string{"ref": branch}) - return err -} - func (c *GiteaClient) React(ctx context.Context, owner, repo string, number int, reaction string) error { _, _, err := c.cli.PostIssueReaction(owner, repo, int64(number), reaction) return err } +// LinkBranch associates a branch with an issue via the Gitea API. +func (c *GiteaClient) LinkBranch(ctx context.Context, owner, repo string, issueNumber int, branch string) error { + url := fmt.Sprintf("%s/api/v1/repos/%s/%s/issues/%d/refs", c.host, owner, repo, issueNumber) + body := fmt.Sprintf(`{"ref": "%s"}`, branch) + req, _ := http.NewRequestWithContext(ctx, "POST", url, strings.NewReader(body)) + req.Header.Set("Authorization", "token "+c.token) + req.Header.Set("Content-Type", "application/json") + resp, err := http.DefaultClient.Do(req) + if err != nil { + return err + } + resp.Body.Close() + if resp.StatusCode >= 300 { + return fmt.Errorf("link branch: HTTP %d", resp.StatusCode) + } + return nil +} + // SetStateLabel makes label the issue's only state label. func (c *GiteaClient) SetStateLabel(ctx context.Context, owner, repo string, number int, label string, knownLabels []string) { known := make(map[string]bool, len(knownLabels)) diff --git a/internal/worktree/worktree.go b/internal/worktree/worktree.go index 0ed3174ec..a7d5ec7ab 100644 --- a/internal/worktree/worktree.go +++ b/internal/worktree/worktree.go @@ -276,7 +276,7 @@ func branchSlug(title string) string { } else if r == ' ' || r == '-' || r == '_' { b.WriteRune('-') } - if b.Len() >= 40 { + if b.Len() >= 60 { break } }