Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gavel.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pre:
- name: build
run: make build
32 changes: 32 additions & 0 deletions .github/workflows/gavel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Gavel
on:
pull_request:
permissions:
contents: read
checks: write
issues: write
pull-requests: write
jobs:
gavel:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0

- uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6
with:
go-version: 1.26.x
cache: false

- uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4
with:
path: |
~/go/pkg/mod
~/.cache/go-build
.bin
key: cache-go-1.26.x-${{ hashFiles('**/go.sum') }}-${{ hashFiles('.bin/*') }}
restore-keys: |
cache-go-1.26.x-

- uses: flanksource/gavel@main
with:
fail-on-error: "true"
20 changes: 11 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and
$(CONTROLLER_GEN) object paths="./api/..." paths="./logs/..."

.PHONY: build
build: static
build: install-deps static
go build -o ./.bin/$(NAME) -ldflags "-X \"main.version=$(VERSION_TAG) built at $(DATE)\"" main.go

.PHONY: dev
Expand Down Expand Up @@ -175,9 +175,11 @@ test-e2e: bin
mkdir -p .bin


DEPS = $(shell which deps 2>/dev/null || echo $(LOCALBIN)/deps)

.PHONY: install-deps
install-deps: $(LOCALBIN) ## Install the deps CLI if not present
which deps 2>/dev/null || test -x $(LOCALBIN)/deps || curl -sSL https://github.com/flanksource/deps/releases/latest/download/deps-$(OS)-$(ARCH).tar.gz | tar -xz -C $(LOCALBIN)
install-deps: $(LOCALBIN)
@test -x $(DEPS) || curl -sSL https://github.com/flanksource/deps/releases/latest/download/deps-$(OS)-$(ARCH).tar.gz | tar -xz -C $(LOCALBIN)

.PHONY: deps
deps: install-deps ginkgo controller-gen golangci-lint kustomize $(TAILWIND_JS) ## Install all tool dependencies
Expand All @@ -187,16 +189,16 @@ ginkgo:
go install github.com/onsi/ginkgo/v2/ginkgo

.PHONY: controller-gen
controller-gen: install-deps $(LOCALBIN)
$(LOCALBIN)/deps install controller-gen@$(CONTROLLER_TOOLS_VERSION) --bin-dir $(LOCALBIN)
controller-gen: install-deps
$(DEPS) install controller-gen@$(CONTROLLER_TOOLS_VERSION) --bin-dir $(LOCALBIN)

.PHONY: golangci-lint
golangci-lint: install-deps $(LOCALBIN)
$(LOCALBIN)/deps install golangci/golangci-lint@v$(GOLANGCI_LINT_VERSION) --bin-dir $(LOCALBIN)
golangci-lint: install-deps
$(DEPS) install golangci/golangci-lint@v$(GOLANGCI_LINT_VERSION) --bin-dir $(LOCALBIN)

.PHONY: kustomize
kustomize: install-deps $(LOCALBIN)
$(LOCALBIN)/deps install kubernetes-sigs/kustomize@$(KUSTOMIZE_VERSION) --bin-dir $(LOCALBIN)
kustomize: install-deps
$(DEPS) install kubernetes-sigs/kustomize@$(KUSTOMIZE_VERSION) --bin-dir $(LOCALBIN)

.PHONY: docs\:mcp
docs\:mcp: ## Generate MCP tools reference documentation
Expand Down
19 changes: 19 additions & 0 deletions api/v1/connection_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ type ConnectionPushover struct {
User string `json:"user"`
}

type ConnectionTeams struct {
// Incoming webhook URL from Microsoft Teams
WebhookURL types.EnvVar `json:"webhookURL"`
}

