Skip to content

Commit

Permalink
#276: fix duplicated PullRequestReviewEvent events
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegorov committed Aug 14, 2024
1 parent 473c102 commit e7df95c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
8 changes: 8 additions & 0 deletions judges/github-events/github-events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
64 changes: 63 additions & 1 deletion test/judges/test-github-events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit e7df95c

Please sign in to comment.