@@ -3,13 +3,22 @@ package main
33import (
44 "context"
55 "os"
6+ "slices"
67 "strings"
78 "time"
89
910 ghapi "github.com/rtzll/rascal/internal/github"
1011 "github.com/spf13/cobra"
1112)
1213
14+ var requiredWebhookEvents = []string {
15+ "issues" ,
16+ "issue_comment" ,
17+ "pull_request_review" ,
18+ "pull_request_review_comment" ,
19+ "pull_request" ,
20+ }
21+
1322func (a * app ) newRepoCmd () * cobra.Command {
1423 cmd := & cobra.Command {
1524 Use : "repo" ,
@@ -174,11 +183,18 @@ func (a *app) newRepoStatusCmd() *cobra.Command {
174183 if err != nil {
175184 return & cliError {Code : exitRuntime , Message : "failed to check webhook" , Cause : err }
176185 }
186+ missingEvents := []string {}
187+ if hook != nil {
188+ missingEvents = missingRequiredWebhookEvents (hook .Events )
189+ }
177190 out := map [string ]any {
178- "repo" : repo ,
179- "label_exists" : labelExists ,
180- "webhook_url" : webhookURL ,
181- "webhook" : hook ,
191+ "repo" : repo ,
192+ "label_exists" : labelExists ,
193+ "webhook_url" : webhookURL ,
194+ "webhook" : hook ,
195+ "required_events" : requiredWebhookEvents ,
196+ "missing_events" : missingEvents ,
197+ "webhook_events_healthy" : hook != nil && len (missingEvents ) == 0 ,
182198 }
183199 return a .emit (out , func () error {
184200 a .println ("repo: %s" , repo )
@@ -191,6 +207,9 @@ func (a *app) newRepoStatusCmd() *cobra.Command {
191207 if len (hook .Events ) > 0 {
192208 a .println ("events: %s" , strings .Join (hook .Events , "," ))
193209 }
210+ if len (missingEvents ) > 0 {
211+ a .println ("warning: webhook missing required events: %s" , strings .Join (missingEvents , "," ))
212+ }
194213 return nil
195214 })
196215 },
@@ -207,3 +226,22 @@ func resolveRepoArg(args []string, def string) string {
207226 }
208227 return strings .TrimSpace (def )
209228}
229+
230+ func missingRequiredWebhookEvents (events []string ) []string {
231+ normalized := make ([]string , 0 , len (events ))
232+ for _ , event := range events {
233+ event = strings .ToLower (strings .TrimSpace (event ))
234+ if event == "" || slices .Contains (normalized , event ) {
235+ continue
236+ }
237+ normalized = append (normalized , event )
238+ }
239+
240+ missing := make ([]string , 0 )
241+ for _ , want := range requiredWebhookEvents {
242+ if ! slices .Contains (normalized , want ) {
243+ missing = append (missing , want )
244+ }
245+ }
246+ return missing
247+ }
0 commit comments