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>
91 lines
2.2 KiB
Go
91 lines
2.2 KiB
Go
package handlers
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/host-uk/core/pkg/jobrunner"
|
|
)
|
|
|
|
func TestDismissReviews_Match_Good(t *testing.T) {
|
|
h := NewDismissReviewsHandler(nil)
|
|
sig := &jobrunner.PipelineSignal{
|
|
PRState: "OPEN",
|
|
ThreadsTotal: 4,
|
|
ThreadsResolved: 2,
|
|
}
|
|
assert.True(t, h.Match(sig))
|
|
}
|
|
|
|
func TestDismissReviews_Match_Bad_AllResolved(t *testing.T) {
|
|
h := NewDismissReviewsHandler(nil)
|
|
sig := &jobrunner.PipelineSignal{
|
|
PRState: "OPEN",
|
|
ThreadsTotal: 3,
|
|
ThreadsResolved: 3,
|
|
}
|
|
assert.False(t, h.Match(sig))
|
|
}
|
|
|
|
func TestDismissReviews_Execute_Good(t *testing.T) {
|
|
callCount := 0
|
|
|
|
srv := httptest.NewServer(withVersion(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
callCount++
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
// ListPullReviews (GET)
|
|
if r.Method == http.MethodGet {
|
|
reviews := []map[string]any{
|
|
{
|
|
"id": 1, "state": "REQUEST_CHANGES", "dismissed": false, "stale": true,
|
|
"body": "fix this", "commit_id": "abc123",
|
|
},
|
|
{
|
|
"id": 2, "state": "APPROVED", "dismissed": false, "stale": false,
|
|
"body": "looks good", "commit_id": "abc123",
|
|
},
|
|
{
|
|
"id": 3, "state": "REQUEST_CHANGES", "dismissed": false, "stale": true,
|
|
"body": "needs work", "commit_id": "abc123",
|
|
},
|
|
}
|
|
_ = json.NewEncoder(w).Encode(reviews)
|
|
return
|
|
}
|
|
|
|
// DismissPullReview (POST to dismissals endpoint)
|
|
w.WriteHeader(http.StatusOK)
|
|
})))
|
|
defer srv.Close()
|
|
|
|
client := newTestForgeClient(t, srv.URL)
|
|
|
|
h := NewDismissReviewsHandler(client)
|
|
sig := &jobrunner.PipelineSignal{
|
|
RepoOwner: "host-uk",
|
|
RepoName: "core-admin",
|
|
PRNumber: 33,
|
|
PRState: "OPEN",
|
|
ThreadsTotal: 3,
|
|
ThreadsResolved: 1,
|
|
}
|
|
|
|
result, err := h.Execute(context.Background(), sig)
|
|
require.NoError(t, err)
|
|
|
|
assert.True(t, result.Success)
|
|
assert.Equal(t, "dismiss_reviews", result.Action)
|
|
assert.Equal(t, "host-uk", result.RepoOwner)
|
|
assert.Equal(t, "core-admin", result.RepoName)
|
|
assert.Equal(t, 33, result.PRNumber)
|
|
|
|
// 1 list + 2 dismiss (reviews #1 and #3 are stale REQUEST_CHANGES)
|
|
assert.Equal(t, 3, callCount)
|
|
}
|