Skip to content

Commit 6c749ec

Browse files
Thomas StrombergThomas Stromberg
authored andcommitted
linting
1 parent 3abe265 commit 6c749ec

File tree

3 files changed

+27
-45
lines changed

3 files changed

+27
-45
lines changed

pkg/srv/client.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
// Connection management follows a simple pattern:
1616
// - ONE goroutine (Run) handles ALL writes to avoid concurrent write issues
1717
// - Server sends pings every pingInterval to detect dead connections
18-
// - Client responds with pongs; server tracks responses via RecordPong
18+
// - Client responds with pongs; read loop resets deadline on any message
1919
// - Read loop (in websocket.go) detects disconnects and closes the connection
2020
type Client struct {
2121
conn *websocket.Conn
@@ -62,7 +62,7 @@ func NewClient(id string, sub Subscription, conn *websocket.Conn, hub *Hub, user
6262
//
6363
// Connection management:
6464
// 1. Server sends ping every pingInterval (54s)
65-
// 2. Client must respond with pong (tracked by RecordPong in read loop)
65+
// 2. Client must respond with pong (read loop resets deadline on any message)
6666
// 3. If client doesn't respond, read timeout (90s) will disconnect them
6767
// 4. Any write error immediately closes the connection
6868
func (c *Client) Run(ctx context.Context, pingInterval, writeTimeout time.Duration) {
@@ -128,16 +128,6 @@ func (c *Client) write(msg any, timeout time.Duration) error {
128128
return nil
129129
}
130130

131-
// RecordPong records receipt of a pong from the client.
132-
// This is called by the read loop when a pong message is received.
133-
// The read loop's timeout (90s) is what actually enforces disconnection.
134-
func (*Client) RecordPong(_ int64) {
135-
// No-op: pong receipt is tracked implicitly by the read loop's timeout.
136-
// The read loop resets its deadline on any message (including pong),
137-
// so as long as pongs arrive, the connection stays alive.
138-
// We keep this method for logging/debugging if needed in the future.
139-
}
140-
141131
// Close gracefully closes the client.
142132
func (c *Client) Close() {
143133
c.closeOnce.Do(func() {

pkg/srv/subscription.go

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,6 @@ func parsePRUrl(prURL string) (*prURLInfo, error) {
173173

174174
// Helper functions to reduce cognitive complexity.
175175

176-
func matchesEventType(sub Subscription, eventType string) bool {
177-
if len(sub.EventTypes) == 0 {
178-
return true // No filter means all events
179-
}
180-
for _, allowedType := range sub.EventTypes {
181-
if eventType == allowedType {
182-
return true
183-
}
184-
}
185-
return false
186-
}
187-
188176
func extractEventOrg(payload map[string]any) string {
189177
// Check repository owner first
190178
if repo, ok := payload["repository"].(map[string]any); ok {
@@ -254,8 +242,17 @@ func matchesPRSubscription(sub Subscription, payload map[string]any, eventOrg st
254242

255243
func matches(sub Subscription, event Event, payload map[string]any, userOrgs map[string]bool) bool {
256244
// Check if event type matches subscription
257-
if !matchesEventType(sub, event.Type) {
258-
return false
245+
if len(sub.EventTypes) > 0 {
246+
found := false
247+
for _, allowedType := range sub.EventTypes {
248+
if event.Type == allowedType {
249+
found = true
250+
break
251+
}
252+
}
253+
if !found {
254+
return false
255+
}
259256
}
260257

261258
// Extract the organization from the event
@@ -310,18 +307,6 @@ func matchesUserInObject(user map[string]any, username string) bool {
310307
return ok && strings.EqualFold(login, username)
311308
}
312309

313-
// matchesUserInList checks if username matches any login in a list of user objects.
314-
func matchesUserInList(users []any, username string) bool {
315-
for _, item := range users {
316-
if user, ok := item.(map[string]any); ok {
317-
if matchesUserInObject(user, username) {
318-
return true
319-
}
320-
}
321-
}
322-
return false
323-
}
324-
325310
// checkPullRequestUsers checks PR author, assignees, and reviewers.
326311
func checkPullRequestUsers(pr map[string]any, username string) bool {
327312
// Check PR author
@@ -333,15 +318,23 @@ func checkPullRequestUsers(pr map[string]any, username string) bool {
333318

334319
// Check assignees
335320
if assignees, ok := pr["assignees"].([]any); ok {
336-
if matchesUserInList(assignees, username) {
337-
return true
321+
for _, item := range assignees {
322+
if user, ok := item.(map[string]any); ok {
323+
if matchesUserInObject(user, username) {
324+
return true
325+
}
326+
}
338327
}
339328
}
340329

341330
// Check requested reviewers
342331
if reviewers, ok := pr["requested_reviewers"].([]any); ok {
343-
if matchesUserInList(reviewers, username) {
344-
return true
332+
for _, item := range reviewers {
333+
if user, ok := item.(map[string]any); ok {
334+
if matchesUserInObject(user, username) {
335+
return true
336+
}
337+
}
345338
}
346339
}
347340

pkg/srv/websocket.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -761,9 +761,8 @@ func (h *WebSocketHandler) Handle(ws *websocket.Conn) {
761761
switch msgType {
762762
case "pong":
763763
// Pong received - connection is alive
764-
if seq, ok := msgMap["seq"].(float64); ok {
765-
client.RecordPong(int64(seq))
766-
}
764+
// No explicit tracking needed: the read loop's deadline reset
765+
// (which happens for ANY message including pong) keeps the connection alive
767766
continue
768767
case "ping":
769768
// Client sent us a ping, send pong back

0 commit comments

Comments
 (0)