From e7df95c4fa7f9e1d860fe1a59f623debaba4aae2 Mon Sep 17 00:00:00 2001 From: Artem Yegorov Date: Tue, 13 Aug 2024 20:53:51 +0300 Subject: [PATCH] #276: fix duplicated PullRequestReviewEvent events --- judges/github-events/github-events.rb | 8 ++++ test/judges/test-github-events.rb | 64 ++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/judges/github-events/github-events.rb b/judges/github-events/github-events.rb index 58e5d903..e542e226 100644 --- a/judges/github-events/github-events.rb +++ b/judges/github-events/github-events.rb @@ -133,6 +133,14 @@ def self.fill_up_event(fact, json) case json[:payload][:action] when 'created' skip_event(json) if json[:payload][:pull_request][:user][:id].to_i == fact.who + if Fbe.fb.query( + "(and (eq repository #{fact.repository}) " \ + '(eq what "pull-was-reviewed") ' \ + "(eq who #{fact.who}) " \ + "(eq issue #{json[:payload][:pull_request][:number]}))" + ).each.last + skip_event(json) + end fact.issue = json[:payload][:pull_request][:number] fact.what = 'pull-was-reviewed' diff --git a/test/judges/test-github-events.rb b/test/judges/test-github-events.rb index efd3cb15..7e52a47f 100644 --- a/test/judges/test-github-events.rb +++ b/test/judges/test-github-events.rb @@ -365,6 +365,63 @@ def test_watch_pull_request_review_events } } } + }, + { + id: '40623323550', + type: 'PullRequestReviewEvent', + public: true, + created_at: '2024-07-31 12:45:09 UTC', + actor: { + id: 55, + login: 'Yegorov', + display_login: 'yegorov', + gravatar_id: '', + url: 'https://api.github.com/users/yegorov' + }, + repo: { + id: 42, + name: 'yegor256/judges', + url: 'https://api.github.com/repos/yegor256/judges' + }, + payload: { + action: 'created', + review: { + id: 2_210_067_609, + node_id: 'PRR_kwDOL6GCO86DuvSZ', + user: { + login: 'yegorov', + id: 42, + node_id: 'MDQ6VXNlcjUyNjMwMQ==', + type: 'User' + }, + pull_request_url: 'https://api.github.com/repos/yegor256/judges/pulls/93', + author_association: 'OWNER', + _links: { + html: { + href: 'https://github.com/yegor256/judges/pull/93#pullrequestreview-2210067609' + }, + pull_request: { + href: 'https://api.github.com/repos/yegor256/judges/pulls/93' + } + } + }, + pull_request: { + url: 'https://api.github.com/repos/yegor256/judges/pulls/93', + id: 1_990_323_155, + node_id: 'PR_kwDOL6GCO852oevG', + number: 93, + state: 'open', + locked: false, + title: 'allows to push gizpped factbase', + user: { + login: 'test', + id: 526_200, + node_id: 'MDQ6VXNlcjE2NDYwMjA=', + type: 'User', + site_admin: false + } + } + } } ].to_json, headers: { @@ -376,6 +433,11 @@ def test_watch_pull_request_review_events 'content-type': 'application/json' } ) + stub_request(:get, 'https://api.github.com/user/55').to_return( + body: { id: 55, login: 'torvalds' }.to_json, headers: { + 'content-type': 'application/json' + } + ) stub_request(:get, 'https://api.github.com/repos/yegor256/judges/pulls/93') .to_return( status: 200, @@ -395,7 +457,7 @@ def test_watch_pull_request_review_events f = fb.query('(eq what "pull-was-reviewed")').each.to_a assert_equal(2, f.count) assert_equal(42, f.first.who) - assert_equal(42, f[1].who) + assert_equal(55, f.last.who) end def test_release_event_contributors