feat(web): add automatic actions for open pull requests

A new pr_open alert carries the head commit SHA of each open, non-draft, same-repository pull request. An action with auto enabled sends its webhook once for each pull request and head commit. An authors list limits which pull requests trigger it. The alert never changes repository health.
This commit is contained in:
2026-10-05 00:41:08 +01:00
parent 23bbbedf59
commit c79ecb728f
15 changed files with 473 additions and 27 deletions
+18 -3
View File
@@ -65,6 +65,7 @@ type Collector struct {
log *slog.Logger
webBase string
kick chan struct{}
onRefresh []func(context.Context, View)
names []string
th config.Thresholds
interval time.Duration
@@ -100,19 +101,33 @@ func New(f Fetcher, cfg *config.Config, log *slog.Logger) *Collector {
func (c *Collector) Run(ctx context.Context) {
t := time.NewTicker(c.interval)
defer t.Stop()
c.Refresh(ctx)
c.refreshAndNotify(ctx)
for {
select {
case <-ctx.Done():
return
case <-t.C:
c.Refresh(ctx)
c.refreshAndNotify(ctx)
case <-c.kick:
c.Refresh(ctx)
c.refreshAndNotify(ctx)
}
}
}
// OnRefresh registers fn to run after every scan started by Run; call it before Run.
func (c *Collector) OnRefresh(fn func(context.Context, View)) { c.onRefresh = append(c.onRefresh, fn) }
func (c *Collector) refreshAndNotify(ctx context.Context) {
c.Refresh(ctx)
if len(c.onRefresh) == 0 || ctx.Err() != nil {
return
}
v := c.View()
for _, fn := range c.onRefresh {
fn(ctx, v)
}
}
// RequestRefresh asks Run for an extra refresh; it reports false when one is already running or queued.
func (c *Collector) RequestRefresh() bool {
if c.refreshing.Load() {