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>
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package handlers
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/host-uk/core/pkg/forge"
|
|
"github.com/host-uk/core/pkg/jobrunner"
|
|
)
|
|
|
|
// PublishDraftHandler marks a draft PR as ready for review once its checks pass.
|
|
type PublishDraftHandler struct {
|
|
forge *forge.Client
|
|
}
|
|
|
|
// NewPublishDraftHandler creates a handler that publishes draft PRs.
|
|
func NewPublishDraftHandler(f *forge.Client) *PublishDraftHandler {
|
|
return &PublishDraftHandler{forge: f}
|
|
}
|
|
|
|
// Name returns the handler identifier.
|
|
func (h *PublishDraftHandler) Name() string {
|
|
return "publish_draft"
|
|
}
|
|
|
|
// Match returns true when the PR is a draft, open, and all checks have passed.
|
|
func (h *PublishDraftHandler) Match(signal *jobrunner.PipelineSignal) bool {
|
|
return signal.IsDraft &&
|
|
signal.PRState == "OPEN" &&
|
|
signal.CheckStatus == "SUCCESS"
|
|
}
|
|
|
|
// Execute marks the PR as no longer a draft.
|
|
func (h *PublishDraftHandler) Execute(ctx context.Context, signal *jobrunner.PipelineSignal) (*jobrunner.ActionResult, error) {
|
|
start := time.Now()
|
|
|
|
err := h.forge.SetPRDraft(signal.RepoOwner, signal.RepoName, int64(signal.PRNumber), false)
|
|
|
|
result := &jobrunner.ActionResult{
|
|
Action: "publish_draft",
|
|
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("publish draft failed: %v", err)
|
|
}
|
|
|
|
return result, nil
|
|
}
|