Skip to content

Commit e89136d

Browse files
Thomas StrombergThomas Stromberg
authored andcommitted
improve commit->PR lookup, linting
1 parent 3eed019 commit e89136d

File tree

15 files changed

+1181
-236
lines changed

15 files changed

+1181
-236
lines changed

pkg/client/client.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,8 @@ func (c *Client) sendPings(ctx context.Context) {
543543
}
544544

545545
// readEvents reads and processes events from the WebSocket with responsive shutdown.
546+
//
547+
//nolint:gocognit,revive,maintidx // Complex event processing with cache management is intentional and well-documented
546548
func (c *Client) readEvents(ctx context.Context, ws *websocket.Conn) error {
547549
for {
548550
// Check for context cancellation first
@@ -647,6 +649,7 @@ func (c *Client) readEvents(ctx context.Context, ws *websocket.Conn) error {
647649

648650
// Populate cache from pull_request events to prevent cache misses
649651
// This ensures check events arriving shortly after PR creation can find the PR
652+
//nolint:nestif // Cache population logic requires nested validation
650653
if event.Type == "pull_request" && event.CommitSHA != "" && strings.Contains(event.URL, "/pull/") {
651654
// Extract owner/repo/pr_number from URL
652655
parts := strings.Split(event.URL, "/")
@@ -671,7 +674,7 @@ func (c *Client) readEvents(ctx context.Context, ws *websocket.Conn) error {
671674
"pr_number", prNum)
672675

673676
// Evict oldest 25% if cache is full
674-
if len(c.commitCacheKeys) > c.maxCacheSize {
677+
if len(c.commitCacheKeys) > c.maxCacheSize { //nolint:revive // Cache eviction logic intentionally nested
675678
n := c.maxCacheSize / 4
676679
for i := range n {
677680
delete(c.commitPRCache, c.commitCacheKeys[i])
@@ -682,12 +685,12 @@ func (c *Client) readEvents(ctx context.Context, ws *websocket.Conn) error {
682685
// Check if PR number already in list
683686
found := false
684687
for _, existingPR := range existing {
685-
if existingPR == prNum {
688+
if existingPR == prNum { //nolint:revive // PR deduplication requires nested check
686689
found = true
687690
break
688691
}
689692
}
690-
if !found {
693+
if !found { //nolint:revive // Cache update requires nested check
691694
// Add PR to existing cache entry
692695
c.commitPRCache[key] = append(existing, prNum)
693696
c.logger.Debug("Added PR to existing cache entry",
@@ -705,6 +708,7 @@ func (c *Client) readEvents(ctx context.Context, ws *websocket.Conn) error {
705708

706709
// Handle check events with repo-only URLs (GitHub race condition)
707710
// Automatically expand into per-PR events using GitHub API with caching
711+
//nolint:nestif // Check event expansion requires nested validation and cache management
708712
if (event.Type == "check_run" || event.Type == "check_suite") && event.CommitSHA != "" && !strings.Contains(event.URL, "/pull/") {
709713
// Extract owner/repo from URL
710714
parts := strings.Split(event.URL, "/")
@@ -750,7 +754,7 @@ func (c *Client) readEvents(ctx context.Context, ws *websocket.Conn) error {
750754
} else {
751755
// Cache the result (even if empty)
752756
c.cacheMu.Lock()
753-
if _, exists := c.commitPRCache[key]; !exists {
757+
if _, exists := c.commitPRCache[key]; !exists { //nolint:revive // Cache management requires nested check
754758
c.commitCacheKeys = append(c.commitCacheKeys, key)
755759
// Evict oldest 25% if cache is full
756760
if len(c.commitCacheKeys) > c.maxCacheSize {

0 commit comments

Comments
 (0)