type ConnectionMattermost struct {
// Incoming webhook URL
WebhookURL types.EnvVar `json:"webhookURL"`

// Channel override (optional)
Channel string `json:"channel,omitempty"`

// Username override (optional)
Username string `json:"username,omitempty"`

// Icon URL override (optional)
IconURL string `json:"iconURL,omitempty"`
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

type ConnectionPostgres struct {
// URL is the connection url.
URL types.EnvVar `json:"url,omitempty"`
Expand Down
32 changes: 32 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions events/event_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,57 @@ func ConsumeAll(ctx context.Context) {
for _, consumer := range consumers {
consumer.ConsumeUntilEmpty(ctx)
}
}

// InitConsumers registers event handlers and creates consumers without starting
// background listeners. Use ConsumeAll to process events explicitly.
// This is useful in tests to avoid races between background consumers and test data setup.
func InitConsumers(ctx context.Context) {
log := ctx.Logger.Named("events")
for _, fn := range registers {
fn(ctx)
}

SyncHandlers.Each(func(event string, handlers []postq.SyncEventHandlerFunc) {
consumer := postq.SyncEventConsumer{
WatchEvents: []string{event},
Consumers: handlers,
ConsumerOption: &postq.ConsumerOption{
ErrorHandler: defaultLoggerErrorHandler,
},
}
if ec, err := consumer.EventConsumer(); err != nil {
log.Fatalf("failed to create event consumer: %s", err)
} else {
consumers = append(consumers, ec)
}
})

AsyncHandlers.Each(func(event string, handlers []asyncHandlerData) {
for _, handler := range handlers {
h := handler.fn
batchSize := ctx.Properties().Int(event+".batchSize", handler.batchSize)
consumer := postq.AsyncEventConsumer{
WatchEvents: []string{event},
BatchSize: batchSize,
Consumer: func(_ctx context.Context, e models.Events) models.Events {
return h(ctx, e)
},
ConsumerOption: &postq.ConsumerOption{
NumConsumers: handler.numConsumers,
ErrorHandler: func(ctx context.Context, err error) bool {
log.Errorf("error consuming event(%s): %v", event, err)
return false
},
},
}
if ec, err := consumer.EventConsumer(); err != nil {
log.Fatalf("failed to create event consumer: %s", err)
} else {
consumers = append(consumers, ec)
}
}
})
}

func StartConsumers(ctx context.Context) {
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/MicahParks/keyfunc v1.9.0
github.com/casbin/casbin/v2 v2.135.0
github.com/casbin/gorm-adapter/v3 v3.41.0
github.com/containrrr/shoutrrr v0.8.0
github.com/fergusstrange/embedded-postgres v1.34.0 // indirect
github.com/flanksource/commons v1.50.2
github.com/flanksource/duty v1.0.1271
Expand Down Expand Up @@ -37,7 +36,6 @@ require (
github.com/MicahParks/keyfunc/v2 v2.1.0
github.com/RussellLuo/slidingwindow v0.0.0-20200528002341-535bb99d338b
github.com/WinterYukky/gorm-extra-clause-plugin v0.4.0
github.com/adityathebe/go-strip-markdown/v2 v2.0.1
github.com/aws/aws-sdk-go-v2 v1.41.5
github.com/aws/aws-sdk-go-v2/config v1.32.14
github.com/aws/aws-sdk-go-v2/credentials v1.19.14
Expand Down
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ github.com/TomOnTime/utfutil v1.0.0 h1:/0Ivgo2OjXJxo8i7zgvs7ewSFZMLwCRGm3P5Umowb
github.com/TomOnTime/utfutil v1.0.0/go.mod h1:l9lZmOniizVSuIliSkEf87qivMRlSNzbdBFKjuLRg1c=
github.com/WinterYukky/gorm-extra-clause-plugin v0.4.0 h1:e4gYsN9tNzoBMYKYBaGwwZpSljJhW231+1cBlYwv8YQ=
github.com/WinterYukky/gorm-extra-clause-plugin v0.4.0/go.mod h1:jNWq8AymgsVev9Kq6mke0b3o3yzY6bTSwjMDfTvZPPM=
github.com/adityathebe/go-strip-markdown/v2 v2.0.1 h1:/Dxr9Rnn6h8VIwh2rqpYTUyoN4Hx4SXeEOjrz+JUO6I=
github.com/adityathebe/go-strip-markdown/v2 v2.0.1/go.mod h1:Ze3XxKLEV5u8VWBaiAALVKOIA7uLZghVIUvQrICHFV0=
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/agnivade/levenshtein v1.2.1 h1:EHBY3UOn1gwdy/VbFwgo4cxecRznFk7fKWN1KOX7eoM=
Expand Down Expand Up @@ -340,8 +338,6 @@ github.com/cncf/xds/go v0.0.0-20260121142036-a486691bba94 h1:kkHPnzHm5Ln7WA0XYjr
github.com/cncf/xds/go v0.0.0-20260121142036-a486691bba94/go.mod h1:KdCmV+x/BuvyMxRnYBlmVaq4OLiKW6iRQfvC62cvdkI=
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
github.com/containrrr/shoutrrr v0.8.0 h1:mfG2ATzIS7NR2Ec6XL+xyoHzN97H8WPjir8aYzJUSec=
github.com/containrrr/shoutrrr v0.8.0/go.mod h1:ioyQAyu1LJY6sILuNyKaQaw+9Ttik5QePU8atnAdO2o=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
Expand Down Expand Up @@ -786,8 +782,6 @@ github.com/jackc/puddle v1.3.0 h1:eHK/5clGOatcjX3oWGBO/MpxpbHzSwud5EWTSCI+MX0=
github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jarcoal/httpmock v1.3.0 h1:2RJ8GP0IIaWwcC9Fp2BmVi8Kog3v2Hn7VXM3fTd+nuc=
github.com/jarcoal/httpmock v1.3.0/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs=
Expand Down
Loading
Loading