From 5e2690ff7060f728a85c647a3d68a8fa7065d815 Mon Sep 17 00:00:00 2001 From: Valentine Frolov Date: Tue, 29 Sep 2026 10:39:47 +0300 Subject: [PATCH] fix(#1231): render the time bounds with getutc so the caller's time is left alone --- lib/fbe/github_graph.rb | 6 ++--- test/fbe/test_github_graph.rb | 46 +++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/lib/fbe/github_graph.rb b/lib/fbe/github_graph.rb index 444b4cf0..84ee0c0c 100644 --- a/lib/fbe/github_graph.rb +++ b/lib/fbe/github_graph.rb @@ -341,7 +341,7 @@ def pull_requests_with_reviews(owner, name, since, cursor: nil) id number updatedAt - timelineItems(first: 1, itemTypes: [PULL_REQUEST_REVIEW], since: "#{since.utc.iso8601}") { + timelineItems(first: 1, itemTypes: [PULL_REQUEST_REVIEW], since: "#{since.getutc.iso8601}") { nodes { ... on PullRequestReview { id } } @@ -463,7 +463,7 @@ def total_commits_pushed(owner, name, since, till = Time.now) defaultBranchRef { target { ... on Commit { - history(#{after}first: 100, since: "#{since.utc.iso8601}", until: "#{till.utc.iso8601}") { + history(#{after}first: 100, since: "#{since.getutc.iso8601}", until: "#{till.getutc.iso8601}") { totalCount nodes { oid @@ -507,7 +507,7 @@ def total_commits_pushed(owner, name, since, till = Time.now) # @param [Time] till The datetime to # @return [Hash] A hash with total issues and pulls def total_issues_created(owner, name, since, till = Time.now) - window = "created:#{since.utc.iso8601}..#{till.utc.iso8601}" + window = "created:#{since.getutc.iso8601}..#{till.getutc.iso8601}" result = query( <<~GRAPHQL { diff --git a/test/fbe/test_github_graph.rb b/test/fbe/test_github_graph.rb index 62a2c570..37515eff 100644 --- a/test/fbe/test_github_graph.rb +++ b/test/fbe/test_github_graph.rb @@ -1058,4 +1058,50 @@ def test_fake_total_releases_published_dont_count_after_till h = graph.total_releases_published(owner, name, since, till: since + 60) assert_equal(1, h['releases'], "the fake counts releases published after the till moment, seed: #{seed}") end + + def test_total_issues_created_keeps_the_given_since + seed = Random.new_seed + t = Time.new(2025, 1, 1, 10, 0, 0, format('+%02d:00', Random.new(seed).rand(1..12))) + g = Fbe::Graph.new(token: 'fake') + g.stub(:query, ->(_q) { {} }) { g.total_issues_created('o', 'n', t, t + 3600) } + refute_predicate(t, :utc?, "since is converted to UTC in place, seed #{seed}") + end + + def test_total_issues_created_accepts_frozen_since + t = Time.new(2025, 1, 1, 10, 0, 0, '+03:00').freeze + g = Fbe::Graph.new(token: 'fake') + h = g.stub(:query, ->(_q) { {} }) { g.total_issues_created('o', 'n', t, t + 3600) } + assert_equal(0, h['issues'], 'frozen since is refused') + end + + def test_total_issues_created_renders_the_window_in_utc + t = Time.new(2025, 1, 1, 10, 0, 0, '+03:00') + g = Fbe::Graph.new(token: 'fake') + seen = nil + g.stub(:query, ->(q) { seen = q and {} }) { g.total_issues_created('o', 'n', t, t + 3600) } + assert_includes(seen, 'created:2025-01-01T07:00:00Z..2025-01-01T08:00:00Z', 'window is not rendered in UTC') + end + + def test_total_commits_pushed_keeps_the_given_till + seed = Random.new_seed + t = Time.new(2025, 1, 1, 10, 0, 0, format('-%02d:00', Random.new(seed).rand(1..11))) + g = Fbe::Graph.new(token: 'fake') + g.stub(:query, ->(_q) { { 'repository' => {} } }) { g.total_commits_pushed('o', 'n', t - 3600, t) } + refute_predicate(t, :utc?, "till is converted to UTC in place, seed #{seed}") + end + + def test_total_commits_pushed_accepts_frozen_since + t = Time.new(2025, 1, 1, 10, 0, 0, '+03:00').freeze + g = Fbe::Graph.new(token: 'fake') + h = g.stub(:query, ->(_q) { { 'repository' => {} } }) { g.total_commits_pushed('o', 'n', t, t + 3600) } + assert_equal(0, h['commits'], 'frozen since is refused') + end + + def test_pull_requests_with_reviews_accepts_frozen_since + t = Time.new(2025, 1, 1, 10, 0, 0, '+03:00').freeze + g = Fbe::Graph.new(token: 'fake') + answer = { 'repository' => { 'pullRequests' => { 'nodes' => [], 'pageInfo' => { 'hasNextPage' => false } } } } + h = g.stub(:query, ->(_q) { answer }) { g.pull_requests_with_reviews('o', 'n', t) } + assert_empty(h['pulls_with_reviews'], 'frozen since is refused') + end end