Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/patch-fix-logs-count-parameter.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions pkg/cli/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions pkg/cli/logs_filtering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Loading