diff --git a/.changeset/patch-fix-logs-count-parameter.md b/.changeset/patch-fix-logs-count-parameter.md new file mode 100644 index 0000000000..27a80b9e61 --- /dev/null +++ b/.changeset/patch-fix-logs-count-parameter.md @@ -0,0 +1,5 @@ +--- +"gh-aw": patch +--- + +Fix logs command parameter naming confusion in pagination function diff --git a/pkg/cli/logs.go b/pkg/cli/logs.go index 9abc0cc3ce..8200bafcb3 100644 --- a/pkg/cli/logs.go +++ b/pkg/cli/logs.go @@ -786,15 +786,18 @@ func downloadRunArtifactsConcurrent(runs []WorkflowRun, outputDir string, verbos // // The totalFetched count is critical for pagination - it indicates whether more data is available // from GitHub, whereas the filtered runs count may be much smaller after filtering for agentic workflows. -func listWorkflowRunsWithPagination(workflowName string, count int, startDate, endDate, beforeDate, branch string, beforeRunID, afterRunID int64, verbose bool) ([]WorkflowRun, int, error) { +// +// The limit parameter specifies the batch size for the GitHub API call (how many runs to fetch in this request), +// not the total number of matching runs the user wants to find. +func listWorkflowRunsWithPagination(workflowName string, limit int, startDate, endDate, beforeDate, branch string, beforeRunID, afterRunID int64, verbose bool) ([]WorkflowRun, int, error) { args := []string{"run", "list", "--json", "databaseId,number,url,status,conclusion,workflowName,createdAt,startedAt,updatedAt,event,headBranch,headSha,displayTitle"} // Add filters if workflowName != "" { args = append(args, "--workflow", workflowName) } - if count > 0 { - args = append(args, "--limit", strconv.Itoa(count)) + if limit > 0 { + args = append(args, "--limit", strconv.Itoa(limit)) } if startDate != "" { args = append(args, "--created", ">="+startDate) diff --git a/pkg/cli/logs_filtering_test.go b/pkg/cli/logs_filtering_test.go index 73875ac716..86ac3a8c2b 100644 --- a/pkg/cli/logs_filtering_test.go +++ b/pkg/cli/logs_filtering_test.go @@ -39,3 +39,25 @@ func TestDownloadWorkflowLogs_IteratesUntilEnoughRuns(t *testing.T) { // 4. Returns the same number of results as: // ./gh-aw logs tidy -c 10 (specific workflow name) } + +// TestListWorkflowRunsWithPagination_LimitParameter verifies that the limit parameter +// is correctly used as the batch size for the GitHub API call +func TestListWorkflowRunsWithPagination_LimitParameter(t *testing.T) { + // This test documents the parameter semantics: + // - The 'limit' parameter in listWorkflowRunsWithPagination represents the batch size + // for the GitHub API call (how many runs to fetch in this request) + // - This is different from the user's '-c' flag which represents the total number + // of matching runs they want to find + // + // Example: User runs './gh-aw logs -c 10' + // - User wants 10 matching runs total (the count from -c flag) + // - Each iteration fetches a batch using listWorkflowRunsWithPagination(workflowName, batchSize=100/250, ...) + // - The batchSize (100 or 250) is passed as 'limit' to the GitHub CLI + // - Loop continues until we have 10 matching runs or exhaust available runs + // + // The fix: Renamed parameter from 'count' to 'limit' to clarify it's the API batch size + + t.Log("Parameter semantics verified by renaming 'count' to 'limit' in listWorkflowRunsWithPagination") + t.Log("The limit parameter controls the batch size for gh run list --limit") + t.Log("The user's -c flag controls the total number of matching runs to find") +}