Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skips issue opened/closed event duplicates #294

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions judges/github-events/github-events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ def self.comments_info(pr)
}
end

def self.issue_seen_already?(fact)
Fbe.fb.query(
"(and (eq repository #{fact.repository}) " \
Copy link
Member

Choose a reason for hiding this comment

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

@tank-bohr don't forget about where, it should be set to github. We may have GitLab, for example, in the same factbase.

Copy link
Contributor

Choose a reason for hiding this comment

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

@yegor256 But can we handle the events of gitlab in a file that called github - judges/github-events/github-events.rb ?

Copy link
Contributor

Choose a reason for hiding this comment

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

@Yegorov In the github-events file, we process events only from github, I think it is proposed to put a filter only on events from github like eq where 'github', so as not to accidentally receive events from gitlab, for example

Copy link
Contributor

Choose a reason for hiding this comment

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

@Suban05 @yegor256 ok, understood (the search was taking place in the general storage Fbe.fb).
Then maybe there is the same check should be done here - #278

'(eq where "github") ' \
"(not (eq event_id #{fact.event_id}))" \
"(eq what \"#{fact.what}\") " \
"(eq issue #{fact.issue}))"
).each.any?
end

def self.count_appreciated_comments(pr, issue_comments, code_comments)
issue_appreciations =
issue_comments.sum do |comment|
Expand Down Expand Up @@ -205,6 +215,7 @@ def self.fill_up_event(fact, json)
else
skip_event(json)
end
skip_event(json) if issue_seen_already?(fact)

when 'IssueCommentEvent'
fact.issue = json[:payload][:issue][:number]
Expand Down
136 changes: 136 additions & 0 deletions test/judges/test-github-events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,142 @@ def test_skip_event_when_user_equals_pr_author
assert_nil(f[1])
end

def test_skip_issue_was_opened_event
WebMock.disable_net_connect!
stub_request(:get, 'https://api.github.com/repos/foo/foo').to_return(
body: { id: 42, full_name: 'foo/foo' }.to_json, headers: {
'content-type': 'application/json'
}
)
stub_request(:get, 'https://api.github.com/repositories/42').to_return(
body: { id: 42, full_name: 'foo/foo' }.to_json, headers: {
'content-type': 'application/json'
}
)
stub_request(:get, 'https://api.github.com/repositories/42/events?per_page=100').to_return(
body: [
{
id: 40_623_323_541,
type: 'IssuesEvent',
public: true,
created_at: '2024-07-31 12:45:09 UTC',
actor: {
id: 42,
login: 'yegor256',
display_login: 'yegor256',
gravatar_id: '',
url: 'https://api.github.com/users/yegor256'
},
repo: {
id: 42,
name: 'yegor256/judges',
url: 'https://api.github.com/repos/yegor256/judges'
},
payload: {
action: 'opened',
issue: {
number: 1347,
state: 'open',
title: 'Found a bug',
body: "I'm having a problem with this."
}
}
}
].to_json,
headers: {
'content-type': 'application/json'
}
)
stub_request(:get, 'https://api.github.com/user/42').to_return(
body: { id: 42, login: 'torvalds' }.to_json, headers: {
'content-type': 'application/json'
}
)
stub_request(:get, 'https://api.github.com/repos/yegor256/judges/issues/1347').to_return(
status: 200,
body: { number: 1347, state: 'open' }.to_json,
headers: { 'content-type': 'application/json' }
)
fb = Factbase.new
op = fb.insert
op.event_id = 100_500
op.what = 'issue-was-opened'
op.where = 'github'
op.repository = 42
op.issue = 1347
load_it('github-events', fb)
f = fb.query('(eq what "issue-was-opened")').each.to_a
assert_equal(1, f.length)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

@tank-bohr Maybe need add test for issue-was-closed case

Copy link
Contributor

Choose a reason for hiding this comment

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

@tank-bohr I agree with @Yegorov. We need a test for issue-was-closed case


def test_skip_issue_was_closed_event
WebMock.disable_net_connect!
stub_request(:get, 'https://api.github.com/repos/foo/foo').to_return(
body: { id: 42, full_name: 'foo/foo' }.to_json, headers: {
'content-type': 'application/json'
}
)
stub_request(:get, 'https://api.github.com/repositories/42').to_return(
body: { id: 42, full_name: 'foo/foo' }.to_json, headers: {
'content-type': 'application/json'
}
)
stub_request(:get, 'https://api.github.com/repositories/42/events?per_page=100').to_return(
body: [
{
id: 40_623_323_541,
type: 'IssuesEvent',
public: true,
created_at: '2024-07-31 12:45:09 UTC',
actor: {
id: 42,
login: 'yegor256',
display_login: 'yegor256',
gravatar_id: '',
url: 'https://api.github.com/users/yegor256'
},
repo: {
id: 42,
name: 'yegor256/judges',
url: 'https://api.github.com/repos/yegor256/judges'
},
payload: {
action: 'closed',
issue: {
number: 1347,
state: 'closed',
title: 'Found a bug',
body: "I'm having a problem with this."
}
}
}
].to_json,
headers: {
'content-type': 'application/json'
}
)
stub_request(:get, 'https://api.github.com/user/42').to_return(
body: { id: 42, login: 'torvalds' }.to_json, headers: {
'content-type': 'application/json'
}
)
stub_request(:get, 'https://api.github.com/repos/yegor256/judges/issues/1347').to_return(
status: 200,
body: { number: 1347, state: 'closed' }.to_json,
headers: { 'content-type': 'application/json' }
)
fb = Factbase.new
op = fb.insert
op.event_id = 100_500
op.what = 'issue-was-closed'
op.where = 'github'
op.repository = 42
op.issue = 1347
load_it('github-events', fb)
f = fb.query('(eq what "issue-was-closed")').each.to_a
assert_equal(1, f.length)
end

def test_watch_pull_request_review_events
WebMock.disable_net_connect!
stub_request(:get, 'https://api.github.com/repos/foo/foo').to_return(
Expand Down