@@ -244,34 +244,19 @@ func matchesPRSubscription(sub Subscription, payload map[string]any, eventOrg st
244244 return false
245245}
246246
247- // repoInfo holds repository metadata extracted from event payloads.
248- type repoInfo struct {
249- Private bool
250- FullName string
251- }
252-
253- // extractRepoFromPayload extracts repository information from a GitHub webhook payload.
254- // Returns nil if no repository information is found in the payload.
255- func extractRepoFromPayload (payload map [string ]any ) * repoInfo {
247+ // extractRepoInfo extracts repository private status and full name from webhook payload.
248+ // Returns (private, fullName, ok) where ok is false if repository data is missing.
249+ //
250+ //nolint:errcheck,revive // Type assertions intentionally unchecked; defaults are correct
251+ func extractRepoInfo (payload map [string ]any ) (private bool , fullName string , ok bool ) {
256252 repoData , ok := payload ["repository" ].(map [string ]any )
257253 if ! ok {
258- return nil
259- }
260-
261- private , ok := repoData ["private" ].(bool )
262- if ! ok {
263- private = false // Default to false if not present
254+ return false , "" , false
264255 }
265256
266- fullName , ok := repoData ["full_name" ].(string )
267- if ! ok {
268- fullName = "" // Default to empty string if not present
269- }
270-
271- return & repoInfo {
272- Private : private ,
273- FullName : fullName ,
274- }
257+ private , _ = repoData ["private" ].(bool )
258+ fullName , _ = repoData ["full_name" ].(string )
259+ return private , fullName , true
275260}
276261
277262// matchesForTest is a test helper that creates a minimal client for testing.
@@ -294,21 +279,15 @@ func matches(ctx context.Context, client *Client, event Event, payload map[strin
294279 sub := client .subscription
295280 userOrgs := client .userOrgs
296281
297- // Extract repository info early to check private repo access
298- repo := extractRepoFromPayload (payload )
299-
300282 // Filter private repo events based on tier
301- if repo != nil && repo .Private {
302- canAccess := client .CanAccessPrivateRepos ()
303- enforceTiers := client .hub .enforceTiers
304-
305- if ! canAccess {
306- if enforceTiers {
283+ if private , repoName , ok := extractRepoInfo (payload ); ok && private {
284+ if ! client .CanAccessPrivateRepos () {
285+ if client .hub .enforceTiers {
307286 // Enforcement is active - actually filter the event
308287 logger .Info (ctx , "filtering private repo event (tier enforcement active)" , logger.Fields {
309288 "user" : sub .Username ,
310289 "tier" : string (client .tier ),
311- "repo" : repo . FullName ,
290+ "repo" : repoName ,
312291 "event_type" : event .Type ,
313292 })
314293 return false
@@ -317,7 +296,7 @@ func matches(ctx context.Context, client *Client, event Event, payload map[strin
317296 logger .Warn (ctx , "would filter private repo event if enforcement was active" , logger.Fields {
318297 "user" : sub .Username ,
319298 "tier" : string (client .tier ),
320- "repo" : repo . FullName ,
299+ "repo" : repoName ,
321300 "event_type" : event .Type ,
322301 "suggestion" : "upgrade to Pro or Flock tier for private repo access" ,
323302 })
0 commit comments