feat(workintake): authorize review reactions by owned PR
This commit is contained in:
1 parent
d956959d39
commit
0064da1d2b
13 files changed
+795
-434
No files matched your search
@@ -183,11 +183,12 @@ structures found in legacy packages.
|
||||
`providerRegistry.RegisterOptional`. Missing or failed providers log warnings
|
||||
and degrade health without terminating the process.
|
||||
- **`internal/infrastructure/staterpc/` (State Store gRPC contract):**
|
||||
Authority is `docs/prds/state-store-contract.md` (rev. 2d) -- read it before
|
||||
Authority is `docs/prds/state-store-contract.md` (rev. 2e) -- read it before
|
||||
changing this package or its callers.
|
||||
- The proto (`proto/state/v1/state.proto`, service `StateStoreService`,
|
||||
package `statev1` in `internal/contracts/state/v1/`) is one gRPC service
|
||||
fronting every ratified store contract (42 RPCs); the Go consumer facades
|
||||
fronting every ratified store contract (48 RPCs, including grant management
|
||||
and deprecated compatibility RPCs); the Go consumer facades
|
||||
stay narrow (`workflow.Store`, `store.TaskStore`, etc., all ≤8 methods
|
||||
except the `TaskStore` composite) via `staterpc.Client`'s multiple `var _`
|
||||
assertions -- never add a Go interface method without a matching RPC.
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
# State Store — contract boundary & transport (ratification)
|
||||
|
||||
**Status:** Ratified (rev. 2d). Rev. 2d revises §10 only: the `State ServiceConnection`
|
||||
struct-field instruction is withdrawn in favour of name-keyed services
|
||||
(`docs/prds/service-registry.md`). The contract, its 42 RPCs, and the listener topology are
|
||||
unchanged. Rev. 1 was marked *conditionally ratified*; the three
|
||||
**Status:** Ratified (rev. 2e). Rev. 2e adds the `OpenTaskByPR` authorization lookup required
|
||||
by the ratified PR-review remediation contract. Rev. 2d revised §10 only: the
|
||||
`State ServiceConnection` struct-field instruction was withdrawn in favour of name-keyed
|
||||
services (`docs/prds/service-registry.md`). Rev. 1 was marked *conditionally ratified*; the three
|
||||
reviewer conditions it raised are resolved (rev. 2), and the two third-pass findings are
|
||||
resolved here: (a) the stale Q3 migration wording in `service-decomposition.md`
|
||||
(`store.WorkflowStore`, `mode = "inproc" | "remote"`) now matches the ratified ownership split
|
||||
@@ -254,7 +254,7 @@ Methods are named after the store methods so the mapping is unambiguous. `workfl
|
||||
|---|---|
|
||||
| Lifecycle | `EnqueueIssue`, `EnqueueChatTask`, `ClaimNext`, `ClaimByIssue`, `Transition`, `Update`, `Requeue`, `RecoverStale` |
|
||||
| Archive / Retry | `ArchiveTask`, `RetryTask` |
|
||||
| Queries | `TaskByIssue`, `TaskByID`, `OpenPRs`, `ClearTerminalTasks`, `Tasks`, `StatusCounts`, `IncrementRetryCount` |
|
||||
| Queries | `TaskByIssue`, `OpenTaskByPR`, `TaskByID`, `OpenPRs`, `ClearTerminalTasks`, `Tasks`, `StatusCounts`, `IncrementRetryCount` |
|
||||
| Events | `InsertEvent`, `EventsSince`, `TaskEvents`, `WorkflowStats`, `StageStats`, `TokensByDay` |
|
||||
| Capture | `InsertCapture`, `ListCaptures` |
|
||||
| Mapping | `InsertMapping`, `GetMapping`, `ListMappings`, `UpdateMapping`, `DeleteMapping` |
|
||||
@@ -264,7 +264,7 @@ Methods are named after the store methods so the mapping is unambiguous. `workfl
|
||||
| Config snapshot | `PutConfigSnapshot`, `GetConfigSnapshot` |
|
||||
| Task log | `ReadTaskLog`, `StreamTaskLogContent` |
|
||||
|
||||
That is **44 unique RPCs** across one service (the `TaskEvents.Close` method is dropped).
|
||||
That is **45 unique contract RPCs** across one service (the `TaskEvents.Close` method is dropped).
|
||||
`Close()` is **excluded** from the wire (it is server lifecycle, not a client call) — see §11.
|
||||
|
||||
The config-snapshot pair was added by `archie-core-ymut` (see
|
||||
@@ -664,7 +664,7 @@ an explicit operator decision.
|
||||
(`workflow.Store` + `workflow.Task`/`Status`/`Source`, per dependency rules #2 and #7);
|
||||
daemon/webui store surfaces stay **producer-owned** in `internal/store`. `store.WorkflowStore`
|
||||
is superseded by `workflow.Store`.
|
||||
- **One `StateStore` gRPC service** (44 RPCs, grouped by contract) + narrow Go consumer facades
|
||||
- **One `StateStore` gRPC service** (45 contract RPCs, grouped by contract) + narrow Go consumer facades
|
||||
(≤8) on `staterpc.Client` — mirrors the single-`ChatService` precedent.
|
||||
- **Domain type relocation** (`Task`/`Status`/`Source` → `internal/domain/workflow`) is a
|
||||
Phase 2 prerequisite, pulled forward from migration-decisions §4 (minimal bound,
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -32,6 +32,7 @@ const (
|
||||
StateStoreService_ArchiveTask_FullMethodName = "/state.v1.StateStoreService/ArchiveTask"
|
||||
StateStoreService_RetryTask_FullMethodName = "/state.v1.StateStoreService/RetryTask"
|
||||
StateStoreService_TaskByIssue_FullMethodName = "/state.v1.StateStoreService/TaskByIssue"
|
||||
StateStoreService_OpenTaskByPR_FullMethodName = "/state.v1.StateStoreService/OpenTaskByPR"
|
||||
StateStoreService_TaskByID_FullMethodName = "/state.v1.StateStoreService/TaskByID"
|
||||
StateStoreService_OpenPRs_FullMethodName = "/state.v1.StateStoreService/OpenPRs"
|
||||
StateStoreService_ClearTerminalTasks_FullMethodName = "/state.v1.StateStoreService/ClearTerminalTasks"
|
||||
@@ -97,6 +98,7 @@ type StateStoreServiceClient interface {
|
||||
RetryTask(ctx context.Context, in *RetryTaskRequest, opts ...grpc.CallOption) (*RetryTaskResponse, error)
|
||||
// Queries
|
||||
TaskByIssue(ctx context.Context, in *TaskByIssueRequest, opts ...grpc.CallOption) (*TaskByIssueResponse, error)
|
||||
OpenTaskByPR(ctx context.Context, in *OpenTaskByPRRequest, opts ...grpc.CallOption) (*OpenTaskByPRResponse, error)
|
||||
TaskByID(ctx context.Context, in *TaskByIDRequest, opts ...grpc.CallOption) (*TaskByIDResponse, error)
|
||||
OpenPRs(ctx context.Context, in *OpenPRsRequest, opts ...grpc.CallOption) (*OpenPRsResponse, error)
|
||||
ClearTerminalTasks(ctx context.Context, in *ClearTerminalTasksRequest, opts ...grpc.CallOption) (*ClearTerminalTasksResponse, error)
|
||||
@@ -302,6 +304,16 @@ func (c *stateStoreServiceClient) TaskByIssue(ctx context.Context, in *TaskByIss
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *stateStoreServiceClient) OpenTaskByPR(ctx context.Context, in *OpenTaskByPRRequest, opts ...grpc.CallOption) (*OpenTaskByPRResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(OpenTaskByPRResponse)
|
||||
err := c.cc.Invoke(ctx, StateStoreService_OpenTaskByPR_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *stateStoreServiceClient) TaskByID(ctx context.Context, in *TaskByIDRequest, opts ...grpc.CallOption) (*TaskByIDResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(TaskByIDResponse)
|
||||
@@ -700,6 +712,7 @@ type StateStoreServiceServer interface {
|
||||
RetryTask(context.Context, *RetryTaskRequest) (*RetryTaskResponse, error)
|
||||
// Queries
|
||||
TaskByIssue(context.Context, *TaskByIssueRequest) (*TaskByIssueResponse, error)
|
||||
OpenTaskByPR(context.Context, *OpenTaskByPRRequest) (*OpenTaskByPRResponse, error)
|
||||
TaskByID(context.Context, *TaskByIDRequest) (*TaskByIDResponse, error)
|
||||
OpenPRs(context.Context, *OpenPRsRequest) (*OpenPRsResponse, error)
|
||||
ClearTerminalTasks(context.Context, *ClearTerminalTasksRequest) (*ClearTerminalTasksResponse, error)
|
||||
@@ -814,6 +827,9 @@ func (UnimplementedStateStoreServiceServer) RetryTask(context.Context, *RetryTas
|
||||
func (UnimplementedStateStoreServiceServer) TaskByIssue(context.Context, *TaskByIssueRequest) (*TaskByIssueResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method TaskByIssue not implemented")
|
||||
}
|
||||
func (UnimplementedStateStoreServiceServer) OpenTaskByPR(context.Context, *OpenTaskByPRRequest) (*OpenTaskByPRResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method OpenTaskByPR not implemented")
|
||||
}
|
||||
func (UnimplementedStateStoreServiceServer) TaskByID(context.Context, *TaskByIDRequest) (*TaskByIDResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method TaskByID not implemented")
|
||||
}
|
||||
@@ -1171,6 +1187,24 @@ func _StateStoreService_TaskByIssue_Handler(srv interface{}, ctx context.Context
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _StateStoreService_OpenTaskByPR_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(OpenTaskByPRRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(StateStoreServiceServer).OpenTaskByPR(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: StateStoreService_OpenTaskByPR_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(StateStoreServiceServer).OpenTaskByPR(ctx, req.(*OpenTaskByPRRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _StateStoreService_TaskByID_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(TaskByIDRequest)
|
||||
if err := dec(in); err != nil {
|
||||
@@ -1821,6 +1855,10 @@ var StateStoreService_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "TaskByIssue",
|
||||
Handler: _StateStoreService_TaskByIssue_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "OpenTaskByPR",
|
||||
Handler: _StateStoreService_OpenTaskByPR_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "TaskByID",
|
||||
Handler: _StateStoreService_TaskByID_Handler,
|
||||
|
||||
@@ -69,6 +69,7 @@ type TaskRetryer interface {
|
||||
// TaskQueries groups read-only task accessors.
|
||||
type TaskQueries interface {
|
||||
TaskByIssue(ctx context.Context, owner, repo string, number int) (*task.Task, error)
|
||||
OpenTaskByPR(ctx context.Context, owner, repo string, number int) (*task.Task, error)
|
||||
TaskByID(ctx context.Context, taskID int64) (*task.Task, error)
|
||||
OpenPRs(ctx context.Context) ([]task.Task, error)
|
||||
ClearTerminalTasks(ctx context.Context) (int64, error)
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package workintake
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync/atomic"
|
||||
|
||||
workflowtask "github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
||||
)
|
||||
|
||||
// ReviewTaskLookup is the authorization query review reactions require.
|
||||
type ReviewTaskLookup interface {
|
||||
OpenTaskByPR(ctx context.Context, owner, repo string, number int) (*workflowtask.Task, error)
|
||||
}
|
||||
|
||||
// ReviewTaskResolver admits only reactions for live Archie-owned pull requests.
|
||||
type ReviewTaskResolver struct {
|
||||
Tasks ReviewTaskLookup
|
||||
dropped atomic.Int64
|
||||
}
|
||||
|
||||
// Resolve returns the live task that owns reaction's pull request.
|
||||
func (r *ReviewTaskResolver) Resolve(ctx context.Context, reaction ReviewCommentEnvelope) (*workflowtask.Task, error) {
|
||||
task, err := r.Tasks.OpenTaskByPR(ctx, reaction.Owner, reaction.Repo, reaction.PRNumber)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if task == nil {
|
||||
r.dropped.Add(1)
|
||||
}
|
||||
return task, nil
|
||||
}
|
||||
|
||||
// Dropped reports how many reactions did not resolve to a live owned task.
|
||||
func (r *ReviewTaskResolver) Dropped() int64 { return r.dropped.Load() }
|
||||
@@ -0,0 +1,46 @@
|
||||
package workintake
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
workflowtask "github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
||||
)
|
||||
|
||||
type reviewTaskLookupFunc func(context.Context, string, string, int) (*workflowtask.Task, error)
|
||||
|
||||
func (f reviewTaskLookupFunc) OpenTaskByPR(ctx context.Context, owner, repo string, number int) (*workflowtask.Task, error) {
|
||||
return f(ctx, owner, repo, number)
|
||||
}
|
||||
|
||||
func TestReviewTaskResolverDropsOnlyUnownedReactions(t *testing.T) {
|
||||
want := &workflowtask.Task{ID: 7, Owner: "acme", Repo: "widgets", PRNumber: 42, Status: workflowtask.StatusPROpen}
|
||||
lookupErr := errors.New("state store unavailable")
|
||||
resolver := &ReviewTaskResolver{Tasks: reviewTaskLookupFunc(func(_ context.Context, owner, repo string, number int) (*workflowtask.Task, error) {
|
||||
switch number {
|
||||
case 42:
|
||||
if owner != want.Owner || repo != want.Repo {
|
||||
t.Fatalf("lookup coordinates = %s/%s, want %s/%s", owner, repo, want.Owner, want.Repo)
|
||||
}
|
||||
return want, nil
|
||||
case 43:
|
||||
return nil, nil
|
||||
default:
|
||||
return nil, lookupErr
|
||||
}
|
||||
})}
|
||||
|
||||
got, err := resolver.Resolve(t.Context(), ReviewCommentEnvelope{Owner: "acme", Repo: "widgets", PRNumber: 42})
|
||||
if err != nil || got != want || resolver.Dropped() != 0 {
|
||||
t.Fatalf("Resolve(owned) = (%+v, %v), dropped=%d", got, err, resolver.Dropped())
|
||||
}
|
||||
got, err = resolver.Resolve(t.Context(), ReviewCommentEnvelope{Owner: "acme", Repo: "widgets", PRNumber: 43})
|
||||
if err != nil || got != nil || resolver.Dropped() != 1 {
|
||||
t.Fatalf("Resolve(unowned) = (%+v, %v), dropped=%d, want nil, nil, 1", got, err, resolver.Dropped())
|
||||
}
|
||||
got, err = resolver.Resolve(t.Context(), ReviewCommentEnvelope{Owner: "acme", Repo: "widgets", PRNumber: 44})
|
||||
if !errors.Is(err, lookupErr) || got != nil || resolver.Dropped() != 1 {
|
||||
t.Fatalf("Resolve(error) = (%+v, %v), dropped=%d, want nil, lookup error, 1", got, err, resolver.Dropped())
|
||||
}
|
||||
}
|
||||
@@ -137,6 +137,17 @@ func (c *Client) TaskByIssue(ctx context.Context, owner, repo string, number int
|
||||
return taskValue(r.Task), nil
|
||||
}
|
||||
|
||||
func (c *Client) OpenTaskByPR(ctx context.Context, owner, repo string, number int) (*task.Task, error) {
|
||||
r, err := c.client.OpenTaskByPR(ctx, &pb.OpenTaskByPRRequest{Owner: owner, Repo: repo, Number: int64(number)})
|
||||
if err != nil {
|
||||
return nil, unmapError(err)
|
||||
}
|
||||
if !r.Found {
|
||||
return nil, nil
|
||||
}
|
||||
return taskValue(r.Task), nil
|
||||
}
|
||||
|
||||
func (c *Client) TaskByID(ctx context.Context, taskID int64) (*task.Task, error) {
|
||||
r, err := c.client.TaskByID(ctx, &pb.TaskByIDRequest{TaskId: taskID})
|
||||
if err != nil {
|
||||
|
||||
@@ -93,6 +93,7 @@ func TestStateStoreConformance(t *testing.T) {
|
||||
}
|
||||
task.Plan = "the plan"
|
||||
task.Status = "running"
|
||||
task.PRNumber = 401
|
||||
if err := c.Update(ctx, task); err != nil {
|
||||
t.Fatalf("Update: %v", err)
|
||||
}
|
||||
@@ -136,6 +137,17 @@ func TestStateStoreConformance(t *testing.T) {
|
||||
if err != nil || byIssue == nil || byIssue.ID != task.ID {
|
||||
t.Fatalf("TaskByIssue: %+v %v", byIssue, err)
|
||||
}
|
||||
if err := c.Transition(ctx, task.ID, "running", "pr_open", "PR #401"); err != nil {
|
||||
t.Fatalf("Transition to pr_open: %v", err)
|
||||
}
|
||||
byPR, err := c.OpenTaskByPR(ctx, task.Owner, task.Repo, task.PRNumber)
|
||||
if err != nil || byPR == nil || byPR.ID != task.ID {
|
||||
t.Fatalf("OpenTaskByPR: %+v %v", byPR, err)
|
||||
}
|
||||
missing, err = c.OpenTaskByPR(ctx, task.Owner, task.Repo, task.PRNumber+1)
|
||||
if err != nil || missing != nil {
|
||||
t.Fatalf("OpenTaskByPR missing: %+v %v", missing, err)
|
||||
}
|
||||
if _, err := c.Tasks(ctx, 10); err != nil {
|
||||
t.Fatalf("Tasks: %v", err)
|
||||
}
|
||||
|
||||
@@ -189,6 +189,14 @@ func (s *server) TaskByIssue(ctx context.Context, r *pb.TaskByIssueRequest) (*pb
|
||||
return &pb.TaskByIssueResponse{Task: taskProto(t), Found: t != nil}, nil
|
||||
}
|
||||
|
||||
func (s *server) OpenTaskByPR(ctx context.Context, r *pb.OpenTaskByPRRequest) (*pb.OpenTaskByPRResponse, error) {
|
||||
t, err := s.deps.Tasks.OpenTaskByPR(ctx, r.Owner, r.Repo, int(r.Number))
|
||||
if err != nil {
|
||||
return nil, s.logErr("OpenTaskByPR", err)
|
||||
}
|
||||
return &pb.OpenTaskByPRResponse{Task: taskProto(t), Found: t != nil}, nil
|
||||
}
|
||||
|
||||
func (s *server) TaskByID(ctx context.Context, r *pb.TaskByIDRequest) (*pb.TaskByIDResponse, error) {
|
||||
t, err := s.deps.Tasks.TaskByID(ctx, r.TaskId)
|
||||
if err != nil {
|
||||
|
||||
@@ -34,6 +34,54 @@ func TestTaskByIssue(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpenTaskByPR(t *testing.T) {
|
||||
s := openTest(t)
|
||||
ctx := t.Context()
|
||||
|
||||
for i, status := range []string{workflow.StatusPROpen, workflow.StatusMerged, workflow.StatusRejected} {
|
||||
issueNumber := i + 1
|
||||
prNumber := 101 + i
|
||||
if _, err := s.EnqueueIssue(ctx, "acme", "widget", issueNumber, "title", "body", "", ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
task, err := s.TaskByIssue(ctx, "acme", "widget", issueNumber)
|
||||
if err != nil || task == nil {
|
||||
t.Fatalf("TaskByIssue(%d) = (%+v, %v)", issueNumber, task, err)
|
||||
}
|
||||
task.PRNumber = prNumber
|
||||
if err := s.Update(ctx, task); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.Transition(ctx, task.ID, workflow.StatusQueued, status, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
got, err := s.OpenTaskByPR(ctx, "acme", "widget", 101)
|
||||
if err != nil || got == nil || got.IssueNumber != 1 {
|
||||
t.Fatalf("OpenTaskByPR(open) = (%+v, %v)", got, err)
|
||||
}
|
||||
for _, prNumber := range []int{102, 103, 999} {
|
||||
got, err := s.OpenTaskByPR(ctx, "acme", "widget", prNumber)
|
||||
if err != nil || got != nil {
|
||||
t.Errorf("OpenTaskByPR(%d) = (%+v, %v), want (nil, nil)", prNumber, got, err)
|
||||
}
|
||||
}
|
||||
if got, err := s.OpenTaskByPR(ctx, "other", "widget", 101); err != nil || got != nil {
|
||||
t.Errorf("OpenTaskByPR(other owner) = (%+v, %v), want (nil, nil)", got, err)
|
||||
}
|
||||
|
||||
var indexedColumns string
|
||||
if err := s.db.QueryRowContext(ctx, `
|
||||
SELECT group_concat(name, ',')
|
||||
FROM pragma_index_info('idx_tasks_pr')`).Scan(&indexedColumns); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if indexedColumns != "owner,repo,pr_number" {
|
||||
t.Fatalf("idx_tasks_pr columns = %q, want owner,repo,pr_number", indexedColumns)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequeueFromWaitingHuman(t *testing.T) {
|
||||
s := openTest(t)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -135,6 +135,15 @@ func migrateTasks(ctx context.Context, db *sql.DB) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return finishTaskMigration(ctx, tx, columns)
|
||||
}
|
||||
|
||||
func finishTaskMigration(ctx context.Context, tx *sql.Tx, columns map[string]bool) error {
|
||||
if columns["owner"] && columns["repo"] && columns["pr_number"] {
|
||||
if _, err := tx.ExecContext(ctx, `CREATE INDEX IF NOT EXISTS idx_tasks_pr ON tasks(owner, repo, pr_number)`); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := tx.ExecContext(ctx, `PRAGMA user_version = 3`); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -418,6 +427,23 @@ func (s *Store) TaskByIssue(ctx context.Context, owner, repo string, number int)
|
||||
return t, err
|
||||
}
|
||||
|
||||
// OpenTaskByPR returns the live task that owns the given pull request, or nil.
|
||||
func (s *Store) OpenTaskByPR(ctx context.Context, owner, repo string, number int) (*workflow.Task, error) {
|
||||
row := s.db.QueryRowContext(ctx, `
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status,
|
||||
workflow, stage, branch, plan, notes, pr_number, tokens_used,
|
||||
iterations, attempt, park_reason, watch_comment_id, retry_count,
|
||||
source, identity, binding_id, binding_version, created_at, updated_at
|
||||
FROM tasks
|
||||
WHERE owner=? AND repo=? AND pr_number=? AND status=?`,
|
||||
owner, repo, number, workflow.StatusPROpen)
|
||||
t, err := scanTask(row)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, nil
|
||||
}
|
||||
return t, err
|
||||
}
|
||||
|
||||
// TaskByID returns the task with the given database ID, or nil. Used by
|
||||
// chat controls (/approve, /cancel) that reference a task by its real
|
||||
// ID rather than a forge issue number.
|
||||
|
||||
@@ -31,6 +31,7 @@ service StateStoreService {
|
||||
|
||||
// Queries
|
||||
rpc TaskByIssue(TaskByIssueRequest) returns (TaskByIssueResponse);
|
||||
rpc OpenTaskByPR(OpenTaskByPRRequest) returns (OpenTaskByPRResponse);
|
||||
rpc TaskByID(TaskByIDRequest) returns (TaskByIDResponse);
|
||||
rpc OpenPRs(OpenPRsRequest) returns (OpenPRsResponse);
|
||||
rpc ClearTerminalTasks(ClearTerminalTasksRequest) returns (ClearTerminalTasksResponse);
|
||||
@@ -331,6 +332,16 @@ message TaskByIssueResponse {
|
||||
bool found = 2;
|
||||
}
|
||||
|
||||
message OpenTaskByPRRequest {
|
||||
string owner = 1;
|
||||
string repo = 2;
|
||||
int64 number = 3;
|
||||
}
|
||||
message OpenTaskByPRResponse {
|
||||
Task task = 1;
|
||||
bool found = 2;
|
||||
}
|
||||
|
||||
message TaskByIDRequest { int64 task_id = 1; }
|
||||
message TaskByIDResponse {
|
||||
Task task = 1;
|
||||
|
||||
Reference in new issue
Block a user