From c5d0ab4ebc578bc1998c95162a2ae9e7e074ee54 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 22 Mar 2026 19:05:50 +0000 Subject: [PATCH] refactor: simplify conditional server rows and redundant pattern splitting - gateway_logs.go: eliminate duplicated if/else blocks for server rows and table config. Build the base row once and conditionally append the Filtered column; build headers similarly. Reduces ~20 lines of duplicate code while preserving identical behavior. - push_repo_memory.cjs: pre-compute patternStrs once before building the regex patterns array, removing two redundant re-splits of the fileGlobFilter string inside the map callback and the error block. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- actions/setup/js/push_repo_memory.cjs | 11 ++----- pkg/cli/gateway_logs.go | 43 ++++++++++----------------- 2 files changed, 19 insertions(+), 35 deletions(-) diff --git a/actions/setup/js/push_repo_memory.cjs b/actions/setup/js/push_repo_memory.cjs index 0315da51032..6dd889373f2 100644 --- a/actions/setup/js/push_repo_memory.cjs +++ b/actions/setup/js/push_repo_memory.cjs @@ -195,11 +195,8 @@ async function main() { // Validate file name patterns if filter is set if (fileGlobFilter) { - const patterns = fileGlobFilter - .trim() - .split(/\s+/) - .filter(Boolean) - .map(pattern => globPatternToRegex(pattern)); + const patternStrs = fileGlobFilter.trim().split(/\s+/).filter(Boolean); + const patterns = patternStrs.map(pattern => globPatternToRegex(pattern)); // Test patterns against the relative file path within the memory directory // Patterns are specified relative to the memory artifact directory, not the branch path @@ -212,8 +209,7 @@ async function main() { const matchResults = patterns.map((pattern, idx) => { const matches = pattern.test(normalizedRelPath); - const patternStr = fileGlobFilter.trim().split(/\s+/).filter(Boolean)[idx]; - core.debug(` Pattern ${idx + 1}: "${patternStr}" -> ${pattern.source} -> ${matches ? "✓ MATCH" : "✗ NO MATCH"}`); + core.debug(` Pattern ${idx + 1}: "${patternStrs[idx]}" -> ${pattern.source} -> ${matches ? "✓ MATCH" : "✗ NO MATCH"}`); return matches; }); @@ -222,7 +218,6 @@ async function main() { core.warning(`Skipping file that does not match allowed patterns: ${normalizedRelPath}`); core.info(` File path being tested (relative to artifact): ${normalizedRelPath}`); core.info(` Configured patterns: ${fileGlobFilter}`); - const patternStrs = fileGlobFilter.trim().split(/\s+/).filter(Boolean); patterns.forEach((pattern, idx) => { core.info(` Pattern: "${patternStrs[idx]}" -> Regex: ${pattern.source} -> ${matchResults[idx] ? "✅ MATCH" : "❌ NO MATCH"}`); }); diff --git a/pkg/cli/gateway_logs.go b/pkg/cli/gateway_logs.go index 3078c635bcc..7211187f5fb 100644 --- a/pkg/cli/gateway_logs.go +++ b/pkg/cli/gateway_logs.go @@ -617,39 +617,28 @@ func renderGatewayMetricsTable(metrics *GatewayMetrics, verbose bool) string { if server.RequestCount > 0 { avgTime = server.TotalDuration / float64(server.RequestCount) } + row := []string{ + serverName, + strconv.Itoa(server.RequestCount), + strconv.Itoa(server.ToolCallCount), + fmt.Sprintf("%.0fms", avgTime), + strconv.Itoa(server.ErrorCount), + } if hasFiltered { - serverRows = append(serverRows, []string{ - serverName, - strconv.Itoa(server.RequestCount), - strconv.Itoa(server.ToolCallCount), - fmt.Sprintf("%.0fms", avgTime), - strconv.Itoa(server.ErrorCount), - strconv.Itoa(server.FilteredCount), - }) - } else { - serverRows = append(serverRows, []string{ - serverName, - strconv.Itoa(server.RequestCount), - strconv.Itoa(server.ToolCallCount), - fmt.Sprintf("%.0fms", avgTime), - strconv.Itoa(server.ErrorCount), - }) + row = append(row, strconv.Itoa(server.FilteredCount)) } + serverRows = append(serverRows, row) } + headers := []string{"Server", "Requests", "Tool Calls", "Avg Time", "Errors"} if hasFiltered { - output.WriteString(console.RenderTable(console.TableConfig{ - Title: "Server Usage", - Headers: []string{"Server", "Requests", "Tool Calls", "Avg Time", "Errors", "Filtered"}, - Rows: serverRows, - })) - } else { - output.WriteString(console.RenderTable(console.TableConfig{ - Title: "Server Usage", - Headers: []string{"Server", "Requests", "Tool Calls", "Avg Time", "Errors"}, - Rows: serverRows, - })) + headers = append(headers, "Filtered") } + output.WriteString(console.RenderTable(console.TableConfig{ + Title: "Server Usage", + Headers: headers, + Rows: serverRows, + })) } // DIFC filtered events table