@@ -3,98 +3,12 @@ import Webhook from "./webhook.js";
33
44import schemaImport from "rest-api-description/descriptions/api.github.com/dereferenced/api.github.com.deref.json" ;
55import { deduplicateWebhooks } from "./deduplicate.js" ;
6+ import { DROPPED_EVENTS , KEPT_EVENTS } from "./event-filters.js" ;
67const schema = schemaImport as any ;
78
89const OUTPUT_PATH = "./src/context-providers/events/webhooks.json" ;
910const OBJECTS_PATH = "./src/context-providers/events/objects.json" ;
10- const ALL_OUTPUT_PATH = "./src/context-providers/events/webhooks.all.json" ;
11- const ALL_OBJECTS_PATH = "./src/context-providers/events/objects.all.json" ;
12- const DROP_OUTPUT_PATH = "./src/context-providers/events/webhooks.drop.json" ;
13- const DROP_OBJECTS_PATH = "./src/context-providers/events/objects.drop.json" ;
14- const STRIP_OUTPUT_PATH = "./src/context-providers/events/webhooks.strip.json" ;
15- const STRIP_OBJECTS_PATH = "./src/context-providers/events/objects.strip.json" ;
16-
17- // Parse --all flag
18- const generateAll = process . argv . includes ( "--all" ) ;
19-
20- // Events to drop - not valid workflow triggers (GitHub App or API-only events)
21- // See: https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows
22- const DROPPED_EVENTS = new Set ( [
23- "branch_protection_configuration" ,
24- "code_scanning_alert" ,
25- "commit_comment" ,
26- "custom_property" ,
27- "custom_property_values" ,
28- "dependabot_alert" ,
29- "deploy_key" ,
30- "github_app_authorization" ,
31- "installation" ,
32- "installation_repositories" ,
33- "installation_target" ,
34- "marketplace_purchase" ,
35- "member" ,
36- "membership" ,
37- "merge_group" ,
38- "meta" ,
39- "org_block" ,
40- "organization" ,
41- "package" ,
42- "personal_access_token_request" ,
43- "ping" ,
44- "repository" ,
45- "repository_advisory" ,
46- "repository_ruleset" ,
47- "secret_scanning_alert" ,
48- "secret_scanning_alert_location" ,
49- "security_advisory" ,
50- "security_and_analysis" ,
51- "sponsorship" ,
52- "star" ,
53- "team" ,
54- "team_add"
55- ] ) ;
56-
57- // Events to keep - valid workflow triggers
58- // See: https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows
59- const KEPT_EVENTS = new Set ( [
60- "branch_protection_rule" ,
61- "check_run" ,
62- "check_suite" ,
63- "create" ,
64- "delete" ,
65- "deployment" ,
66- "deployment_status" ,
67- "discussion" ,
68- "discussion_comment" ,
69- "fork" ,
70- "gollum" ,
71- "issue_comment" ,
72- "issues" ,
73- "label" ,
74- "milestone" ,
75- "page_build" ,
76- "project" ,
77- "project_card" ,
78- "project_column" ,
79- "projects_v2" ,
80- "projects_v2_item" ,
81- "public" ,
82- "pull_request" ,
83- "pull_request_review" ,
84- "pull_request_review_comment" ,
85- "pull_request_review_thread" ,
86- "push" ,
87- "registry_package" ,
88- "release" ,
89- "repository_dispatch" ,
90- "repository_import" ,
91- "repository_vulnerability_alert" ,
92- "status" ,
93- "watch" ,
94- "workflow_dispatch" ,
95- "workflow_job" ,
96- "workflow_run"
97- ] ) ;
11+ const FULL_OUTPUT_PATH = "./src/context-providers/events/webhooks.full.json" ;
9812
9913/**
10014 * Fields to strip from the JSON data.
@@ -234,6 +148,23 @@ if (unknownEvents.length > 0) {
234148 process . exit ( 1 ) ;
235149}
236150
151+ // Build full webhooks (all events, no transformations) for validation tests
152+ const fullWebhooks : Record < string , Record < string , Webhook > > = { } ;
153+ for ( const webhook of webhooks ) {
154+ if ( ! webhook . action ) webhook . action = "default" ;
155+
156+ if ( fullWebhooks [ webhook . category ] ) {
157+ fullWebhooks [ webhook . category ] [ webhook . action ] = webhook ;
158+ } else {
159+ fullWebhooks [ webhook . category ] = { } ;
160+ fullWebhooks [ webhook . category ] [ webhook . action ] = webhook ;
161+ }
162+ }
163+
164+ // Write full version (before any optimizations)
165+ await fs . writeFile ( FULL_OUTPUT_PATH , JSON . stringify ( fullWebhooks , null , 2 ) ) ;
166+ console . log ( `Wrote ${ FULL_OUTPUT_PATH } (${ Object . keys ( fullWebhooks ) . length } events, unoptimized)` ) ;
167+
237168// The category is the name of the webhook
238169const categorizedWebhooks : Record < string , Record < string , Webhook > > = { } ;
239170for ( const webhook of webhooks ) {
@@ -264,47 +195,3 @@ await fs.writeFile(OUTPUT_PATH, JSON.stringify(strippedWebhooks, null, 2));
264195
265196console . log ( `Wrote ${ OUTPUT_PATH } (${ Object . keys ( strippedWebhooks ) . length } events)` ) ;
266197console . log ( `Wrote ${ OBJECTS_PATH } (${ objectsArray . length } objects)` ) ;
267-
268- // Optionally generate intermediate versions for size comparison
269- if ( generateAll ) {
270- // Helper to deep clone
271- function clone < T > ( obj : T ) : T {
272- return JSON . parse ( JSON . stringify ( obj ) ) ;
273- }
274-
275- // Build full webhooks (no drop, no strip) from fresh data
276- const fullWebhooks : Record < string , Record < string , any > > = { } ;
277- for ( const webhook of webhooks ) {
278- const w = clone ( webhook ) ;
279- if ( ! w . action ) w . action = "default" ;
280- fullWebhooks [ w . category ] ||= { } ;
281- fullWebhooks [ w . category ] [ w . action ] = w ;
282- }
283-
284- // Generate all version (no drop, no strip)
285- const allWebhooks = clone ( fullWebhooks ) ;
286- const allObjects = deduplicateWebhooks ( allWebhooks ) ;
287- await fs . writeFile ( ALL_OUTPUT_PATH , JSON . stringify ( allWebhooks , null , 2 ) ) ;
288- await fs . writeFile ( ALL_OBJECTS_PATH , JSON . stringify ( allObjects , null , 2 ) ) ;
289- console . log ( `Wrote ${ ALL_OUTPUT_PATH } (${ Object . keys ( allWebhooks ) . length } events)` ) ;
290- console . log ( `Wrote ${ ALL_OBJECTS_PATH } (${ allObjects . length } objects)` ) ;
291-
292- // Generate drop-only version (drop events, no strip)
293- const dropWebhooks = clone ( fullWebhooks ) ;
294- for ( const event of DROPPED_EVENTS ) {
295- delete dropWebhooks [ event ] ;
296- }
297- const dropObjects = deduplicateWebhooks ( dropWebhooks ) ;
298- await fs . writeFile ( DROP_OUTPUT_PATH , JSON . stringify ( dropWebhooks , null , 2 ) ) ;
299- await fs . writeFile ( DROP_OBJECTS_PATH , JSON . stringify ( dropObjects , null , 2 ) ) ;
300- console . log ( `Wrote ${ DROP_OUTPUT_PATH } (${ Object . keys ( dropWebhooks ) . length } events)` ) ;
301- console . log ( `Wrote ${ DROP_OBJECTS_PATH } (${ dropObjects . length } objects)` ) ;
302-
303- // Generate strip-only version (strip fields, no drop)
304- const stripWebhooks = stripFields ( clone ( fullWebhooks ) ) ;
305- const stripObjects = deduplicateWebhooks ( stripWebhooks ) ;
306- await fs . writeFile ( STRIP_OUTPUT_PATH , JSON . stringify ( stripWebhooks , null , 2 ) ) ;
307- await fs . writeFile ( STRIP_OBJECTS_PATH , JSON . stringify ( stripObjects , null , 2 ) ) ;
308- console . log ( `Wrote ${ STRIP_OUTPUT_PATH } (${ Object . keys ( stripWebhooks ) . length } events)` ) ;
309- console . log ( `Wrote ${ STRIP_OBJECTS_PATH } (${ stripObjects . length } objects)` ) ;
310- }
0 commit comments