feat(workflow): watched-repos triggers pr-review via the generic binding system
Watched-repos needs no bespoke webhook-parsing code: the existing generic capture+binding system (internal/infrastructure/captureintake, internal/domain/binding.Binding) already turns any inbound webhook into a task on any workflow, via a dashboard-editable matcher, CEL filter and payload-to-input mapping. pr-review just needed to become a binding-targetable workflow. - Workflow gains an Interface field (task.WorkflowInterface) so a Go-literal builtin can declare inputs the same way a YAML-defined one does; ShippedDefinitions emits an inputs: block only when non-empty, so every other builtin's generated YAML is byte-identical to before. - PRReview() declares pr_number as a required number input. - Task gains EffectivePRNumber(): PRNumber when a producer set it directly (archie's own PRs), else the pr_number input a binding assigned generically through Task.Inputs. Handles json.Number (the store's round-trip encoding), float64 and int. - The daemon resolves it once in acquireTaskContainer, before the task brief is written and before the pr-review prefetch runs, so everything downstream agrees. stagePRIntake falls back to the same resolution for any dispatch path that bypasses container acquisition, and fails loudly if neither PRNumber nor the input is set. An operator wires up watched-repos entirely through the dashboard: a Binding matching the webhook's source, a CEL filter for pull_request events, workflow: pr-review, and an Inputs mapping pr_number from the payload. No code change needed for a new repo or a new source. Operator/chat trigger remains open, left as a precise continuation: EnqueueChatTask is part of the State Store's protobuf-generated gRPC contract (proto/state/v1/state.proto), not just a Go interface -- extending it for a generic inputs parameter needs a proto field addition + regen, a new SQL query (StampTaskBinding cannot be reused, since it unconditionally stamps binding_id/version, which a plain chat task must never carry), and updates across staterpc's client/server and ~20 call sites. Real plumbing, not a quick tool rewrite -- scoped correctly as its own pass rather than rushed here.
This commit is contained in:
8 files changed
+176
-1
No files matched your search
@@ -9,6 +9,7 @@ package task
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/org"
|
||||
@@ -151,6 +152,34 @@ func (t Task) IsForgeBacked() bool {
|
||||
return t.Source != SourceChat
|
||||
}
|
||||
|
||||
// EffectivePRNumber resolves the pull request a pr-review task targets:
|
||||
// PRNumber when a producer already set it directly (archie's own PRs, which
|
||||
// never goes through binding/chat input assignment), otherwise the pr_number
|
||||
// input a binding (watched repositories) or a chat task (the operator
|
||||
// trigger) assigned generically through Inputs. Returns 0 when neither is
|
||||
// set. DecodeInputs (the store's round-trip) decodes a JSON number as
|
||||
// json.Number; a caller that built Inputs by hand in Go may use float64 or
|
||||
// int instead, so all three are accepted.
|
||||
func (t Task) EffectivePRNumber() int {
|
||||
if t.PRNumber != 0 {
|
||||
return t.PRNumber
|
||||
}
|
||||
switch n := t.Inputs["pr_number"].(type) {
|
||||
case json.Number:
|
||||
i, err := n.Int64()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
return int(i)
|
||||
case float64:
|
||||
return int(n)
|
||||
case int:
|
||||
return n
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
// Store is the narrow, consumer-owned subset of the State Store contract
|
||||
// that workflow stages call mid-run. The PostgreSQL store and staterpc.Client
|
||||
// satisfy it; this is the interface archie-agent uses over the gRPC State
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package task
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEffectivePRNumber(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
task Task
|
||||
want int
|
||||
}{
|
||||
{"PRNumber set directly wins", Task{PRNumber: 7, Inputs: map[string]any{"pr_number": json.Number("99")}}, 7},
|
||||
{"json.Number from a store round trip", Task{Inputs: map[string]any{"pr_number": json.Number("42")}}, 42},
|
||||
{"float64 from a hand-built map", Task{Inputs: map[string]any{"pr_number": float64(13)}}, 13},
|
||||
{"int from a hand-built map", Task{Inputs: map[string]any{"pr_number": 5}}, 5},
|
||||
{"missing input", Task{Inputs: map[string]any{}}, 0},
|
||||
{"nil Inputs", Task{}, 0},
|
||||
{"wrong type", Task{Inputs: map[string]any{"pr_number": "not a number"}}, 0},
|
||||
{"malformed json.Number", Task{Inputs: map[string]any{"pr_number": json.Number("not-a-number")}}, 0},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if got := test.task.EffectivePRNumber(); got != test.want {
|
||||
t.Errorf("EffectivePRNumber() = %d, want %d", got, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user