Replace all GitHub API and gh CLI dependencies with Forgejo SDK via pkg/forge. The bash dispatcher burned a week of credit in a day due to bugs — the jobrunner now talks directly to Forgejo. - Add forge client methods: CreateIssueComment, CloseIssue, MergePullRequest, SetPRDraft, ListPRReviews, GetCombinedStatus, DismissReview - Create ForgejoSource implementing JobSource (epic polling, checklist parsing, commit status via combined status API) - Rewrite all 5 handlers to accept *forge.Client instead of shelling out - Replace ResolveThreadsHandler with DismissReviewsHandler (Forgejo has no thread resolution API — dismiss stale REQUEST_CHANGES reviews instead) - Delete pkg/jobrunner/github/ and handlers/exec.go entirely - Update internal/core-ide/headless.go to wire Forgejo source and handlers - All 33 tests pass with mock Forgejo HTTP servers Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
100 lines
2.8 KiB
Go
100 lines
2.8 KiB
Go
package handlers
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
forgejosdk "codeberg.org/mvdkleijn/forgejo-sdk/forgejo/v2"
|
|
|
|
"github.com/host-uk/core/pkg/forge"
|
|
"github.com/host-uk/core/pkg/jobrunner"
|
|
)
|
|
|
|
// TickParentHandler ticks a child checkbox in the parent epic issue body
|
|
// after the child's PR has been merged.
|
|
type TickParentHandler struct {
|
|
forge *forge.Client
|
|
}
|
|
|
|
// NewTickParentHandler creates a handler that ticks parent epic checkboxes.
|
|
func NewTickParentHandler(f *forge.Client) *TickParentHandler {
|
|
return &TickParentHandler{forge: f}
|
|
}
|
|
|
|
// Name returns the handler identifier.
|
|
func (h *TickParentHandler) Name() string {
|
|
return "tick_parent"
|
|
}
|
|
|
|
// Match returns true when the child PR has been merged.
|
|
func (h *TickParentHandler) Match(signal *jobrunner.PipelineSignal) bool {
|
|
return signal.PRState == "MERGED"
|
|
}
|
|
|
|
// Execute fetches the epic body, replaces the unchecked checkbox for the
|
|
// child issue with a checked one, updates the epic, and closes the child issue.
|
|
func (h *TickParentHandler) Execute(ctx context.Context, signal *jobrunner.PipelineSignal) (*jobrunner.ActionResult, error) {
|
|
start := time.Now()
|
|
|
|
// Fetch the epic issue body.
|
|
epic, err := h.forge.GetIssue(signal.RepoOwner, signal.RepoName, int64(signal.EpicNumber))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("tick_parent: fetch epic: %w", err)
|
|
}
|
|
|
|
oldBody := epic.Body
|
|
unchecked := fmt.Sprintf("- [ ] #%d", signal.ChildNumber)
|
|
checked := fmt.Sprintf("- [x] #%d", signal.ChildNumber)
|
|
|
|
if !strings.Contains(oldBody, unchecked) {
|
|
// Already ticked or not found -- nothing to do.
|
|
return &jobrunner.ActionResult{
|
|
Action: "tick_parent",
|
|
RepoOwner: signal.RepoOwner,
|
|
RepoName: signal.RepoName,
|
|
PRNumber: signal.PRNumber,
|
|
Success: true,
|
|
Timestamp: time.Now(),
|
|
Duration: time.Since(start),
|
|
}, nil
|
|
}
|
|
|
|
newBody := strings.Replace(oldBody, unchecked, checked, 1)
|
|
|
|
// Update the epic body.
|
|
_, err = h.forge.EditIssue(signal.RepoOwner, signal.RepoName, int64(signal.EpicNumber), forgejosdk.EditIssueOption{
|
|
Body: &newBody,
|
|
})
|
|
if err != nil {
|
|
return &jobrunner.ActionResult{
|
|
Action: "tick_parent",
|
|
RepoOwner: signal.RepoOwner,
|
|
RepoName: signal.RepoName,
|
|
PRNumber: signal.PRNumber,
|
|
Error: fmt.Sprintf("edit epic failed: %v", err),
|
|
Timestamp: time.Now(),
|
|
Duration: time.Since(start),
|
|
}, nil
|
|
}
|
|
|
|
// Close the child issue.
|
|
err = h.forge.CloseIssue(signal.RepoOwner, signal.RepoName, int64(signal.ChildNumber))
|
|
|
|
result := &jobrunner.ActionResult{
|
|
Action: "tick_parent",
|
|
RepoOwner: signal.RepoOwner,
|
|
RepoName: signal.RepoName,
|
|
PRNumber: signal.PRNumber,
|
|
Success: err == nil,
|
|
Timestamp: time.Now(),
|
|
Duration: time.Since(start),
|
|
}
|
|
|
|
if err != nil {
|
|
result.Error = fmt.Sprintf("close child issue failed: %v", err)
|
|
}
|
|
|
|
return result, nil
|
|
}
|