refactor(archied): delete the file-configured forge webhook receiver; forge webhooks arrive through event capture (#1817)
This commit is contained in:
21 files changed
+110
-1508
No files matched your search
@@ -19,9 +19,6 @@ bot_user = "vectis-labs-archie"
|
||||
type = "github"
|
||||
host = "https://github.com"
|
||||
token = { engine = "env", key = "ARCHIE_GITHUB_TOKEN" }
|
||||
# intake = "poll" # "poll", "webhook" or "both"
|
||||
# webhook_secret = { engine = "env", key = "ARCHIE_WEBHOOK_SECRET" }
|
||||
# webhook_addr = "0.0.0.0:8645"
|
||||
|
||||
[dispatch]
|
||||
trigger = "assignee" # "assignee", "label" or "either"
|
||||
|
||||
@@ -78,7 +78,7 @@ accounts by unverified email, or create an administrator.
|
||||
| Chat downloads: `webui/api_chat_files.go` | Offered file token expires and is bound to the initiating person; requests cannot supply a filesystem path. | `TestChatFileDownload` |
|
||||
| Per-person memory: `archiegateway/chat_identity.go`, gateway memory tools, `sessioncurator` | Verified web sender identity scopes reads/writes. Curator refuses unidentified or mixed participants instead of guessing a person. | Gateway memory and session-curator tests |
|
||||
| Workflow/task actions: `webui/api_tasks.go`, `domain/taskactions`, `staterpc` | Policy and stored workspace before action; domain transition, authority and durable dispatch guards remain in force. | HTTP deny matrix, task action/domain tests, task grant tests |
|
||||
| Incoming webhooks: `forge/webhook`, `captureintake`, access delivery engine | Verify HMAC before parsing; derive source/org from stored source; evaluate source delivery policies and egress rules. No browser-user credential is inferred. | Webhook/capture tests, `TestAuthorizeDelivery` |
|
||||
| Incoming webhooks: `captureintake`, access delivery engine | Verify HMAC before parsing; derive source/org from stored source; evaluate source delivery policies and egress rules. No browser-user credential is inferred. | Capture tests, `TestAuthorizeDelivery` |
|
||||
| Control-plane configuration, secrets, harness and extensions | Browser policy and instance-only restrictions where registered; service contracts carry principal/org; task grants cannot invoke administrative RPCs. | HTTP deny matrix, `TestAdministrationRoutes`, `TestChannelReloadRoute`, `TestConfineHarnessOrg` |
|
||||
| Audit feed: `webui/api_audit.go`, `domain/audit` | `read_audit` on the `audit` resource; org scope and the instance-wide exception come from the authenticated principal, never the query string. Export carries the same grant, needs an explicit range of at most a year, and is rate-limited per identity, one at a time. Redaction runs in the State Store adapter before an entry crosses gRPC. | `TestReadAuditRoleBoundary`, `TestAuditRoutesFollowTheReadAuditRole`, `TestHTTPPolicyCannotBeBypassed`, `TestAuditErrorMapping`, `TestAuditCSVCellNeutralisesFormulas` |
|
||||
| Live HTTP/SSE and diagnostics | Authenticated policy gate applies before stream creation; org-scoped event reads; instance logs require administrative visibility. | HTTP deny matrix, instance-only tests, `TestServiceLogsRequireInstanceCredential` |
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/signal"
|
||||
@@ -43,7 +42,6 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/domain/workintake"
|
||||
"github.com/samcharles93/archie-core/internal/events"
|
||||
"github.com/samcharles93/archie-core/internal/forge"
|
||||
forgewebhook "github.com/samcharles93/archie-core/internal/forge/webhook"
|
||||
"github.com/samcharles93/archie-core/internal/gateway"
|
||||
infraaccess "github.com/samcharles93/archie-core/internal/infrastructure/access"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
|
||||
@@ -680,7 +678,6 @@ func (b *boot) buildDaemon() {
|
||||
b.d.Denials = denials
|
||||
}
|
||||
b.d.PlaybookLedger = playbookLedger(b.stateStore, b.log)
|
||||
b.setupForgeWebhook()
|
||||
}
|
||||
|
||||
func playbookLedger(source any, log *slog.Logger) storecontract.PlaybookDispatcher {
|
||||
@@ -691,43 +688,6 @@ func playbookLedger(source any, log *slog.Logger) storecontract.PlaybookDispatch
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *boot) setupForgeWebhook() {
|
||||
cfg, log := b.cfg, b.log
|
||||
if cfg.Forge.Intake != config.ForgeIntakeWebhook && cfg.Forge.Intake != config.ForgeIntakeBoth {
|
||||
return
|
||||
}
|
||||
parser, ok := b.forgeClient.(forge.WebhookParser)
|
||||
if !ok {
|
||||
log.Error("forge webhook disabled: the forge cannot parse webhooks", "forge_type", cfg.Forge.Type)
|
||||
return
|
||||
}
|
||||
secretValue, err := b.secrets.Resolve(cfg.Forge.WebhookSecret)
|
||||
if err != nil || secretValue == "" {
|
||||
log.Error("forge webhook disabled: secret unavailable",
|
||||
"engine", cfg.Forge.WebhookSecret.Engine, "key", cfg.Forge.WebhookSecret.Key, "err", err)
|
||||
return
|
||||
}
|
||||
|
||||
receiver := forgewebhook.New(secretValue, parser, cfg.Dispatch.Trigger, cfg.Label, cfg.BotUser, b.d.PublishTask, b.d.PublishReaction, b.withdrawIssue, log)
|
||||
host, port := parseListenAddr(cfg.Forge.WebhookAddr, "0.0.0.0", 8645)
|
||||
addr := fmt.Sprintf("%s:%d", host, port)
|
||||
srv := &http.Server{Addr: addr, Handler: receiver, ReadHeaderTimeout: 5 * time.Second}
|
||||
|
||||
b.startGateways = append(b.startGateways, func() {
|
||||
go func() {
|
||||
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||
log.Error("forge webhook server stopped", "err", err)
|
||||
}
|
||||
}()
|
||||
log.Info("forge webhook listening", "addr", addr)
|
||||
})
|
||||
b.addCleanup(func() {
|
||||
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
_ = srv.Shutdown(shutdownCtx)
|
||||
})
|
||||
}
|
||||
|
||||
func (b *boot) publishConfig(ctx context.Context, cfg config.Config) {
|
||||
b.cfgHolder.Set(cfg)
|
||||
// The daemon owns the published configuration view.
|
||||
|
||||
@@ -12,11 +12,9 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
@@ -253,23 +251,6 @@ func persistEvents(ctx context.Context, sink *events.Sub, st storecontract.TaskS
|
||||
}
|
||||
}
|
||||
|
||||
// parseListenAddr splits "host:port" into components, using defaults
|
||||
// when the input is empty or missing a part.
|
||||
func parseListenAddr(addr, defaultHost string, defaultPort int) (string, int) {
|
||||
if addr == "" {
|
||||
return defaultHost, defaultPort
|
||||
}
|
||||
host, portStr, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
return defaultHost, defaultPort
|
||||
}
|
||||
port, err := strconv.Atoi(portStr)
|
||||
if err != nil || port < 0 {
|
||||
return host, defaultPort
|
||||
}
|
||||
return host, port
|
||||
}
|
||||
|
||||
// subscribeSystemLogs subscribes to every task's system log subject at once.
|
||||
// archie-agent's own log lines ship here (agentexec.SubjectForSystem) rather
|
||||
// than staying on its stderr, and this is where they land: one wildcard
|
||||
|
||||
@@ -29,15 +29,6 @@ func (b *boot) taskActions() taskactions.Service {
|
||||
)
|
||||
}
|
||||
|
||||
// withdrawIssue declines the task an issue queued, if it has one.
|
||||
func (b *boot) withdrawIssue(ctx context.Context, owner, repo string, number int, reason string) error {
|
||||
task, err := b.stateStore.TaskByIssue(ctx, owner, repo, number)
|
||||
if err != nil || task == nil {
|
||||
return err
|
||||
}
|
||||
return b.taskActions().Withdraw(ctx, task.ID, reason)
|
||||
}
|
||||
|
||||
func (b *boot) cancelTask(id int64) bool {
|
||||
if b.d == nil {
|
||||
return false
|
||||
|
||||
@@ -233,30 +233,11 @@ type Provider struct {
|
||||
Disabled bool `toml:"-" yaml:"-" json:"-"`
|
||||
}
|
||||
|
||||
// Forge intake modes for Forge.Intake. Poll is the default; webhook reacts to
|
||||
// forge events as they arrive instead of (or in addition to) polling.
|
||||
const (
|
||||
ForgeIntakePoll = "poll"
|
||||
ForgeIntakeWebhook = "webhook"
|
||||
ForgeIntakeBoth = "both"
|
||||
)
|
||||
|
||||
// Forge configures the code forge integration.
|
||||
type Forge struct {
|
||||
Type string `toml:"type" yaml:"type"`
|
||||
Host string `toml:"host" yaml:"host"`
|
||||
Token SecretRef `toml:"token" yaml:"token"`
|
||||
// Intake selects how forge issues become work: "poll" (default),
|
||||
// "webhook", or "both". Webhook intake reacts to forge events the moment
|
||||
// they arrive instead of up to poll_interval later.
|
||||
Intake string `toml:"intake" yaml:"intake"`
|
||||
// WebhookSecret is the shared secret used to verify GitHub webhook
|
||||
// signatures (X-Hub-Signature-256). Required when Intake is "webhook" or
|
||||
// "both".
|
||||
WebhookSecret SecretRef `toml:"webhook_secret" yaml:"webhook_secret"`
|
||||
// WebhookAddr is the host:port the webhook receiver listens on. Required
|
||||
// when Intake is "webhook" or "both".
|
||||
WebhookAddr string `toml:"webhook_addr" yaml:"webhook_addr"`
|
||||
}
|
||||
|
||||
// Dispatch configures how archied discovers work and reacts on pickup.
|
||||
|
||||
@@ -2804,464 +2804,6 @@ func (x *GetRepoArchiveResponse) GetData() []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
type ParseWebhookRequest struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Headers map[string]string `protobuf:"bytes,1,rep,name=headers,proto3" json:"headers,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
|
||||
Body []byte `protobuf:"bytes,2,opt,name=body,proto3" json:"body,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *ParseWebhookRequest) Reset() {
|
||||
*x = ParseWebhookRequest{}
|
||||
mi := &file_forge_v1_forge_proto_msgTypes[53]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *ParseWebhookRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*ParseWebhookRequest) ProtoMessage() {}
|
||||
|
||||
func (x *ParseWebhookRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_forge_v1_forge_proto_msgTypes[53]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use ParseWebhookRequest.ProtoReflect.Descriptor instead.
|
||||
func (*ParseWebhookRequest) Descriptor() ([]byte, []int) {
|
||||
return file_forge_v1_forge_proto_rawDescGZIP(), []int{53}
|
||||
}
|
||||
|
||||
func (x *ParseWebhookRequest) GetHeaders() map[string]string {
|
||||
if x != nil {
|
||||
return x.Headers
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *ParseWebhookRequest) GetBody() []byte {
|
||||
if x != nil {
|
||||
return x.Body
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type ParseWebhookResponse struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
// Types that are valid to be assigned to Event:
|
||||
//
|
||||
// *ParseWebhookResponse_Issue
|
||||
// *ParseWebhookResponse_Review
|
||||
// *ParseWebhookResponse_ReviewComment
|
||||
Event isParseWebhookResponse_Event `protobuf_oneof:"event"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *ParseWebhookResponse) Reset() {
|
||||
*x = ParseWebhookResponse{}
|
||||
mi := &file_forge_v1_forge_proto_msgTypes[54]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *ParseWebhookResponse) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*ParseWebhookResponse) ProtoMessage() {}
|
||||
|
||||
func (x *ParseWebhookResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_forge_v1_forge_proto_msgTypes[54]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use ParseWebhookResponse.ProtoReflect.Descriptor instead.
|
||||
func (*ParseWebhookResponse) Descriptor() ([]byte, []int) {
|
||||
return file_forge_v1_forge_proto_rawDescGZIP(), []int{54}
|
||||
}
|
||||
|
||||
func (x *ParseWebhookResponse) GetEvent() isParseWebhookResponse_Event {
|
||||
if x != nil {
|
||||
return x.Event
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *ParseWebhookResponse) GetIssue() *IssueEvent {
|
||||
if x != nil {
|
||||
if x, ok := x.Event.(*ParseWebhookResponse_Issue); ok {
|
||||
return x.Issue
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *ParseWebhookResponse) GetReview() *ReviewEvent {
|
||||
if x != nil {
|
||||
if x, ok := x.Event.(*ParseWebhookResponse_Review); ok {
|
||||
return x.Review
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *ParseWebhookResponse) GetReviewComment() *ReviewCommentEvent {
|
||||
if x != nil {
|
||||
if x, ok := x.Event.(*ParseWebhookResponse_ReviewComment); ok {
|
||||
return x.ReviewComment
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type isParseWebhookResponse_Event interface {
|
||||
isParseWebhookResponse_Event()
|
||||
}
|
||||
|
||||
type ParseWebhookResponse_Issue struct {
|
||||
Issue *IssueEvent `protobuf:"bytes,1,opt,name=issue,proto3,oneof"`
|
||||
}
|
||||
|
||||
type ParseWebhookResponse_Review struct {
|
||||
Review *ReviewEvent `protobuf:"bytes,2,opt,name=review,proto3,oneof"`
|
||||
}
|
||||
|
||||
type ParseWebhookResponse_ReviewComment struct {
|
||||
ReviewComment *ReviewCommentEvent `protobuf:"bytes,3,opt,name=review_comment,json=reviewComment,proto3,oneof"`
|
||||
}
|
||||
|
||||
func (*ParseWebhookResponse_Issue) isParseWebhookResponse_Event() {}
|
||||
|
||||
func (*ParseWebhookResponse_Review) isParseWebhookResponse_Event() {}
|
||||
|
||||
func (*ParseWebhookResponse_ReviewComment) isParseWebhookResponse_Event() {}
|
||||
|
||||
type IssueEvent struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Action string `protobuf:"bytes,1,opt,name=action,proto3" json:"action,omitempty"`
|
||||
State string `protobuf:"bytes,2,opt,name=state,proto3" json:"state,omitempty"`
|
||||
IsPullRequest bool `protobuf:"varint,3,opt,name=is_pull_request,json=isPullRequest,proto3" json:"is_pull_request,omitempty"`
|
||||
Repo *RepoRef `protobuf:"bytes,4,opt,name=repo,proto3" json:"repo,omitempty"`
|
||||
Number int32 `protobuf:"varint,5,opt,name=number,proto3" json:"number,omitempty"`
|
||||
Title string `protobuf:"bytes,6,opt,name=title,proto3" json:"title,omitempty"`
|
||||
Body string `protobuf:"bytes,7,opt,name=body,proto3" json:"body,omitempty"`
|
||||
Labels []string `protobuf:"bytes,8,rep,name=labels,proto3" json:"labels,omitempty"`
|
||||
Assignees []string `protobuf:"bytes,9,rep,name=assignees,proto3" json:"assignees,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *IssueEvent) Reset() {
|
||||
*x = IssueEvent{}
|
||||
mi := &file_forge_v1_forge_proto_msgTypes[55]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *IssueEvent) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*IssueEvent) ProtoMessage() {}
|
||||
|
||||
func (x *IssueEvent) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_forge_v1_forge_proto_msgTypes[55]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use IssueEvent.ProtoReflect.Descriptor instead.
|
||||
func (*IssueEvent) Descriptor() ([]byte, []int) {
|
||||
return file_forge_v1_forge_proto_rawDescGZIP(), []int{55}
|
||||
}
|
||||
|
||||
func (x *IssueEvent) GetAction() string {
|
||||
if x != nil {
|
||||
return x.Action
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *IssueEvent) GetState() string {
|
||||
if x != nil {
|
||||
return x.State
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *IssueEvent) GetIsPullRequest() bool {
|
||||
if x != nil {
|
||||
return x.IsPullRequest
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *IssueEvent) GetRepo() *RepoRef {
|
||||
if x != nil {
|
||||
return x.Repo
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *IssueEvent) GetNumber() int32 {
|
||||
if x != nil {
|
||||
return x.Number
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *IssueEvent) GetTitle() string {
|
||||
if x != nil {
|
||||
return x.Title
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *IssueEvent) GetBody() string {
|
||||
if x != nil {
|
||||
return x.Body
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *IssueEvent) GetLabels() []string {
|
||||
if x != nil {
|
||||
return x.Labels
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *IssueEvent) GetAssignees() []string {
|
||||
if x != nil {
|
||||
return x.Assignees
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type ReviewEvent struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Action string `protobuf:"bytes,1,opt,name=action,proto3" json:"action,omitempty"`
|
||||
Repo *RepoRef `protobuf:"bytes,2,opt,name=repo,proto3" json:"repo,omitempty"`
|
||||
PrNumber int32 `protobuf:"varint,3,opt,name=pr_number,json=prNumber,proto3" json:"pr_number,omitempty"`
|
||||
ReviewId int64 `protobuf:"varint,4,opt,name=review_id,json=reviewId,proto3" json:"review_id,omitempty"`
|
||||
Author string `protobuf:"bytes,5,opt,name=author,proto3" json:"author,omitempty"`
|
||||
State string `protobuf:"bytes,6,opt,name=state,proto3" json:"state,omitempty"`
|
||||
Body string `protobuf:"bytes,7,opt,name=body,proto3" json:"body,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *ReviewEvent) Reset() {
|
||||
*x = ReviewEvent{}
|
||||
mi := &file_forge_v1_forge_proto_msgTypes[56]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *ReviewEvent) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*ReviewEvent) ProtoMessage() {}
|
||||
|
||||
func (x *ReviewEvent) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_forge_v1_forge_proto_msgTypes[56]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use ReviewEvent.ProtoReflect.Descriptor instead.
|
||||
func (*ReviewEvent) Descriptor() ([]byte, []int) {
|
||||
return file_forge_v1_forge_proto_rawDescGZIP(), []int{56}
|
||||
}
|
||||
|
||||
func (x *ReviewEvent) GetAction() string {
|
||||
if x != nil {
|
||||
return x.Action
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *ReviewEvent) GetRepo() *RepoRef {
|
||||
if x != nil {
|
||||
return x.Repo
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *ReviewEvent) GetPrNumber() int32 {
|
||||
if x != nil {
|
||||
return x.PrNumber
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ReviewEvent) GetReviewId() int64 {
|
||||
if x != nil {
|
||||
return x.ReviewId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ReviewEvent) GetAuthor() string {
|
||||
if x != nil {
|
||||
return x.Author
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *ReviewEvent) GetState() string {
|
||||
if x != nil {
|
||||
return x.State
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *ReviewEvent) GetBody() string {
|
||||
if x != nil {
|
||||
return x.Body
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type ReviewCommentEvent struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Action string `protobuf:"bytes,1,opt,name=action,proto3" json:"action,omitempty"`
|
||||
Repo *RepoRef `protobuf:"bytes,2,opt,name=repo,proto3" json:"repo,omitempty"`
|
||||
PrNumber int32 `protobuf:"varint,3,opt,name=pr_number,json=prNumber,proto3" json:"pr_number,omitempty"`
|
||||
ReviewId int64 `protobuf:"varint,4,opt,name=review_id,json=reviewId,proto3" json:"review_id,omitempty"`
|
||||
CommentId int64 `protobuf:"varint,5,opt,name=comment_id,json=commentId,proto3" json:"comment_id,omitempty"`
|
||||
Author string `protobuf:"bytes,6,opt,name=author,proto3" json:"author,omitempty"`
|
||||
Body string `protobuf:"bytes,7,opt,name=body,proto3" json:"body,omitempty"`
|
||||
Path string `protobuf:"bytes,8,opt,name=path,proto3" json:"path,omitempty"`
|
||||
Line int32 `protobuf:"varint,9,opt,name=line,proto3" json:"line,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *ReviewCommentEvent) Reset() {
|
||||
*x = ReviewCommentEvent{}
|
||||
mi := &file_forge_v1_forge_proto_msgTypes[57]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *ReviewCommentEvent) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*ReviewCommentEvent) ProtoMessage() {}
|
||||
|
||||
func (x *ReviewCommentEvent) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_forge_v1_forge_proto_msgTypes[57]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use ReviewCommentEvent.ProtoReflect.Descriptor instead.
|
||||
func (*ReviewCommentEvent) Descriptor() ([]byte, []int) {
|
||||
return file_forge_v1_forge_proto_rawDescGZIP(), []int{57}
|
||||
}
|
||||
|
||||
func (x *ReviewCommentEvent) GetAction() string {
|
||||
if x != nil {
|
||||
return x.Action
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *ReviewCommentEvent) GetRepo() *RepoRef {
|
||||
if x != nil {
|
||||
return x.Repo
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *ReviewCommentEvent) GetPrNumber() int32 {
|
||||
if x != nil {
|
||||
return x.PrNumber
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ReviewCommentEvent) GetReviewId() int64 {
|
||||
if x != nil {
|
||||
return x.ReviewId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ReviewCommentEvent) GetCommentId() int64 {
|
||||
if x != nil {
|
||||
return x.CommentId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ReviewCommentEvent) GetAuthor() string {
|
||||
if x != nil {
|
||||
return x.Author
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *ReviewCommentEvent) GetBody() string {
|
||||
if x != nil {
|
||||
return x.Body
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *ReviewCommentEvent) GetPath() string {
|
||||
if x != nil {
|
||||
return x.Path
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *ReviewCommentEvent) GetLine() int32 {
|
||||
if x != nil {
|
||||
return x.Line
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
var File_forge_v1_forge_proto protoreflect.FileDescriptor
|
||||
|
||||
const file_forge_v1_forge_proto_rawDesc = "" +
|
||||
@@ -3434,48 +2976,7 @@ const file_forge_v1_forge_proto_rawDesc = "" +
|
||||
"\x04repo\x18\x01 \x01(\v2\x11.forge.v1.RepoRefR\x04repo\x12\x10\n" +
|
||||
"\x03ref\x18\x02 \x01(\tR\x03ref\",\n" +
|
||||
"\x16GetRepoArchiveResponse\x12\x12\n" +
|
||||
"\x04data\x18\x01 \x01(\fR\x04data\"\xab\x01\n" +
|
||||
"\x13ParseWebhookRequest\x12D\n" +
|
||||
"\aheaders\x18\x01 \x03(\v2*.forge.v1.ParseWebhookRequest.HeadersEntryR\aheaders\x12\x12\n" +
|
||||
"\x04body\x18\x02 \x01(\fR\x04body\x1a:\n" +
|
||||
"\fHeadersEntry\x12\x10\n" +
|
||||
"\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" +
|
||||
"\x05value\x18\x02 \x01(\tR\x05value:\x028\x01\"\xc5\x01\n" +
|
||||
"\x14ParseWebhookResponse\x12,\n" +
|
||||
"\x05issue\x18\x01 \x01(\v2\x14.forge.v1.IssueEventH\x00R\x05issue\x12/\n" +
|
||||
"\x06review\x18\x02 \x01(\v2\x15.forge.v1.ReviewEventH\x00R\x06review\x12E\n" +
|
||||
"\x0ereview_comment\x18\x03 \x01(\v2\x1c.forge.v1.ReviewCommentEventH\x00R\rreviewCommentB\a\n" +
|
||||
"\x05event\"\x81\x02\n" +
|
||||
"\n" +
|
||||
"IssueEvent\x12\x16\n" +
|
||||
"\x06action\x18\x01 \x01(\tR\x06action\x12\x14\n" +
|
||||
"\x05state\x18\x02 \x01(\tR\x05state\x12&\n" +
|
||||
"\x0fis_pull_request\x18\x03 \x01(\bR\risPullRequest\x12%\n" +
|
||||
"\x04repo\x18\x04 \x01(\v2\x11.forge.v1.RepoRefR\x04repo\x12\x16\n" +
|
||||
"\x06number\x18\x05 \x01(\x05R\x06number\x12\x14\n" +
|
||||
"\x05title\x18\x06 \x01(\tR\x05title\x12\x12\n" +
|
||||
"\x04body\x18\a \x01(\tR\x04body\x12\x16\n" +
|
||||
"\x06labels\x18\b \x03(\tR\x06labels\x12\x1c\n" +
|
||||
"\tassignees\x18\t \x03(\tR\tassignees\"\xc8\x01\n" +
|
||||
"\vReviewEvent\x12\x16\n" +
|
||||
"\x06action\x18\x01 \x01(\tR\x06action\x12%\n" +
|
||||
"\x04repo\x18\x02 \x01(\v2\x11.forge.v1.RepoRefR\x04repo\x12\x1b\n" +
|
||||
"\tpr_number\x18\x03 \x01(\x05R\bprNumber\x12\x1b\n" +
|
||||
"\treview_id\x18\x04 \x01(\x03R\breviewId\x12\x16\n" +
|
||||
"\x06author\x18\x05 \x01(\tR\x06author\x12\x14\n" +
|
||||
"\x05state\x18\x06 \x01(\tR\x05state\x12\x12\n" +
|
||||
"\x04body\x18\a \x01(\tR\x04body\"\x80\x02\n" +
|
||||
"\x12ReviewCommentEvent\x12\x16\n" +
|
||||
"\x06action\x18\x01 \x01(\tR\x06action\x12%\n" +
|
||||
"\x04repo\x18\x02 \x01(\v2\x11.forge.v1.RepoRefR\x04repo\x12\x1b\n" +
|
||||
"\tpr_number\x18\x03 \x01(\x05R\bprNumber\x12\x1b\n" +
|
||||
"\treview_id\x18\x04 \x01(\x03R\breviewId\x12\x1d\n" +
|
||||
"\n" +
|
||||
"comment_id\x18\x05 \x01(\x03R\tcommentId\x12\x16\n" +
|
||||
"\x06author\x18\x06 \x01(\tR\x06author\x12\x12\n" +
|
||||
"\x04body\x18\a \x01(\tR\x04body\x12\x12\n" +
|
||||
"\x04path\x18\b \x01(\tR\x04path\x12\x12\n" +
|
||||
"\x04line\x18\t \x01(\x05R\x04line2\xe9\x0e\n" +
|
||||
"\x04data\x18\x01 \x01(\fR\x04data2\x9a\x0e\n" +
|
||||
"\fForgeService\x12D\n" +
|
||||
"\tConfigure\x12\x1a.forge.v1.ConfigureRequest\x1a\x1b.forge.v1.ConfigureResponse\x12S\n" +
|
||||
"\x0eAssignedIssues\x12\x1f.forge.v1.AssignedIssuesRequest\x1a .forge.v1.AssignedIssuesResponse\x12V\n" +
|
||||
@@ -3501,8 +3002,7 @@ const file_forge_v1_forge_proto_rawDesc = "" +
|
||||
"VerifyPush\x12\x1b.forge.v1.VerifyPushRequest\x1a\x1c.forge.v1.VerifyPushResponse\x12G\n" +
|
||||
"\n" +
|
||||
"LinkBranch\x12\x1b.forge.v1.LinkBranchRequest\x1a\x1c.forge.v1.LinkBranchResponse\x12P\n" +
|
||||
"\rGitCredential\x12\x1e.forge.v1.GitCredentialRequest\x1a\x1f.forge.v1.GitCredentialResponse\x12M\n" +
|
||||
"\fParseWebhook\x12\x1d.forge.v1.ParseWebhookRequest\x1a\x1e.forge.v1.ParseWebhookResponse\x12U\n" +
|
||||
"\rGitCredential\x12\x1e.forge.v1.GitCredentialRequest\x1a\x1f.forge.v1.GitCredentialResponse\x12U\n" +
|
||||
"\x0eGetRepoArchive\x12\x1f.forge.v1.GetRepoArchiveRequest\x1a .forge.v1.GetRepoArchiveResponse0\x01B\xa4\x01\n" +
|
||||
"\fcom.forge.v1B\n" +
|
||||
"ForgeProtoP\x01ZGgithub.com/samcharles93/archie-core/internal/contracts/forge/v1;forgev1\xa2\x02\x03FXX\xaa\x02\bForge.V1\xca\x02\bForge\\V1\xe2\x02\x14Forge\\V1\\GPBMetadata\xea\x02\tForge::V1b\x06proto3"
|
||||
@@ -3519,7 +3019,7 @@ func file_forge_v1_forge_proto_rawDescGZIP() []byte {
|
||||
return file_forge_v1_forge_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_forge_v1_forge_proto_msgTypes = make([]protoimpl.MessageInfo, 60)
|
||||
var file_forge_v1_forge_proto_msgTypes = make([]protoimpl.MessageInfo, 54)
|
||||
var file_forge_v1_forge_proto_goTypes = []any{
|
||||
(*ConfigureRequest)(nil), // 0: forge.v1.ConfigureRequest
|
||||
(*ConfigureResponse)(nil), // 1: forge.v1.ConfigureResponse
|
||||
@@ -3574,17 +3074,11 @@ var file_forge_v1_forge_proto_goTypes = []any{
|
||||
(*GitCredentialResponse)(nil), // 50: forge.v1.GitCredentialResponse
|
||||
(*GetRepoArchiveRequest)(nil), // 51: forge.v1.GetRepoArchiveRequest
|
||||
(*GetRepoArchiveResponse)(nil), // 52: forge.v1.GetRepoArchiveResponse
|
||||
(*ParseWebhookRequest)(nil), // 53: forge.v1.ParseWebhookRequest
|
||||
(*ParseWebhookResponse)(nil), // 54: forge.v1.ParseWebhookResponse
|
||||
(*IssueEvent)(nil), // 55: forge.v1.IssueEvent
|
||||
(*ReviewEvent)(nil), // 56: forge.v1.ReviewEvent
|
||||
(*ReviewCommentEvent)(nil), // 57: forge.v1.ReviewCommentEvent
|
||||
nil, // 58: forge.v1.ConfigureRequest.SettingsEntry
|
||||
nil, // 59: forge.v1.ParseWebhookRequest.HeadersEntry
|
||||
(*timestamppb.Timestamp)(nil), // 60: google.protobuf.Timestamp
|
||||
nil, // 53: forge.v1.ConfigureRequest.SettingsEntry
|
||||
(*timestamppb.Timestamp)(nil), // 54: google.protobuf.Timestamp
|
||||
}
|
||||
var file_forge_v1_forge_proto_depIdxs = []int32{
|
||||
58, // 0: forge.v1.ConfigureRequest.settings:type_name -> forge.v1.ConfigureRequest.SettingsEntry
|
||||
53, // 0: forge.v1.ConfigureRequest.settings:type_name -> forge.v1.ConfigureRequest.SettingsEntry
|
||||
2, // 1: forge.v1.PullRequestRef.repo:type_name -> forge.v1.RepoRef
|
||||
4, // 2: forge.v1.AssignedIssuesResponse.issues:type_name -> forge.v1.Issue
|
||||
4, // 3: forge.v1.IssuesWithLabelResponse.issues:type_name -> forge.v1.Issue
|
||||
@@ -3603,9 +3097,9 @@ var file_forge_v1_forge_proto_depIdxs = []int32{
|
||||
27, // 16: forge.v1.GetPullRequestResponse.pull_request:type_name -> forge.v1.PullRequest
|
||||
2, // 17: forge.v1.GetPullRequestDiffRequest.repo:type_name -> forge.v1.RepoRef
|
||||
3, // 18: forge.v1.ListReviewsRequest.pull_request:type_name -> forge.v1.PullRequestRef
|
||||
60, // 19: forge.v1.Review.submitted_at:type_name -> google.protobuf.Timestamp
|
||||
54, // 19: forge.v1.Review.submitted_at:type_name -> google.protobuf.Timestamp
|
||||
33, // 20: forge.v1.ListReviewsResponse.reviews:type_name -> forge.v1.Review
|
||||
60, // 21: forge.v1.ReviewComment.created_at:type_name -> google.protobuf.Timestamp
|
||||
54, // 21: forge.v1.ReviewComment.created_at:type_name -> google.protobuf.Timestamp
|
||||
3, // 22: forge.v1.ListReviewCommentsRequest.pull_request:type_name -> forge.v1.PullRequestRef
|
||||
35, // 23: forge.v1.ListReviewCommentsResponse.comments:type_name -> forge.v1.ReviewComment
|
||||
3, // 24: forge.v1.ReplyToReviewRequest.pull_request:type_name -> forge.v1.PullRequestRef
|
||||
@@ -3615,68 +3109,59 @@ var file_forge_v1_forge_proto_depIdxs = []int32{
|
||||
2, // 28: forge.v1.AcceptInvitationsRequest.repositories:type_name -> forge.v1.RepoRef
|
||||
2, // 29: forge.v1.VerifyPushRequest.repo:type_name -> forge.v1.RepoRef
|
||||
2, // 30: forge.v1.GitCredentialRequest.repo:type_name -> forge.v1.RepoRef
|
||||
60, // 31: forge.v1.GitCredentialResponse.expires_at:type_name -> google.protobuf.Timestamp
|
||||
54, // 31: forge.v1.GitCredentialResponse.expires_at:type_name -> google.protobuf.Timestamp
|
||||
2, // 32: forge.v1.GetRepoArchiveRequest.repo:type_name -> forge.v1.RepoRef
|
||||
59, // 33: forge.v1.ParseWebhookRequest.headers:type_name -> forge.v1.ParseWebhookRequest.HeadersEntry
|
||||
55, // 34: forge.v1.ParseWebhookResponse.issue:type_name -> forge.v1.IssueEvent
|
||||
56, // 35: forge.v1.ParseWebhookResponse.review:type_name -> forge.v1.ReviewEvent
|
||||
57, // 36: forge.v1.ParseWebhookResponse.review_comment:type_name -> forge.v1.ReviewCommentEvent
|
||||
2, // 37: forge.v1.IssueEvent.repo:type_name -> forge.v1.RepoRef
|
||||
2, // 38: forge.v1.ReviewEvent.repo:type_name -> forge.v1.RepoRef
|
||||
2, // 39: forge.v1.ReviewCommentEvent.repo:type_name -> forge.v1.RepoRef
|
||||
0, // 40: forge.v1.ForgeService.Configure:input_type -> forge.v1.ConfigureRequest
|
||||
7, // 41: forge.v1.ForgeService.AssignedIssues:input_type -> forge.v1.AssignedIssuesRequest
|
||||
8, // 42: forge.v1.ForgeService.IssuesWithLabel:input_type -> forge.v1.IssuesWithLabelRequest
|
||||
9, // 43: forge.v1.ForgeService.Comment:input_type -> forge.v1.CommentRequest
|
||||
11, // 44: forge.v1.ForgeService.CreateIssue:input_type -> forge.v1.CreateIssueRequest
|
||||
13, // 45: forge.v1.ForgeService.CloseIssue:input_type -> forge.v1.CloseIssueRequest
|
||||
19, // 46: forge.v1.ForgeService.React:input_type -> forge.v1.ReactRequest
|
||||
21, // 47: forge.v1.ForgeService.SetStateLabel:input_type -> forge.v1.SetStateLabelRequest
|
||||
23, // 48: forge.v1.ForgeService.CreatePR:input_type -> forge.v1.CreatePRRequest
|
||||
25, // 49: forge.v1.ForgeService.PRState:input_type -> forge.v1.PRStateRequest
|
||||
15, // 50: forge.v1.ForgeService.ClosePR:input_type -> forge.v1.ClosePRRequest
|
||||
17, // 51: forge.v1.ForgeService.MergePR:input_type -> forge.v1.MergePRRequest
|
||||
28, // 52: forge.v1.ForgeService.GetPullRequest:input_type -> forge.v1.GetPullRequestRequest
|
||||
30, // 53: forge.v1.ForgeService.GetPullRequestDiff:input_type -> forge.v1.GetPullRequestDiffRequest
|
||||
32, // 54: forge.v1.ForgeService.ListReviews:input_type -> forge.v1.ListReviewsRequest
|
||||
36, // 55: forge.v1.ForgeService.ListReviewComments:input_type -> forge.v1.ListReviewCommentsRequest
|
||||
38, // 56: forge.v1.ForgeService.ReplyToReview:input_type -> forge.v1.ReplyToReviewRequest
|
||||
41, // 57: forge.v1.ForgeService.CreateReviewComments:input_type -> forge.v1.CreateReviewCommentsRequest
|
||||
45, // 58: forge.v1.ForgeService.AcceptInvitations:input_type -> forge.v1.AcceptInvitationsRequest
|
||||
47, // 59: forge.v1.ForgeService.VerifyPush:input_type -> forge.v1.VerifyPushRequest
|
||||
43, // 60: forge.v1.ForgeService.LinkBranch:input_type -> forge.v1.LinkBranchRequest
|
||||
49, // 61: forge.v1.ForgeService.GitCredential:input_type -> forge.v1.GitCredentialRequest
|
||||
53, // 62: forge.v1.ForgeService.ParseWebhook:input_type -> forge.v1.ParseWebhookRequest
|
||||
51, // 63: forge.v1.ForgeService.GetRepoArchive:input_type -> forge.v1.GetRepoArchiveRequest
|
||||
1, // 64: forge.v1.ForgeService.Configure:output_type -> forge.v1.ConfigureResponse
|
||||
5, // 65: forge.v1.ForgeService.AssignedIssues:output_type -> forge.v1.AssignedIssuesResponse
|
||||
6, // 66: forge.v1.ForgeService.IssuesWithLabel:output_type -> forge.v1.IssuesWithLabelResponse
|
||||
10, // 67: forge.v1.ForgeService.Comment:output_type -> forge.v1.CommentResponse
|
||||
12, // 68: forge.v1.ForgeService.CreateIssue:output_type -> forge.v1.CreateIssueResponse
|
||||
14, // 69: forge.v1.ForgeService.CloseIssue:output_type -> forge.v1.CloseIssueResponse
|
||||
20, // 70: forge.v1.ForgeService.React:output_type -> forge.v1.ReactResponse
|
||||
22, // 71: forge.v1.ForgeService.SetStateLabel:output_type -> forge.v1.SetStateLabelResponse
|
||||
24, // 72: forge.v1.ForgeService.CreatePR:output_type -> forge.v1.CreatePRResponse
|
||||
26, // 73: forge.v1.ForgeService.PRState:output_type -> forge.v1.PRStateResponse
|
||||
16, // 74: forge.v1.ForgeService.ClosePR:output_type -> forge.v1.ClosePRResponse
|
||||
18, // 75: forge.v1.ForgeService.MergePR:output_type -> forge.v1.MergePRResponse
|
||||
29, // 76: forge.v1.ForgeService.GetPullRequest:output_type -> forge.v1.GetPullRequestResponse
|
||||
31, // 77: forge.v1.ForgeService.GetPullRequestDiff:output_type -> forge.v1.GetPullRequestDiffResponse
|
||||
34, // 78: forge.v1.ForgeService.ListReviews:output_type -> forge.v1.ListReviewsResponse
|
||||
37, // 79: forge.v1.ForgeService.ListReviewComments:output_type -> forge.v1.ListReviewCommentsResponse
|
||||
39, // 80: forge.v1.ForgeService.ReplyToReview:output_type -> forge.v1.ReplyToReviewResponse
|
||||
42, // 81: forge.v1.ForgeService.CreateReviewComments:output_type -> forge.v1.CreateReviewCommentsResponse
|
||||
46, // 82: forge.v1.ForgeService.AcceptInvitations:output_type -> forge.v1.AcceptInvitationsResponse
|
||||
48, // 83: forge.v1.ForgeService.VerifyPush:output_type -> forge.v1.VerifyPushResponse
|
||||
44, // 84: forge.v1.ForgeService.LinkBranch:output_type -> forge.v1.LinkBranchResponse
|
||||
50, // 85: forge.v1.ForgeService.GitCredential:output_type -> forge.v1.GitCredentialResponse
|
||||
54, // 86: forge.v1.ForgeService.ParseWebhook:output_type -> forge.v1.ParseWebhookResponse
|
||||
52, // 87: forge.v1.ForgeService.GetRepoArchive:output_type -> forge.v1.GetRepoArchiveResponse
|
||||
64, // [64:88] is the sub-list for method output_type
|
||||
40, // [40:64] is the sub-list for method input_type
|
||||
40, // [40:40] is the sub-list for extension type_name
|
||||
40, // [40:40] is the sub-list for extension extendee
|
||||
0, // [0:40] is the sub-list for field type_name
|
||||
0, // 33: forge.v1.ForgeService.Configure:input_type -> forge.v1.ConfigureRequest
|
||||
7, // 34: forge.v1.ForgeService.AssignedIssues:input_type -> forge.v1.AssignedIssuesRequest
|
||||
8, // 35: forge.v1.ForgeService.IssuesWithLabel:input_type -> forge.v1.IssuesWithLabelRequest
|
||||
9, // 36: forge.v1.ForgeService.Comment:input_type -> forge.v1.CommentRequest
|
||||
11, // 37: forge.v1.ForgeService.CreateIssue:input_type -> forge.v1.CreateIssueRequest
|
||||
13, // 38: forge.v1.ForgeService.CloseIssue:input_type -> forge.v1.CloseIssueRequest
|
||||
19, // 39: forge.v1.ForgeService.React:input_type -> forge.v1.ReactRequest
|
||||
21, // 40: forge.v1.ForgeService.SetStateLabel:input_type -> forge.v1.SetStateLabelRequest
|
||||
23, // 41: forge.v1.ForgeService.CreatePR:input_type -> forge.v1.CreatePRRequest
|
||||
25, // 42: forge.v1.ForgeService.PRState:input_type -> forge.v1.PRStateRequest
|
||||
15, // 43: forge.v1.ForgeService.ClosePR:input_type -> forge.v1.ClosePRRequest
|
||||
17, // 44: forge.v1.ForgeService.MergePR:input_type -> forge.v1.MergePRRequest
|
||||
28, // 45: forge.v1.ForgeService.GetPullRequest:input_type -> forge.v1.GetPullRequestRequest
|
||||
30, // 46: forge.v1.ForgeService.GetPullRequestDiff:input_type -> forge.v1.GetPullRequestDiffRequest
|
||||
32, // 47: forge.v1.ForgeService.ListReviews:input_type -> forge.v1.ListReviewsRequest
|
||||
36, // 48: forge.v1.ForgeService.ListReviewComments:input_type -> forge.v1.ListReviewCommentsRequest
|
||||
38, // 49: forge.v1.ForgeService.ReplyToReview:input_type -> forge.v1.ReplyToReviewRequest
|
||||
41, // 50: forge.v1.ForgeService.CreateReviewComments:input_type -> forge.v1.CreateReviewCommentsRequest
|
||||
45, // 51: forge.v1.ForgeService.AcceptInvitations:input_type -> forge.v1.AcceptInvitationsRequest
|
||||
47, // 52: forge.v1.ForgeService.VerifyPush:input_type -> forge.v1.VerifyPushRequest
|
||||
43, // 53: forge.v1.ForgeService.LinkBranch:input_type -> forge.v1.LinkBranchRequest
|
||||
49, // 54: forge.v1.ForgeService.GitCredential:input_type -> forge.v1.GitCredentialRequest
|
||||
51, // 55: forge.v1.ForgeService.GetRepoArchive:input_type -> forge.v1.GetRepoArchiveRequest
|
||||
1, // 56: forge.v1.ForgeService.Configure:output_type -> forge.v1.ConfigureResponse
|
||||
5, // 57: forge.v1.ForgeService.AssignedIssues:output_type -> forge.v1.AssignedIssuesResponse
|
||||
6, // 58: forge.v1.ForgeService.IssuesWithLabel:output_type -> forge.v1.IssuesWithLabelResponse
|
||||
10, // 59: forge.v1.ForgeService.Comment:output_type -> forge.v1.CommentResponse
|
||||
12, // 60: forge.v1.ForgeService.CreateIssue:output_type -> forge.v1.CreateIssueResponse
|
||||
14, // 61: forge.v1.ForgeService.CloseIssue:output_type -> forge.v1.CloseIssueResponse
|
||||
20, // 62: forge.v1.ForgeService.React:output_type -> forge.v1.ReactResponse
|
||||
22, // 63: forge.v1.ForgeService.SetStateLabel:output_type -> forge.v1.SetStateLabelResponse
|
||||
24, // 64: forge.v1.ForgeService.CreatePR:output_type -> forge.v1.CreatePRResponse
|
||||
26, // 65: forge.v1.ForgeService.PRState:output_type -> forge.v1.PRStateResponse
|
||||
16, // 66: forge.v1.ForgeService.ClosePR:output_type -> forge.v1.ClosePRResponse
|
||||
18, // 67: forge.v1.ForgeService.MergePR:output_type -> forge.v1.MergePRResponse
|
||||
29, // 68: forge.v1.ForgeService.GetPullRequest:output_type -> forge.v1.GetPullRequestResponse
|
||||
31, // 69: forge.v1.ForgeService.GetPullRequestDiff:output_type -> forge.v1.GetPullRequestDiffResponse
|
||||
34, // 70: forge.v1.ForgeService.ListReviews:output_type -> forge.v1.ListReviewsResponse
|
||||
37, // 71: forge.v1.ForgeService.ListReviewComments:output_type -> forge.v1.ListReviewCommentsResponse
|
||||
39, // 72: forge.v1.ForgeService.ReplyToReview:output_type -> forge.v1.ReplyToReviewResponse
|
||||
42, // 73: forge.v1.ForgeService.CreateReviewComments:output_type -> forge.v1.CreateReviewCommentsResponse
|
||||
46, // 74: forge.v1.ForgeService.AcceptInvitations:output_type -> forge.v1.AcceptInvitationsResponse
|
||||
48, // 75: forge.v1.ForgeService.VerifyPush:output_type -> forge.v1.VerifyPushResponse
|
||||
44, // 76: forge.v1.ForgeService.LinkBranch:output_type -> forge.v1.LinkBranchResponse
|
||||
50, // 77: forge.v1.ForgeService.GitCredential:output_type -> forge.v1.GitCredentialResponse
|
||||
52, // 78: forge.v1.ForgeService.GetRepoArchive:output_type -> forge.v1.GetRepoArchiveResponse
|
||||
56, // [56:79] is the sub-list for method output_type
|
||||
33, // [33:56] is the sub-list for method input_type
|
||||
33, // [33:33] is the sub-list for extension type_name
|
||||
33, // [33:33] is the sub-list for extension extendee
|
||||
0, // [0:33] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_forge_v1_forge_proto_init() }
|
||||
@@ -3684,18 +3169,13 @@ func file_forge_v1_forge_proto_init() {
|
||||
if File_forge_v1_forge_proto != nil {
|
||||
return
|
||||
}
|
||||
file_forge_v1_forge_proto_msgTypes[54].OneofWrappers = []any{
|
||||
(*ParseWebhookResponse_Issue)(nil),
|
||||
(*ParseWebhookResponse_Review)(nil),
|
||||
(*ParseWebhookResponse_ReviewComment)(nil),
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: unsafe.Slice(unsafe.StringData(file_forge_v1_forge_proto_rawDesc), len(file_forge_v1_forge_proto_rawDesc)),
|
||||
NumEnums: 0,
|
||||
NumMessages: 60,
|
||||
NumMessages: 54,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
|
||||
@@ -41,7 +41,6 @@ const (
|
||||
ForgeService_VerifyPush_FullMethodName = "/forge.v1.ForgeService/VerifyPush"
|
||||
ForgeService_LinkBranch_FullMethodName = "/forge.v1.ForgeService/LinkBranch"
|
||||
ForgeService_GitCredential_FullMethodName = "/forge.v1.ForgeService/GitCredential"
|
||||
ForgeService_ParseWebhook_FullMethodName = "/forge.v1.ForgeService/ParseWebhook"
|
||||
ForgeService_GetRepoArchive_FullMethodName = "/forge.v1.ForgeService/GetRepoArchive"
|
||||
)
|
||||
|
||||
@@ -83,10 +82,6 @@ type ForgeServiceClient interface {
|
||||
// repository, and the identity commits through it should carry. A forge that
|
||||
// authenticates git with its configured token answers UNIMPLEMENTED.
|
||||
GitCredential(ctx context.Context, in *GitCredentialRequest, opts ...grpc.CallOption) (*GitCredentialResponse, error)
|
||||
// ParseWebhook decodes one webhook delivery the host has already
|
||||
// authenticated. A delivery that is not an event the host acts on returns no
|
||||
// event; an undecodable body is INVALID_ARGUMENT.
|
||||
ParseWebhook(ctx context.Context, in *ParseWebhookRequest, opts ...grpc.CallOption) (*ParseWebhookResponse, error)
|
||||
// GetRepoArchive streams a gzipped tar of the repository at a ref.
|
||||
GetRepoArchive(ctx context.Context, in *GetRepoArchiveRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[GetRepoArchiveResponse], error)
|
||||
}
|
||||
@@ -319,16 +314,6 @@ func (c *forgeServiceClient) GitCredential(ctx context.Context, in *GitCredentia
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *forgeServiceClient) ParseWebhook(ctx context.Context, in *ParseWebhookRequest, opts ...grpc.CallOption) (*ParseWebhookResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(ParseWebhookResponse)
|
||||
err := c.cc.Invoke(ctx, ForgeService_ParseWebhook_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *forgeServiceClient) GetRepoArchive(ctx context.Context, in *GetRepoArchiveRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[GetRepoArchiveResponse], error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
stream, err := c.cc.NewStream(ctx, &ForgeService_ServiceDesc.Streams[0], ForgeService_GetRepoArchive_FullMethodName, cOpts...)
|
||||
@@ -386,10 +371,6 @@ type ForgeServiceServer interface {
|
||||
// repository, and the identity commits through it should carry. A forge that
|
||||
// authenticates git with its configured token answers UNIMPLEMENTED.
|
||||
GitCredential(context.Context, *GitCredentialRequest) (*GitCredentialResponse, error)
|
||||
// ParseWebhook decodes one webhook delivery the host has already
|
||||
// authenticated. A delivery that is not an event the host acts on returns no
|
||||
// event; an undecodable body is INVALID_ARGUMENT.
|
||||
ParseWebhook(context.Context, *ParseWebhookRequest) (*ParseWebhookResponse, error)
|
||||
// GetRepoArchive streams a gzipped tar of the repository at a ref.
|
||||
GetRepoArchive(*GetRepoArchiveRequest, grpc.ServerStreamingServer[GetRepoArchiveResponse]) error
|
||||
mustEmbedUnimplementedForgeServiceServer()
|
||||
@@ -468,9 +449,6 @@ func (UnimplementedForgeServiceServer) LinkBranch(context.Context, *LinkBranchRe
|
||||
func (UnimplementedForgeServiceServer) GitCredential(context.Context, *GitCredentialRequest) (*GitCredentialResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method GitCredential not implemented")
|
||||
}
|
||||
func (UnimplementedForgeServiceServer) ParseWebhook(context.Context, *ParseWebhookRequest) (*ParseWebhookResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method ParseWebhook not implemented")
|
||||
}
|
||||
func (UnimplementedForgeServiceServer) GetRepoArchive(*GetRepoArchiveRequest, grpc.ServerStreamingServer[GetRepoArchiveResponse]) error {
|
||||
return status.Error(codes.Unimplemented, "method GetRepoArchive not implemented")
|
||||
}
|
||||
@@ -891,24 +869,6 @@ func _ForgeService_GitCredential_Handler(srv interface{}, ctx context.Context, d
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _ForgeService_ParseWebhook_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ParseWebhookRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ForgeServiceServer).ParseWebhook(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: ForgeService_ParseWebhook_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ForgeServiceServer).ParseWebhook(ctx, req.(*ParseWebhookRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _ForgeService_GetRepoArchive_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||
m := new(GetRepoArchiveRequest)
|
||||
if err := stream.RecvMsg(m); err != nil {
|
||||
@@ -1015,10 +975,6 @@ var ForgeService_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "GitCredential",
|
||||
Handler: _ForgeService_GitCredential_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ParseWebhook",
|
||||
Handler: _ForgeService_ParseWebhook_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{
|
||||
{
|
||||
|
||||
@@ -411,15 +411,8 @@ func (d *Daemon) drainLoop(ctx context.Context) {
|
||||
// work, using the given forge client and dispatch config. complete is false when any part of the poll failed or was skipped, so
|
||||
// the result must not be read as the whole eligible set.
|
||||
func (d *Daemon) pollIssuesWithConfig(ctx context.Context, fg forge.Forge, cfg config.Config, repo config.Repo) (issues []forge.Issue, complete bool) {
|
||||
// Webhook intake hears about issues as they change; polling as well would
|
||||
// spend forge API quota to find the same work. The receiver runs from the
|
||||
// root forge settings, so their mode decides for every identity.
|
||||
if d.Cfg.Get().Forge.Intake == config.ForgeIntakeWebhook {
|
||||
return nil, false
|
||||
}
|
||||
labelled := func() ([]forge.Issue, bool) {
|
||||
// Empty-label rule shared with workintake.MatchesDispatch: a label
|
||||
// trigger needs a non-empty label or it would match every open issue.
|
||||
// A label trigger needs a non-empty label or it would match every open issue.
|
||||
if cfg.Label == "" {
|
||||
d.Log.ErrorContext(ctx, "label trigger configured with an empty label; refusing to poll (an empty label matches every open issue)", "repo", repo.FullName())
|
||||
return nil, false
|
||||
@@ -1295,10 +1288,6 @@ func (d *taskDispatcher) Wait() {
|
||||
// afresh each cycle so a rotated credential or a new connection applies to
|
||||
// the next poll.
|
||||
func (d *Daemon) poll(ctx context.Context) error {
|
||||
// Webhook intake replaces polling; an empty pass is not a failure.
|
||||
if d.Cfg.Get().Forge.Intake == config.ForgeIntakeWebhook {
|
||||
return nil
|
||||
}
|
||||
var failed []string
|
||||
room := d.Cfg.Get().IntakePerPass
|
||||
for _, source := range d.issueSources(ctx) {
|
||||
|
||||
@@ -1,41 +1,7 @@
|
||||
package workintake
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// RequiresLabel reports whether the dispatch trigger matches on a label and
|
||||
// therefore needs a non-empty label to be meaningful.
|
||||
func RequiresLabel(trigger string) bool {
|
||||
return trigger == "label" || trigger == "either"
|
||||
}
|
||||
|
||||
// MatchesDispatch reports whether an issue is eligible work under the dispatch
|
||||
// trigger. labels and assignees are the issue's current labels and assignee
|
||||
// logins. An empty label never matches, even when the trigger is "label":
|
||||
// a missing label must not be mistaken for "every issue" (3209a1f).
|
||||
func MatchesDispatch(trigger, label, botUser string, labels, assignees []string) bool {
|
||||
switch trigger {
|
||||
case "label":
|
||||
return label != "" && containsLabel(labels, label)
|
||||
case "either":
|
||||
return containsAssignee(assignees, botUser) || (label != "" && containsLabel(labels, label))
|
||||
default: // "assignee"
|
||||
return containsAssignee(assignees, botUser)
|
||||
}
|
||||
}
|
||||
|
||||
// containsLabel matches label names exactly: GitHub label names are
|
||||
// case-sensitive and "Bug" and "bug" can coexist as distinct labels, matching
|
||||
// IssuesWithLabel's exact-match server-side filter.
|
||||
func containsLabel(labels []string, needle string) bool {
|
||||
return slices.Contains(labels, needle)
|
||||
}
|
||||
|
||||
// containsAssignee matches logins case-insensitively.
|
||||
func containsAssignee(assignees []string, botUser string) bool {
|
||||
return slices.ContainsFunc(assignees, func(a string) bool {
|
||||
return strings.EqualFold(a, botUser)
|
||||
})
|
||||
}
|
||||
@@ -5,7 +5,6 @@ package forge
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"time"
|
||||
)
|
||||
@@ -198,59 +197,6 @@ type ReviewCommentWriter interface {
|
||||
CreateReviewComments(ctx context.Context, owner, repo string, number int, reviewedHeadSHA string, review ReviewSubmission) error
|
||||
}
|
||||
|
||||
// WebhookEvent is one decoded webhook delivery. At most one field is set; none
|
||||
// means a delivery the host does not act on.
|
||||
type WebhookEvent struct {
|
||||
Issue *IssueEvent
|
||||
Review *ReviewEvent
|
||||
ReviewComment *ReviewCommentEvent
|
||||
}
|
||||
|
||||
// IssueEvent is an issue webhook, carrying what eligibility needs.
|
||||
type IssueEvent struct {
|
||||
Action string
|
||||
State string
|
||||
PullRequest bool
|
||||
Owner, Repo string
|
||||
Number int
|
||||
Title, Body string
|
||||
Labels []string
|
||||
Assignees []string
|
||||
}
|
||||
|
||||
// ReviewEvent is a submitted pull request review.
|
||||
type ReviewEvent struct {
|
||||
Action string
|
||||
Owner, Repo string
|
||||
PRNumber int
|
||||
ReviewID int64
|
||||
Author string
|
||||
State string
|
||||
Body string
|
||||
}
|
||||
|
||||
// ReviewCommentEvent is an inline pull request review comment.
|
||||
type ReviewCommentEvent struct {
|
||||
Action string
|
||||
Owner, Repo string
|
||||
PRNumber int
|
||||
ReviewID int64
|
||||
CommentID int64
|
||||
Author string
|
||||
Body string
|
||||
Path string
|
||||
Line int
|
||||
}
|
||||
|
||||
// ErrBadWebhook marks a delivery body the forge could not decode.
|
||||
var ErrBadWebhook = errors.New("undecodable webhook payload")
|
||||
|
||||
// WebhookParser decodes webhook deliveries. Callers verify the delivery's
|
||||
// signature first; implementations parse only what is authenticated.
|
||||
type WebhookParser interface {
|
||||
ParseWebhook(ctx context.Context, headers map[string]string, body []byte) (WebhookEvent, error)
|
||||
}
|
||||
|
||||
// GitCredential is a short-lived git credential for one repository and the
|
||||
// identity commits through it carry.
|
||||
type GitCredential struct {
|
||||
|
||||
@@ -1,386 +0,0 @@
|
||||
// Package webhook receives forge issue and review webhooks, verifies their
|
||||
// HMAC, has the forge's parser decode them and publishes them through the
|
||||
// poller's publish path. Only
|
||||
// application/json payloads are accepted. A GET returns delivery Status.
|
||||
package webhook
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/workintake"
|
||||
"github.com/samcharles93/archie-core/internal/forge"
|
||||
"github.com/samcharles93/archie-core/internal/webhookguard"
|
||||
)
|
||||
|
||||
// maxBodyBytes bounds a webhook payload before it is read. GitHub webhook
|
||||
// bodies are small; the cap exists so a hostile sender cannot exhaust memory.
|
||||
const maxBodyBytes = 1 << 20 // 1 MiB
|
||||
|
||||
// PublishFunc delivers a decoded, dispatch-matched task envelope to the
|
||||
// daemon's publish path. The composition root wires it to
|
||||
// (*daemon.Daemon).PublishTask, the same enqueue path the poller uses.
|
||||
type PublishFunc func(ctx context.Context, task workintake.TaskEnvelope) error
|
||||
|
||||
// WithdrawFunc declines the work an issue no longer asks for.
|
||||
type WithdrawFunc func(ctx context.Context, owner, repo string, number int, reason string) error
|
||||
|
||||
// ReactionPublishFunc publishes one review reaction.
|
||||
type ReactionPublishFunc func(ctx context.Context, reaction workintake.ReviewCommentEnvelope) error
|
||||
|
||||
// reactionRateLimit bounds reaction deliveries per remote source per window
|
||||
// (decision 6's per-source rate limiting, due now that the receiver carries a
|
||||
// second event family). It guards spend, not authorization: the owned-task
|
||||
// guard at the consumer remains the authorization boundary.
|
||||
const (
|
||||
reactionRateLimit = 60
|
||||
reactionRateWindow = time.Minute
|
||||
reactionRateBucketTTL = 5 * time.Minute
|
||||
)
|
||||
|
||||
// Receiver is the HTTP handler for forge webhooks. It verifies the signature,
|
||||
// decodes the event, applies the shared dispatch predicate, and publishes
|
||||
// matched issues.
|
||||
type Receiver struct {
|
||||
secret string
|
||||
parser forge.WebhookParser
|
||||
trigger string
|
||||
label string
|
||||
botUser string
|
||||
publish PublishFunc
|
||||
reactionPublish ReactionPublishFunc
|
||||
withdraw WithdrawFunc
|
||||
log *slog.Logger
|
||||
|
||||
mu sync.Mutex
|
||||
startedAt time.Time
|
||||
lastReceivedAt time.Time
|
||||
deliveries uint64
|
||||
publishes uint64
|
||||
reactionPublishes uint64
|
||||
|
||||
reactionLimiter map[string]*reactionWindow
|
||||
}
|
||||
|
||||
// reactionWindow is one remote's fixed-window rate budget.
|
||||
type reactionWindow struct {
|
||||
start time.Time
|
||||
count int
|
||||
}
|
||||
|
||||
// New returns an unstarted Receiver.
|
||||
func New(secret string, parser forge.WebhookParser, trigger, label, botUser string, publish PublishFunc, reactionPublish ReactionPublishFunc, withdraw WithdrawFunc, log *slog.Logger) *Receiver {
|
||||
if log == nil {
|
||||
log = slog.New(slog.DiscardHandler)
|
||||
}
|
||||
return &Receiver{
|
||||
secret: secret,
|
||||
parser: parser,
|
||||
trigger: trigger,
|
||||
label: label,
|
||||
botUser: botUser,
|
||||
publish: publish,
|
||||
reactionPublish: reactionPublish,
|
||||
withdraw: withdraw,
|
||||
reactionLimiter: map[string]*reactionWindow{},
|
||||
log: log.With("component", "forge-webhook"),
|
||||
startedAt: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
// Status counts authenticated deliveries and published tasks.
|
||||
// LastReceivedAt is nil before the first delivery.
|
||||
type Status struct {
|
||||
StartedAt time.Time `json:"started_at"`
|
||||
LastReceivedAt *time.Time `json:"last_received_at"`
|
||||
Deliveries uint64 `json:"deliveries"`
|
||||
Publishes uint64 `json:"publishes"`
|
||||
ReactionPublishes uint64 `json:"reaction_publishes"`
|
||||
}
|
||||
|
||||
// Status returns a snapshot of the receiver's activity counters.
|
||||
func (r *Receiver) Status() Status {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
s := Status{
|
||||
StartedAt: r.startedAt,
|
||||
Deliveries: r.deliveries,
|
||||
Publishes: r.publishes,
|
||||
ReactionPublishes: r.reactionPublishes,
|
||||
}
|
||||
if !r.lastReceivedAt.IsZero() {
|
||||
last := r.lastReceivedAt
|
||||
s.LastReceivedAt = &last
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// recordDelivery marks one authenticated, parseable webhook as received.
|
||||
// Called only after HMAC verification and payload parsing succeed, so an
|
||||
// unauthenticated request (anyone spamming the endpoint with a bad
|
||||
// signature) can never inflate the "receiver is alive" signal.
|
||||
func (r *Receiver) recordDelivery() {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
r.deliveries++
|
||||
r.lastReceivedAt = time.Now()
|
||||
}
|
||||
|
||||
// recordPublish marks one delivery as having produced a task.
|
||||
func (r *Receiver) recordPublish() {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
r.publishes++
|
||||
}
|
||||
|
||||
// recordReactionPublish marks one delivery as having produced a reaction.
|
||||
func (r *Receiver) recordReactionPublish() {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
r.reactionPublishes++
|
||||
}
|
||||
|
||||
// ServeHTTP handles one forge webhook delivery. GitHub only ever POSTs here,
|
||||
// so any GET is answered with the receiver's Status instead -- an operator
|
||||
// (or a monitor) can curl the same address the webhook is configured against
|
||||
// to check liveness, with no separate health-check surface to wire up.
|
||||
func (r *Receiver) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
if req.Method == http.MethodGet {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(r.Status())
|
||||
return
|
||||
}
|
||||
if req.Method != http.MethodPost {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(io.LimitReader(req.Body, maxBodyBytes))
|
||||
if err != nil {
|
||||
r.log.ErrorContext(req.Context(), "read body", "err", err)
|
||||
http.Error(w, "read error", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// HMAC verification. An invalid or missing signature is rejected and
|
||||
// logged, never silently accepted.
|
||||
sig := req.Header.Get("X-Hub-Signature-256")
|
||||
if !webhookguard.VerifyHMAC(body, sig, r.secret) {
|
||||
r.log.WarnContext(req.Context(), "invalid signature", "remote", req.RemoteAddr)
|
||||
http.Error(w, "invalid signature", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
headers := make(map[string]string, len(req.Header))
|
||||
for name := range req.Header {
|
||||
headers[name] = req.Header.Get(name)
|
||||
}
|
||||
event, err := r.parser.ParseWebhook(req.Context(), headers, body)
|
||||
if errors.Is(err, forge.ErrBadWebhook) {
|
||||
r.log.WarnContext(req.Context(), "parse webhook", "err", err)
|
||||
http.Error(w, "bad payload", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
r.log.ErrorContext(req.Context(), "parse webhook", "err", err)
|
||||
http.Error(w, "parse unavailable", http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
// Authenticated and parseable: this is a genuine forge delivery,
|
||||
// independent of whether it turns out to be dispatch-eligible.
|
||||
r.recordDelivery()
|
||||
|
||||
switch {
|
||||
case event.Issue != nil:
|
||||
r.serveIssueEvent(w, req, event.Issue)
|
||||
case event.Review != nil:
|
||||
r.serveReviewEvent(w, req, event.Review)
|
||||
case event.ReviewComment != nil:
|
||||
r.serveReviewCommentEvent(w, req, event.ReviewComment)
|
||||
default:
|
||||
// Not an event this receiver decodes (ping, push, etc.).
|
||||
// Acknowledge and ignore.
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
}
|
||||
}
|
||||
|
||||
// serveIssueEvent is the receiver's original contract: an eligible issue
|
||||
// event becomes a task envelope on the task path.
|
||||
func (r *Receiver) serveIssueEvent(w http.ResponseWriter, req *http.Request, issueEvent *forge.IssueEvent) {
|
||||
task, ok := r.taskFromEvent(issueEvent)
|
||||
if !ok {
|
||||
// Delivered but not eligible work (PR, closed, unrelated action,
|
||||
// dispatch mismatch). A withdrawal declines the work it queued;
|
||||
// anything else is acknowledged without publishing.
|
||||
if reason, withdrawn := r.withdrawal(issueEvent); withdrawn && r.withdraw != nil {
|
||||
if err := r.withdraw(req.Context(), issueEvent.Owner, issueEvent.Repo, issueEvent.Number, reason); err != nil {
|
||||
r.log.ErrorContext(req.Context(), "withdraw task", "repo", issueEvent.Owner+"/"+issueEvent.Repo, "issue", issueEvent.Number, "err", err)
|
||||
http.Error(w, "withdraw failed", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
return
|
||||
}
|
||||
|
||||
if err := r.publish(req.Context(), task); err != nil {
|
||||
r.log.ErrorContext(req.Context(), "publish task", "task", task.Ref(), "err", err)
|
||||
http.Error(w, "publish failed", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
r.recordPublish()
|
||||
r.log.InfoContext(req.Context(), "published", "task", task.Ref())
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
}
|
||||
|
||||
// serveReviewEvent turns a submitted review into a reaction, the webhook
|
||||
// half of decision 2: the same typed reaction the poller produces, so
|
||||
// PublishUnique dedups the two sources. Only "submitted" carries a verdict
|
||||
// or summary to remediate; edited and dismissed restate or withdraw one.
|
||||
func (r *Receiver) serveReviewEvent(w http.ResponseWriter, req *http.Request, e *forge.ReviewEvent) {
|
||||
if e.Action != "submitted" {
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
return
|
||||
}
|
||||
if !r.allowReactionDelivery(req.RemoteAddr) {
|
||||
r.log.WarnContext(req.Context(), "reaction rate limit exceeded", "remote", req.RemoteAddr)
|
||||
http.Error(w, "rate limited", http.StatusTooManyRequests)
|
||||
return
|
||||
}
|
||||
if r.reactionPublish == nil {
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
return
|
||||
}
|
||||
reaction := workintake.ReviewCommentEnvelope{
|
||||
Owner: e.Owner,
|
||||
Repo: e.Repo,
|
||||
PRNumber: e.PRNumber,
|
||||
Kind: workintake.ReviewReactionReview,
|
||||
ReviewID: e.ReviewID,
|
||||
Author: e.Author,
|
||||
State: e.State,
|
||||
Body: e.Body,
|
||||
}
|
||||
r.deliverReaction(w, req, reaction)
|
||||
}
|
||||
|
||||
// serveReviewCommentEvent publishes an inline comment as a reaction. The
|
||||
// comment carries its parent review's ID, so the consumer can collect it
|
||||
// into that review's unit (decision 5) rather than starting a round of its
|
||||
// own.
|
||||
func (r *Receiver) serveReviewCommentEvent(w http.ResponseWriter, req *http.Request, e *forge.ReviewCommentEvent) {
|
||||
if e.Action != "created" {
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
return
|
||||
}
|
||||
if !r.allowReactionDelivery(req.RemoteAddr) {
|
||||
r.log.WarnContext(req.Context(), "reaction rate limit exceeded", "remote", req.RemoteAddr)
|
||||
http.Error(w, "rate limited", http.StatusTooManyRequests)
|
||||
return
|
||||
}
|
||||
if r.reactionPublish == nil {
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
return
|
||||
}
|
||||
reaction := workintake.ReviewCommentEnvelope{
|
||||
Owner: e.Owner,
|
||||
Repo: e.Repo,
|
||||
PRNumber: e.PRNumber,
|
||||
Kind: workintake.ReviewReactionComment,
|
||||
ReviewID: e.ReviewID,
|
||||
CommentID: e.CommentID,
|
||||
Author: e.Author,
|
||||
Body: e.Body,
|
||||
Path: e.Path,
|
||||
Line: e.Line,
|
||||
}
|
||||
r.deliverReaction(w, req, reaction)
|
||||
}
|
||||
|
||||
func (r *Receiver) deliverReaction(w http.ResponseWriter, req *http.Request, reaction workintake.ReviewCommentEnvelope) {
|
||||
if err := r.reactionPublish(req.Context(), reaction); err != nil {
|
||||
r.log.ErrorContext(req.Context(), "publish reaction", "key", reaction.IdempotencyKey(), "err", err)
|
||||
http.Error(w, "publish failed", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
r.recordReactionPublish()
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
}
|
||||
|
||||
// allowReactionDelivery consumes one reaction slot for the remote source.
|
||||
// A fixed window keeps the bookkeeping trivial; the failure mode is a burst
|
||||
// slightly over one window, which the consumer's dedup and round cap bound.
|
||||
func (r *Receiver) allowReactionDelivery(remote string) bool {
|
||||
now := time.Now()
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
for k, v := range r.reactionLimiter {
|
||||
if now.Sub(v.start) > reactionRateBucketTTL {
|
||||
delete(r.reactionLimiter, k)
|
||||
}
|
||||
}
|
||||
w, ok := r.reactionLimiter[remote]
|
||||
if !ok || now.Sub(w.start) > reactionRateWindow {
|
||||
r.reactionLimiter[remote] = &reactionWindow{start: now, count: 0}
|
||||
w = r.reactionLimiter[remote]
|
||||
}
|
||||
w.count++
|
||||
return w.count <= reactionRateLimit
|
||||
}
|
||||
|
||||
// withdrawal reports whether an issues event takes an issue out of dispatch:
|
||||
// it was closed, or lost the label or assignee that made it work.
|
||||
func (r *Receiver) withdrawal(event *forge.IssueEvent) (string, bool) {
|
||||
if event.PullRequest || event.Owner == "" || event.Repo == "" {
|
||||
return "", false
|
||||
}
|
||||
switch event.Action {
|
||||
case "closed":
|
||||
return "the issue was closed", true
|
||||
case "unlabeled", "unassigned":
|
||||
if !workintake.MatchesDispatch(r.trigger, r.label, r.botUser, event.Labels, event.Assignees) {
|
||||
return "the issue was " + event.Action, true
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
// taskFromEvent reports the task an issues event makes eligible, or
|
||||
// (zero, false) when it is not eligible work.
|
||||
func (r *Receiver) taskFromEvent(event *forge.IssueEvent) (workintake.TaskEnvelope, bool) {
|
||||
if event.PullRequest {
|
||||
return workintake.TaskEnvelope{}, false
|
||||
}
|
||||
// Only events that could newly make an issue eligible. unlabeled,
|
||||
// unassigned, closed, and edited never queue work.
|
||||
switch event.Action {
|
||||
case "opened", "reopened", "labeled", "assigned":
|
||||
default:
|
||||
return workintake.TaskEnvelope{}, false
|
||||
}
|
||||
if event.State != "open" {
|
||||
return workintake.TaskEnvelope{}, false
|
||||
}
|
||||
if !workintake.MatchesDispatch(r.trigger, r.label, r.botUser, event.Labels, event.Assignees) {
|
||||
return workintake.TaskEnvelope{}, false
|
||||
}
|
||||
if event.Owner == "" || event.Repo == "" {
|
||||
r.log.Warn("event missing repository", "action", event.Action)
|
||||
return workintake.TaskEnvelope{}, false
|
||||
}
|
||||
return workintake.TaskEnvelope{
|
||||
Owner: event.Owner,
|
||||
Repo: event.Repo,
|
||||
Number: event.Number,
|
||||
Title: event.Title,
|
||||
Body: event.Body,
|
||||
Labels: event.Labels,
|
||||
Kind: workintake.KindForLabels(event.Labels),
|
||||
}, true
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package webhook
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/forge"
|
||||
)
|
||||
|
||||
// An issue leaves dispatch when it is closed or loses what made it work; an
|
||||
// unlabel or unassign that still leaves it eligible withdraws nothing.
|
||||
func TestWithdrawal(t *testing.T) {
|
||||
r := New("", nil, "either", "archie", "bot", nil, nil, nil, nil)
|
||||
tests := []struct {
|
||||
name string
|
||||
event forge.IssueEvent
|
||||
want bool
|
||||
}{
|
||||
{"closed", forge.IssueEvent{Action: "closed", State: "closed"}, true},
|
||||
{"label removed, still assigned", forge.IssueEvent{Action: "unlabeled", Assignees: []string{"bot"}}, false},
|
||||
{"label removed, nothing left", forge.IssueEvent{Action: "unlabeled"}, true},
|
||||
{"unassigned, still labelled", forge.IssueEvent{Action: "unassigned", Labels: []string{"archie"}}, false},
|
||||
{"unassigned, nothing left", forge.IssueEvent{Action: "unassigned"}, true},
|
||||
{"edited", forge.IssueEvent{Action: "edited"}, false},
|
||||
{"a pull request closing", forge.IssueEvent{Action: "closed", PullRequest: true}, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
tt.event.Owner, tt.event.Repo = "acme", "widget"
|
||||
if _, got := r.withdrawal(&tt.event); got != tt.want {
|
||||
t.Fatalf("withdrawal = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -254,9 +254,6 @@ func applyForgeDefaults(cfg *config.Config) {
|
||||
if cfg.Forge.Host == "" {
|
||||
cfg.Forge.Host = defaultForgeHost
|
||||
}
|
||||
if cfg.Forge.Intake == "" {
|
||||
cfg.Forge.Intake = config.ForgeIntakePoll
|
||||
}
|
||||
}
|
||||
|
||||
// applyAccessDefaults fills the access surfaces' settings. See
|
||||
|
||||
@@ -9,9 +9,6 @@ var DeniedKeys = map[string]string{
|
||||
"forge.type": "Constructs the forge client at startup.",
|
||||
"forge.host": "Constructs the forge client at startup.",
|
||||
"forge.token": "Binds the forge account at startup.",
|
||||
"forge.intake": "Constructs the poll and webhook intake at startup.",
|
||||
"forge.webhook_secret": "Binds the webhook receiver at startup.",
|
||||
"forge.webhook_addr": "Binds the webhook listener at startup.",
|
||||
"bot_user": "Pins the daemon's forge identity and task-grant namespace at startup.",
|
||||
"bot_email": "Pins the forge account's commit identity at startup.",
|
||||
"org": "Pins the deployment's org at startup.",
|
||||
|
||||
@@ -38,7 +38,6 @@ var forgeTypePattern = regexp.MustCompile(`^[a-z0-9][a-z0-9-]*$`)
|
||||
var (
|
||||
dispatchTriggers = []string{dispatchTriggerAssignee, dispatchTriggerLabel, dispatchTriggerEither}
|
||||
natsModes = []string{config.NATSModeEmbedded, config.NATSModeExternal}
|
||||
forgeIntakes = []string{config.ForgeIntakePoll, config.ForgeIntakeWebhook, config.ForgeIntakeBoth}
|
||||
memoryEngines = []string{memoryEngineBuiltin}
|
||||
)
|
||||
|
||||
@@ -60,9 +59,6 @@ func validate(cfg *config.Config) error {
|
||||
// validateBootstrap checks the settings a file configuration still owns,
|
||||
// skipping those the control plane stores.
|
||||
func validateBootstrap(cfg *config.Config) error {
|
||||
if err := validateForgeIntake(cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateIdentityStructure(cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -176,31 +172,6 @@ func DispatchTriggerValid(trigger string) bool {
|
||||
return oneOf(trigger, dispatchTriggers)
|
||||
}
|
||||
|
||||
// validateForgeIntake checks the intake mode and webhook settings, and
|
||||
// rejects webhook intake with [[identities]] or on an identity.
|
||||
func validateForgeIntake(cfg *config.Config) error {
|
||||
intake := cfg.Forge.Intake
|
||||
if intake == "" {
|
||||
intake = config.ForgeIntakePoll
|
||||
}
|
||||
if !oneOf(intake, forgeIntakes) {
|
||||
return fmt.Errorf("%w: forge.intake %q (want %s)", ErrInvalidInput, cfg.Forge.Intake, list(forgeIntakes))
|
||||
}
|
||||
if intake == config.ForgeIntakeWebhook || intake == config.ForgeIntakeBoth {
|
||||
if len(cfg.Identities) > 0 {
|
||||
return fmt.Errorf("%w: forge.intake %q is not supported alongside [[identities]]: webhook intake is single-identity only, so every identity would silently keep polling (drop the [[identities]] blocks, or set forge.intake = %q and let each identity poll)",
|
||||
ErrInvalidInput, intake, config.ForgeIntakePoll)
|
||||
}
|
||||
if cfg.Forge.WebhookSecret == (config.SecretRef{}) {
|
||||
return fmt.Errorf("%w: forge.webhook_secret is required when forge.intake is %q", ErrInvalidInput, intake)
|
||||
}
|
||||
if cfg.Forge.WebhookAddr == "" {
|
||||
return fmt.Errorf("%w: forge.webhook_addr is required when forge.intake is %q", ErrInvalidInput, intake)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// validateProviders rejects base URLs carrying credentials or query state.
|
||||
// A provider URL is used to build API requests, so userinfo or a stray query
|
||||
// string would be silently attached to every call.
|
||||
|
||||
@@ -28,34 +28,29 @@ func TestForgeLayeringReadsTheConnection(t *testing.T) {
|
||||
base := config.Config{
|
||||
Forge: config.Forge{
|
||||
Type: "github", Host: "file.example.com",
|
||||
Token: config.SecretRef{Engine: "env", Key: "FILE_TOKEN"},
|
||||
Intake: config.ForgeIntakeBoth,
|
||||
WebhookSecret: config.SecretRef{Engine: "env", Key: "HOOK"},
|
||||
Token: config.SecretRef{Engine: "env", Key: "FILE_TOKEN"},
|
||||
},
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
connections string
|
||||
wantType string
|
||||
wantHost string
|
||||
wantKey string
|
||||
wantWebhookKept bool
|
||||
name string
|
||||
connections string
|
||||
wantType string
|
||||
wantHost string
|
||||
wantKey string
|
||||
}{
|
||||
{
|
||||
name: "the root connection replaces the file's forge",
|
||||
connections: `[{"id":"default","name":"Instance","type":"gitea","host":"gitea.example.com","token":{"engine":"vault","key":"forge/root"}}]`,
|
||||
wantType: "gitea",
|
||||
wantHost: "gitea.example.com",
|
||||
wantKey: "forge/root",
|
||||
wantWebhookKept: true,
|
||||
name: "the root connection replaces the file's forge",
|
||||
connections: `[{"id":"default","name":"Instance","type":"gitea","host":"gitea.example.com","token":{"engine":"vault","key":"forge/root"}}]`,
|
||||
wantType: "gitea",
|
||||
wantHost: "gitea.example.com",
|
||||
wantKey: "forge/root",
|
||||
},
|
||||
{
|
||||
name: "a document with no root connection disables the forge",
|
||||
connections: `[{"id":"acme","name":"Acme","type":"github","host":"github.com"}]`,
|
||||
wantType: "",
|
||||
wantHost: "",
|
||||
wantKey: "",
|
||||
wantWebhookKept: true,
|
||||
name: "a document with no root connection disables the forge",
|
||||
connections: `[{"id":"acme","name":"Acme","type":"github","host":"github.com"}]`,
|
||||
wantType: "",
|
||||
wantHost: "",
|
||||
wantKey: "",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
@@ -67,9 +62,6 @@ func TestForgeLayeringReadsTheConnection(t *testing.T) {
|
||||
if cfg.Forge.Type != tt.wantType || cfg.Forge.Host != tt.wantHost || cfg.Forge.Token.Key != tt.wantKey {
|
||||
t.Fatalf("forge = %+v, want type %q host %q key %q", cfg.Forge, tt.wantType, tt.wantHost, tt.wantKey)
|
||||
}
|
||||
if kept := cfg.Forge.WebhookSecret.Key == "HOOK" && cfg.Forge.Intake == config.ForgeIntakeBoth; kept != tt.wantWebhookKept {
|
||||
t.Fatalf("webhook intake/secret = %q/%q, want them kept from the file", cfg.Forge.Intake, cfg.Forge.WebhookSecret.Key)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,6 @@ var (
|
||||
_ forge.RepoArchiveReader = (*Forge)(nil)
|
||||
_ forge.PullRequestReviewReader = (*Forge)(nil)
|
||||
_ forge.ReviewCommentWriter = (*Forge)(nil)
|
||||
_ forge.WebhookParser = (*Forge)(nil)
|
||||
)
|
||||
|
||||
// Open starts the instance's extension process and configures it. The process
|
||||
@@ -350,42 +349,6 @@ func (f *Forge) LinkBranch(ctx context.Context, owner, repo string, issueNumber
|
||||
return err
|
||||
}
|
||||
|
||||
// ParseWebhook has the extension decode an authenticated delivery.
|
||||
func (f *Forge) ParseWebhook(ctx context.Context, headers map[string]string, body []byte) (forge.WebhookEvent, error) {
|
||||
resp, err := call(ctx, f, "parse webhook", func(c forgev1.ForgeServiceClient) (*forgev1.ParseWebhookResponse, error) {
|
||||
return c.ParseWebhook(ctx, &forgev1.ParseWebhookRequest{Headers: headers, Body: body})
|
||||
})
|
||||
if status.Code(errors.Unwrap(err)) == codes.InvalidArgument {
|
||||
return forge.WebhookEvent{}, fmt.Errorf("%w: %w", forge.ErrBadWebhook, err)
|
||||
}
|
||||
if err != nil {
|
||||
return forge.WebhookEvent{}, err
|
||||
}
|
||||
switch e := resp.GetEvent().(type) {
|
||||
case *forgev1.ParseWebhookResponse_Issue:
|
||||
i := e.Issue
|
||||
return forge.WebhookEvent{Issue: &forge.IssueEvent{
|
||||
Action: i.GetAction(), State: i.GetState(), PullRequest: i.GetIsPullRequest(),
|
||||
Owner: i.GetRepo().GetOwner(), Repo: i.GetRepo().GetRepo(), Number: int(i.GetNumber()),
|
||||
Title: i.GetTitle(), Body: i.GetBody(), Labels: i.GetLabels(), Assignees: i.GetAssignees(),
|
||||
}}, nil
|
||||
case *forgev1.ParseWebhookResponse_Review:
|
||||
r := e.Review
|
||||
return forge.WebhookEvent{Review: &forge.ReviewEvent{
|
||||
Action: r.GetAction(), Owner: r.GetRepo().GetOwner(), Repo: r.GetRepo().GetRepo(), PRNumber: int(r.GetPrNumber()),
|
||||
ReviewID: r.GetReviewId(), Author: r.GetAuthor(), State: r.GetState(), Body: r.GetBody(),
|
||||
}}, nil
|
||||
case *forgev1.ParseWebhookResponse_ReviewComment:
|
||||
c := e.ReviewComment
|
||||
return forge.WebhookEvent{ReviewComment: &forge.ReviewCommentEvent{
|
||||
Action: c.GetAction(), Owner: c.GetRepo().GetOwner(), Repo: c.GetRepo().GetRepo(), PRNumber: int(c.GetPrNumber()),
|
||||
ReviewID: c.GetReviewId(), CommentID: c.GetCommentId(), Author: c.GetAuthor(), Body: c.GetBody(),
|
||||
Path: c.GetPath(), Line: int(c.GetLine()),
|
||||
}}, nil
|
||||
}
|
||||
return forge.WebhookEvent{}, nil
|
||||
}
|
||||
|
||||
// GetRepoArchive streams the archive. The first chunk is read before
|
||||
// returning so an unsupported or failing forge surfaces as the call's error.
|
||||
func (f *Forge) GetRepoArchive(ctx context.Context, owner, repo, ref string) (io.ReadCloser, error) {
|
||||
|
||||
@@ -39,6 +39,10 @@ breaking:
|
||||
# and AuditResponse messages were removed in favour of the unified feed in
|
||||
# state/v1/audit.proto. The State Store and every client ship together, so
|
||||
# this is a deliberate break with no compatibility window.
|
||||
#
|
||||
# ForgeService.ParseWebhook and its event messages were removed with the
|
||||
# file-configured forge webhook receiver; forge webhooks arrive through event
|
||||
# capture. The forge extensions drop the RPC in the same change.
|
||||
ignore_only:
|
||||
FIELD_SAME_TYPE:
|
||||
- state/v1
|
||||
@@ -46,6 +50,7 @@ breaking:
|
||||
- state/v1
|
||||
- controlplane/v1/controlplane.proto
|
||||
- gateway/v1/chat.proto
|
||||
- forge/v1/forge.proto
|
||||
MESSAGE_NO_DELETE:
|
||||
- state/v1
|
||||
- controlplane/v1/controlplane.proto
|
||||
@@ -55,6 +60,7 @@ breaking:
|
||||
# CSR and FILE scopes.
|
||||
PACKAGE_MESSAGE_NO_DELETE:
|
||||
- controlplane/v1/controlplane.proto
|
||||
- forge/v1/forge.proto
|
||||
FIELD_NO_DELETE:
|
||||
- state/v1
|
||||
- controlplane/v1/controlplane.proto
|
||||
|
||||
@@ -41,10 +41,6 @@ service ForgeService {
|
||||
// repository, and the identity commits through it should carry. A forge that
|
||||
// authenticates git with its configured token answers UNIMPLEMENTED.
|
||||
rpc GitCredential(GitCredentialRequest) returns (GitCredentialResponse);
|
||||
// ParseWebhook decodes one webhook delivery the host has already
|
||||
// authenticated. A delivery that is not an event the host acts on returns no
|
||||
// event; an undecodable body is INVALID_ARGUMENT.
|
||||
rpc ParseWebhook(ParseWebhookRequest) returns (ParseWebhookResponse);
|
||||
// GetRepoArchive streams a gzipped tar of the repository at a ref.
|
||||
rpc GetRepoArchive(GetRepoArchiveRequest) returns (stream GetRepoArchiveResponse);
|
||||
}
|
||||
@@ -260,49 +256,3 @@ message GetRepoArchiveRequest {
|
||||
string ref = 2;
|
||||
}
|
||||
message GetRepoArchiveResponse { bytes data = 1; }
|
||||
|
||||
message ParseWebhookRequest {
|
||||
map<string, string> headers = 1;
|
||||
bytes body = 2;
|
||||
}
|
||||
message ParseWebhookResponse {
|
||||
oneof event {
|
||||
IssueEvent issue = 1;
|
||||
ReviewEvent review = 2;
|
||||
ReviewCommentEvent review_comment = 3;
|
||||
}
|
||||
}
|
||||
|
||||
message IssueEvent {
|
||||
string action = 1;
|
||||
string state = 2;
|
||||
bool is_pull_request = 3;
|
||||
RepoRef repo = 4;
|
||||
int32 number = 5;
|
||||
string title = 6;
|
||||
string body = 7;
|
||||
repeated string labels = 8;
|
||||
repeated string assignees = 9;
|
||||
}
|
||||
|
||||
message ReviewEvent {
|
||||
string action = 1;
|
||||
RepoRef repo = 2;
|
||||
int32 pr_number = 3;
|
||||
int64 review_id = 4;
|
||||
string author = 5;
|
||||
string state = 6;
|
||||
string body = 7;
|
||||
}
|
||||
|
||||
message ReviewCommentEvent {
|
||||
string action = 1;
|
||||
RepoRef repo = 2;
|
||||
int32 pr_number = 3;
|
||||
int64 review_id = 4;
|
||||
int64 comment_id = 5;
|
||||
string author = 6;
|
||||
string body = 7;
|
||||
string path = 8;
|
||||
int32 line = 9;
|
||||
}
|
||||
+25
-126
@@ -1,20 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
# Send a test event to the daemon's inbound webhook intakes and report what
|
||||
# landed. Two intakes, two failure modes, one tool:
|
||||
#
|
||||
# capture (default) POST /webhooks/capture/{source} on the dashboard
|
||||
# listener. Token-free, stores the redacted event for
|
||||
# the Event inspector.
|
||||
# Proves the capture -> inspector half of the Events chain.
|
||||
#
|
||||
# forge (--forge) POST to [forge].webhook_addr (default port 8645; the
|
||||
# receiver is the root handler of its own server, so any
|
||||
# path works), HMAC-signed with the webhook secret in
|
||||
# X-Hub-Signature-256. The receiver verifies the signature,
|
||||
# parses GitHub's issue event, and queues a task envelope
|
||||
# when the shared dispatch predicate matches. Proves the
|
||||
# forge -> task half. Needs [forge].intake webhook or both,
|
||||
# and forge.webhook_addr set.
|
||||
# Send a test event to the event capture intake and report what landed:
|
||||
# POST /webhooks/capture/{source} on the dashboard listener, stored redacted for
|
||||
# the Event inspector. With --secret the body is signed in X-Hub-Signature-256,
|
||||
# so a signed source records it as authenticated and its bindings can dispatch.
|
||||
#
|
||||
# Usage:
|
||||
# tools/webhook-send.sh # one generic capture event
|
||||
@@ -23,30 +11,25 @@
|
||||
# tools/webhook-send.sh --body '{"a":1}' # an exact payload
|
||||
# tools/webhook-send.sh --file /tmp/event.json
|
||||
# tools/webhook-send.sh --count 5 --delay 1
|
||||
# tools/webhook-send.sh --forge --url http://127.0.0.1:8645 \
|
||||
# --secret "$WH_SECRET" --assignee my-bot --label archie
|
||||
# tools/webhook-send.sh --kind github-issue --source gh --secret "$SOURCE_SECRET"
|
||||
# tools/webhook-send.sh --list # kinds, and exit
|
||||
#
|
||||
# --url is the intake a send goes to (the dashboard for capture, the receiver
|
||||
# for --forge). The read-back always reads the dashboard, which --api points
|
||||
# elsewhere when the dashboard is not on the default host.
|
||||
# --url is the dashboard the send goes to and is read back from.
|
||||
#
|
||||
# Environment:
|
||||
# ARCHIE_URL dashboard base URL (default http://127.0.0.1:8484)
|
||||
# ARCHIE_FORGE_URL forge receiver base URL, for --forge without --url
|
||||
# ARCHIE_WEBHOOK_SECRET the shared secret, for --forge without --secret
|
||||
# ARCHIE_WEBHOOK_SECRET the source's secret, when --secret is not given
|
||||
#
|
||||
# Limits the capture intake enforces (defaults from [capture] in
|
||||
# config.example.toml):
|
||||
# rate 1/s per remote address, burst 5 -> a fast --count > 5 needs --delay
|
||||
# bodies over 256 KiB are rejected with 413
|
||||
# Both are per-daemon-configurable, so a 429/413 here is the daemon's policy,
|
||||
# not a broken sender. The forge intake has no equivalent limits.
|
||||
# not a broken sender.
|
||||
set -euo pipefail
|
||||
|
||||
BASE_URL="${ARCHIE_URL:-http://127.0.0.1:8484}"
|
||||
TARGET_URL=""
|
||||
API_URL=""
|
||||
SOURCE="manual-test"
|
||||
KIND="generic"
|
||||
COUNT=1
|
||||
@@ -54,12 +37,8 @@ DELAY=0
|
||||
BODY=""
|
||||
FILE=""
|
||||
QUIET=0
|
||||
FORGE=0
|
||||
FORGE_URL="${ARCHIE_FORGE_URL:-}"
|
||||
SECRET="${ARCHIE_WEBHOOK_SECRET:-}"
|
||||
GH_EVENT="issues"
|
||||
ASSIGNEE=""
|
||||
LABEL=""
|
||||
|
||||
usage() {
|
||||
sed -n '2,40p' "$0" | sed 's/^# \{0,1\}//'
|
||||
@@ -75,10 +54,6 @@ Kinds (what each one posts):
|
||||
form application/x-www-form-urlencoded body
|
||||
large ~64 KB JSON, to exercise the intake's body bound
|
||||
empty no body at all
|
||||
|
||||
Forge mode (--forge) signs the payload for the forge receiver. Only an *issue*
|
||||
event dispatches, and only when the receiver's dispatch predicate matches, so
|
||||
reach for --assignee / --label to match a bot-user or label trigger.
|
||||
KINDS
|
||||
}
|
||||
|
||||
@@ -91,12 +66,8 @@ while [ $# -gt 0 ]; do
|
||||
--body) BODY="${2:?--body needs a value}"; shift 2 ;;
|
||||
--file) FILE="${2:?--file needs a value}"; shift 2 ;;
|
||||
--url) TARGET_URL="${2:?--url needs a value}"; shift 2 ;;
|
||||
--api) API_URL="${2:?--api needs a value}"; shift 2 ;;
|
||||
--forge) FORGE=1; shift ;;
|
||||
--secret) SECRET="${2:?--secret needs a value}"; shift 2 ;;
|
||||
--event) GH_EVENT="${2:?--event needs a value}"; shift 2 ;;
|
||||
--assignee) ASSIGNEE="${2:?--assignee needs a value}"; shift 2 ;;
|
||||
--label) LABEL="${2:?--label needs a value}"; shift 2 ;;
|
||||
--quiet) QUIET=1; shift ;;
|
||||
--list) list_kinds; exit 0 ;;
|
||||
-h|--help) usage; exit 0 ;;
|
||||
@@ -104,22 +75,7 @@ while [ $# -gt 0 ]; do
|
||||
esac
|
||||
done
|
||||
|
||||
# --url is the intake this send goes to, whichever one that is; the read-back
|
||||
# always needs the dashboard, which --api names when it is not the same host.
|
||||
if [ "$FORGE" -eq 1 ]; then
|
||||
FORGE_URL="${TARGET_URL:-$FORGE_URL}"
|
||||
BASE_URL="${API_URL:-$BASE_URL}"
|
||||
else
|
||||
BASE_URL="${TARGET_URL:-$BASE_URL}"
|
||||
fi
|
||||
|
||||
# A login or label goes into JSON, so it has to be a plain token: anything else
|
||||
# would be a way to write JSON with the shell rather than a way to send an event.
|
||||
for value in "$ASSIGNEE" "$LABEL"; do
|
||||
case "$value" in
|
||||
""|*[!A-Za-z0-9._-]*) [ -z "$value" ] || { echo "--assignee/--label take plain tokens (A-Za-z0-9._-)" >&2; exit 2; } ;;
|
||||
esac
|
||||
done
|
||||
BASE_URL="${TARGET_URL:-$BASE_URL}"
|
||||
|
||||
CONTENT_TYPE="application/json"
|
||||
if [ -n "$BODY" ]; then
|
||||
@@ -132,11 +88,7 @@ else
|
||||
github-issue)
|
||||
# The receiver only queues an issue event that is open, not a pull
|
||||
# request, and whose action could newly make it eligible.
|
||||
assignees="[]"
|
||||
[ -n "$ASSIGNEE" ] && assignees="[{\"login\":\"${ASSIGNEE}\"}]"
|
||||
labels="[]"
|
||||
[ -n "$LABEL" ] && labels="[{\"name\":\"${LABEL}\"}]"
|
||||
PAYLOAD="$(printf '{"action":"opened","issue":{"number":42,"title":"Test issue from webhook-send.sh","body":"Filed by tools/webhook-send.sh.","state":"open","html_url":"https://github.com/samcharles93/archie-core/issues/42","assignees":%s,"labels":%s},"repository":{"name":"archie-core","full_name":"samcharles93/archie-core","html_url":"https://github.com/samcharles93/archie-core","owner":{"login":"samcharles93"}},"sender":{"login":"webhook-send"}}' "$assignees" "$labels")"
|
||||
PAYLOAD="$(printf '{"action":"opened","issue":{"number":42,"title":"Test issue from webhook-send.sh","body":"Filed by tools/webhook-send.sh.","state":"open","html_url":"https://github.com/samcharles93/archie-core/issues/42","assignees":[],"labels":[]},"repository":{"name":"archie-core","full_name":"samcharles93/archie-core","html_url":"https://github.com/samcharles93/archie-core","owner":{"login":"samcharles93"}},"sender":{"login":"webhook-send"}}')"
|
||||
;;
|
||||
github-push)
|
||||
PAYLOAD='{"ref":"refs/heads/main","repository":{"name":"archie-core","full_name":"samcharles93/archie-core","owner":{"login":"samcharles93"}},"commits":[{"id":"c0ffee1","message":"Test commit from webhook-send.sh"}],"pusher":{"name":"webhook-send"}}'
|
||||
@@ -176,19 +128,13 @@ sign() {
|
||||
send_capture() {
|
||||
local url="${BASE_URL%/}/webhooks/capture/${SOURCE}"
|
||||
local code
|
||||
if [ -n "$PAYLOAD" ]; then
|
||||
code="$(curl -sS -o /tmp/webhook-send.out -w '%{http_code}' \
|
||||
-X POST "$url" -H "Content-Type: ${CONTENT_TYPE}" --data-binary "$PAYLOAD")" || {
|
||||
echo "cannot reach ${BASE_URL} — is the daemon running? (task dev, or archied)" >&2
|
||||
return 1
|
||||
}
|
||||
else
|
||||
code="$(curl -sS -o /tmp/webhook-send.out -w '%{http_code}' \
|
||||
-X POST "$url" -H "Content-Type: ${CONTENT_TYPE}")" || {
|
||||
echo "cannot reach ${BASE_URL} — is the daemon running? (task dev, or archied)" >&2
|
||||
return 1
|
||||
}
|
||||
fi
|
||||
local args=(-sS -o /tmp/webhook-send.out -w '%{http_code}' -X POST "$url" -H "Content-Type: ${CONTENT_TYPE}" -H "X-GitHub-Event: ${GH_EVENT}")
|
||||
[ -n "$SECRET" ] && args+=(-H "X-Hub-Signature-256: sha256=$(sign "$PAYLOAD")")
|
||||
[ -n "$PAYLOAD" ] && args+=(--data-binary "$PAYLOAD")
|
||||
code="$(curl "${args[@]}")" || {
|
||||
echo "cannot reach ${BASE_URL} — is the daemon running? (task dev, or archied)" >&2
|
||||
return 1
|
||||
}
|
||||
if [ "$code" -eq 429 ]; then
|
||||
echo "POST ${url} -> 429: the intake's rate limit (default 1/s, burst 5 per address)." >&2
|
||||
echo "Space sends out with --delay 1, or raise [capture] rate_per_second / rate_burst." >&2
|
||||
@@ -202,49 +148,12 @@ send_capture() {
|
||||
echo "POST ${url} -> ${code}: $(cat /tmp/webhook-send.out)" >&2
|
||||
return 1
|
||||
fi
|
||||
[ "$QUIET" -eq 1 ] || echo "POST ${url} -> ${code} (source: ${SOURCE}, kind: ${KIND})"
|
||||
[ "$QUIET" -eq 1 ] || echo "POST ${url} -> ${code} (source: ${SOURCE}, kind: ${KIND}$([ -n "$SECRET" ] && echo ', signed'))"
|
||||
}
|
||||
|
||||
send_forge() {
|
||||
local url="${FORGE_URL%/}"
|
||||
local signature
|
||||
signature="sha256=$(sign "$PAYLOAD")"
|
||||
local code
|
||||
code="$(curl -sS -o /tmp/webhook-send.out -w '%{http_code}' \
|
||||
-X POST "$url" \
|
||||
-H "Content-Type: ${CONTENT_TYPE}" \
|
||||
-H "X-GitHub-Event: ${GH_EVENT}" \
|
||||
-H "X-Hub-Signature-256: ${signature}" \
|
||||
--data-binary "$PAYLOAD")" || {
|
||||
echo "cannot reach ${url} — is [forge].webhook_addr listening?" >&2
|
||||
return 1
|
||||
}
|
||||
# A 2xx means "delivered", not "queued work": the receiver acknowledges
|
||||
# anything that verifies and is simply not eligible work. The task read-back
|
||||
# below is what tells the two apart.
|
||||
if [ "$code" -lt 200 ] || [ "$code" -ge 300 ]; then
|
||||
echo "POST ${url} -> ${code}: $(cat /tmp/webhook-send.out)" >&2
|
||||
[ "$code" = "401" ] && echo "401 means the signature was refused: check --secret against forge.webhook_secret." >&2
|
||||
return 1
|
||||
fi
|
||||
[ "$QUIET" -eq 1 ] || echo "POST ${url} -> ${code} (X-GitHub-Event: ${GH_EVENT}, signed)"
|
||||
}
|
||||
|
||||
if [ "$FORGE" -eq 1 ]; then
|
||||
if [ -z "$FORGE_URL" ]; then
|
||||
echo "--forge needs --url or ARCHIE_FORGE_URL: the receiver has an address of its own" >&2
|
||||
echo "(watch for \"forge webhook\" in the daemon log for the one it bound)." >&2
|
||||
exit 2
|
||||
fi
|
||||
if [ -z "$SECRET" ]; then
|
||||
echo "--forge needs --secret or ARCHIE_WEBHOOK_SECRET: the receiver verifies X-Hub-Signature-256" >&2
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
|
||||
i=0
|
||||
while [ "$i" -lt "$COUNT" ]; do
|
||||
if [ "$FORGE" -eq 1 ]; then send_forge; else send_capture; fi
|
||||
send_capture
|
||||
i=$((i + 1))
|
||||
[ "$i" -lt "$COUNT" ] && [ "$DELAY" != "0" ] && sleep "$DELAY"
|
||||
done
|
||||
@@ -252,20 +161,10 @@ done
|
||||
# Read it back, so a silent drop is visible here rather than only in the UI.
|
||||
if [ "$QUIET" -eq 0 ]; then
|
||||
sleep 0.3
|
||||
if [ "$FORGE" -eq 1 ]; then
|
||||
echo
|
||||
echo "Newest tasks (a signed issue event that matched dispatch shows up here):"
|
||||
curl -sS "${BASE_URL%/}/api/tasks?limit=3" | tr ',' '\n' \
|
||||
| grep -E '"id"|"status"|"number"|"title"|"repo"' | sed 's/^ *//' | head -16
|
||||
[ -z "$ASSIGNEE$LABEL" ] && echo "(no --assignee/--label given: a bot-user or label trigger will not have matched)"
|
||||
echo
|
||||
echo "Open ${BASE_URL%/}/tasks to see the board."
|
||||
else
|
||||
echo
|
||||
echo "Latest captures:"
|
||||
curl -sS "${BASE_URL%/}/api/captures?limit=${COUNT}" \
|
||||
| tr ',' '\n' | grep -E '"id"|"source"|"received_at"|"content_type"' | sed 's/^ *//' | head -20
|
||||
echo
|
||||
echo "Open ${BASE_URL%/}/captures to inspect them."
|
||||
fi
|
||||
echo
|
||||
echo "Latest captures:"
|
||||
curl -sS "${BASE_URL%/}/api/captures?limit=${COUNT}" \
|
||||
| tr ',' '\n' | grep -E '"id"|"source"|"received_at"|"content_type"' | sed 's/^ *//' | head -20
|
||||
echo
|
||||
echo "Open ${BASE_URL%/}/captures to inspect them."
|
||||
fi
|
||||
Reference in new issue
Block a user