From 6c0e4d86563c21cf116b397830f7ac2a07a63ff0 Mon Sep 17 00:00:00 2001 From: devil Date: Tue, 6 Oct 2026 06:25:07 +0000 Subject: [PATCH 1/2] #1435: give every item of the fake search its state, closed_at and user, and a pull_request to every pull --- lib/fbe/fake_octokit.rb | 151 +++++++++++++++++++++++----------------- 1 file changed, 88 insertions(+), 63 deletions(-) diff --git a/lib/fbe/fake_octokit.rb b/lib/fbe/fake_octokit.rb index 20f1141a..3b893c3d 100644 --- a/lib/fbe/fake_octokit.rb +++ b/lib/fbe/fake_octokit.rb @@ -768,70 +768,95 @@ def create_commit_comment(_repo, sha, text) } end + # Searches issues and pull requests. + # + # Every item carries +state+, +closed_at+ and +user+, the way GitHub answers: + # +closed_at+ is set only when the query asks for +closed:+ or +is:closed+, + # and every item of a +type:pr+ query has a +pull_request+ object. + # + # @param [String] query The search query + # @param [Hash] _options Additional options (not used in mock) + # @return [Hash] The total count and the items found + # @example + # client.search_issues('repo:foo/bar type:issue closed:>2024-08-01')[:items].first[:closed_at] + # # => 2024-08-21 19:00:00 UTC def search_issues(query, _options = {}) - if query.include?('type:pr') && query.include?('is:unmerged') - { - total_count: 1, - incomplete_results: false, - items: [ - { - id: 42, - number: 10, - title: 'Awesome PR 10' - } - ] - } - elsif query.include?('type:pr') && query.include?('is:merged') - { - total_count: 1, - incomplete_results: false, - items: [ - { - id: 42, - number: 10, - title: 'Awesome PR 10', - created_at: Time.parse('2024-08-21 19:00:00 UTC'), - pull_request: { merged_at: Time.parse('2024-08-23 19:00:00 UTC') } - } - ] - } - elsif query.include?('type:pr') - { - total_count: 2, - incomplete_results: false, - items: [ - { - id: 42, - number: 10, - title: 'Awesome PR 10', - created_at: Time.parse('2024-08-21 19:00:00 UTC') - }, - { - id: 43, - number: 11, - title: 'Awesome PR 11', - created_at: Time.parse('2024-08-21 20:00:00 UTC') - } - ] - } - else - { - total_count: 1, - incomplete_results: false, - items: [ - { - number: 42, - labels: [ - { - name: 'bug' - } - ], - user: { login: 'yegor256', id: 526_301, type: 'User' }, - created_at: Time.parse('2024-08-20 19:00:00 UTC') - } - ] - } - end + found = + if query.include?('type:pr') && query.include?('is:unmerged') + { + total_count: 1, + incomplete_results: false, + items: [ + { + id: 42, + number: 10, + title: 'Awesome PR 10' + } + ] + } + elsif query.include?('type:pr') && query.include?('is:merged') + { + total_count: 1, + incomplete_results: false, + items: [ + { + id: 42, + number: 10, + title: 'Awesome PR 10', + created_at: Time.parse('2024-08-21 19:00:00 UTC'), + pull_request: { merged_at: Time.parse('2024-08-23 19:00:00 UTC') } + } + ] + } + elsif query.include?('type:pr') + { + total_count: 2, + incomplete_results: false, + items: [ + { + id: 42, + number: 10, + title: 'Awesome PR 10', + created_at: Time.parse('2024-08-21 19:00:00 UTC') + }, + { + id: 43, + number: 11, + title: 'Awesome PR 11', + created_at: Time.parse('2024-08-21 20:00:00 UTC') + } + ] + } + else + { + total_count: 1, + incomplete_results: false, + items: [ + { + number: 42, + labels: [ + { + name: 'bug' + } + ], + user: { login: 'yegor256', id: 526_301, type: 'User' }, + created_at: Time.parse('2024-08-20 19:00:00 UTC') + } + ] + } + end + closed = query.include?('closed:') || query.include?('is:closed') + found.merge( + items: found[:items].map do |i| + item = { + state: closed ? 'closed' : 'open', + closed_at: (i.dig(:pull_request, :merged_at) || Time.parse('2024-08-24 19:00:00 UTC') if closed), + user: { login: 'yegor256', id: 526_301, type: 'User' } + }.merge(i) + item[:pull_request] ||= { merged_at: nil } if query.include?('type:pr') + item + end + ) end def commits_since(repo, _since) From 768eaec2b53d85e63f3de588eeb82a82057e09f9 Mon Sep 17 00:00:00 2001 From: devil Date: Tue, 6 Oct 2026 06:28:18 +0000 Subject: [PATCH 2/2] #1435: test the state, closed_at, user and pull_request of the fake search items --- test/fbe/test_octo.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/fbe/test_octo.rb b/test/fbe/test_octo.rb index 9efa8b8a..7afc79fc 100644 --- a/test/fbe/test_octo.rb +++ b/test/fbe/test_octo.rb @@ -1672,4 +1672,14 @@ def test_fake_workflow_run_always_has_status refute_nil(result[:repository], "for workflow run #{id}") end end + + def test_fake_search_closes_every_item_of_a_closed_query + found = Fbe::FakeOctokit.new.search_issues('repo:foo/bar type:issue closed:>2024-08-01')[:items] + assert_empty(found.reject { |i| i[:state] == 'closed' && i[:closed_at].is_a?(Time) && i[:user] }, found.inspect) + end + + def test_fake_search_marks_every_pull_as_a_pull + found = Fbe::FakeOctokit.new.search_issues('repo:foo/bar type:pr is:unmerged')[:items] + assert_empty(found.reject { |i| i.key?(:pull_request) && i[:state] == 'open' && i[:closed_at].nil? }, found.inspect) + end end