Skip to content

fix: combine date bounds into a single --created range expression#31514

Merged
pelikhan merged 3 commits into
mainfrom
copilot/fix-gh-aw-logs-date-range-filtering
May 11, 2026
Merged

fix: combine date bounds into a single --created range expression#31514
pelikhan merged 3 commits into
mainfrom
copilot/fix-gh-aw-logs-date-range-filtering

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 11, 2026

Bug Fix

What was the bug?

gh run list treats --created as a StringVarP (single string), so passing it multiple times only keeps the last value. listWorkflowRunsWithPagination was appending one flag per bound:

# What was being constructed — only <=END is applied; >=START is silently dropped
gh run list ... --created ">=START" --created "<=END"

# With pagination — only <BEFORE_DATE survives; StartDate is completely ignored
gh run list ... --created ">=START" --created "<=END" --created "<BEFORE_DATE"

This meant --start-date was never enforced, allowing runs from arbitrarily early dates to be returned.

How did you fix it?

Added buildCreatedFilter(startDate, endDate, beforeDate string) string that collapses all bounds into a single --created value using GitHub's range syntax:

Inputs Output
startDate + endDate start..end
startDate + beforeDate (pagination) start..(beforeDate − 1s)
startDate only >=start
endDate only <=end
beforeDate only <beforeDate

BeforeDate is an exclusive pagination cursor; one second is subtracted before using it as the inclusive upper bound in range syntax, preventing the boundary run from reappearing on the next page.

// Before: three separate --created flags, only the last survives
if opts.StartDate != "" {
    args = append(args, "--created", ">="+opts.StartDate)
}
if opts.EndDate != "" {
    args = append(args, "--created", "<="+opts.EndDate)
}
if opts.BeforeDate != "" {
    args = append(args, "--created", "<"+opts.BeforeDate)
}

// After: single expression, all bounds enforced
if createdFilter := buildCreatedFilter(opts.StartDate, opts.EndDate, opts.BeforeDate); createdFilter != "" {
    args = append(args, "--created", createdFilter)
}

Testing

Unit tests added in logs_github_api_test.go covering all bound combinations, including a dedicated regression test (TestBuildCreatedFilterStartDateAlwaysEnforced) that asserts the lower bound is always present in the emitted filter string.

Copilot AI and others added 2 commits May 11, 2026 14:45
…g bug

Replace the three separate --created flag appends in listWorkflowRunsWithPagination
with a single buildCreatedFilter helper that combines StartDate, EndDate, and BeforeDate
into one --created expression.

gh run list treats --created as a single string flag (StringVarP); supplying it multiple
times only keeps the last value, silently discarding earlier bounds. This caused runs
outside the requested --start-date/--end-date window to be returned.

The fix uses GitHub's range syntax (start..end) when both a lower and upper bound are
present. For the pagination cursor (BeforeDate, which is an exclusive upper bound), one
second is subtracted before building the inclusive range so that the boundary run is not
returned again on the next page.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix gh aw logs date-range filtering returning incorrect runs fix: combine date bounds into a single --created range expression May 11, 2026
Copilot AI requested a review from pelikhan May 11, 2026 14:46
@pelikhan pelikhan marked this pull request as ready for review May 11, 2026 15:29
Copilot AI review requested due to automatic review settings May 11, 2026 15:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes gh run list date filtering by ensuring all provided date bounds are applied via a single --created flag value (since the upstream flag only retains the last occurrence), including pagination support via an exclusive BeforeDate cursor.

Changes:

  • Added buildCreatedFilter(startDate, endDate, beforeDate string) string to collapse multiple date bounds into one GitHub-compatible range expression.
  • Updated listWorkflowRunsWithPagination to emit exactly one --created argument built from all applicable bounds.
  • Added unit tests covering all bound combinations and a regression test to ensure StartDate is never dropped.
Show a summary per file
File Description
pkg/cli/logs_github_api.go Introduces buildCreatedFilter and switches gh run list arg construction to use a single combined --created expression.
pkg/cli/logs_github_api_test.go Adds unit tests for buildCreatedFilter, including regression coverage for the original “StartDate silently dropped” bug.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 0

@pelikhan pelikhan merged commit 51381f6 into main May 11, 2026
4 checks passed
@pelikhan pelikhan deleted the copilot/fix-gh-aw-logs-date-range-filtering branch May 11, 2026 15:41
@github-actions github-actions Bot mentioned this pull request May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gh aw logs date-range filtering can return runs outside the requested window

3 participants