-
Notifications
You must be signed in to change notification settings - Fork 5
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,14 @@ def self.comments_info(pr) | |
} | ||
end | ||
|
||
def self.issue_event_exists?(fact, what) | ||
Fbe.fb.query( | ||
"(and (eq repository #{fact.repository}) " \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tank-bohr don't forget about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yegor256 But can we handle the events of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yegorov In the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
"(eq what \"#{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| | ||
|
@@ -197,9 +205,11 @@ def self.fill_up_event(fact, json) | |
fact.issue = json[:payload][:issue][:number] | ||
case json[:payload][:action] | ||
when 'closed' | ||
skip_event(json) if issue_event_exists?(fact, 'issue-was-closed') | ||
fact.what = 'issue-was-closed' | ||
fact.details = "The issue #{Fbe.issue(fact)} has been closed by #{Fbe.who(fact)}." | ||
when 'opened' | ||
skip_event(json) if issue_event_exists?(fact, 'issue-was-opened') | ||
fact.what = 'issue-was-opened' | ||
fact.details = "The issue #{Fbe.issue(fact)} has been opened by #{Fbe.who(fact)}." | ||
else | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,6 +240,138 @@ 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: '40623323541', | ||
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.what = 'issue-was-opened' | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tank-bohr Maybe need add test for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tank-bohr I agree with @Yegorov. We need a test for |
||
|
||
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: '40623323541', | ||
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.what = 'issue-was-closed' | ||
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( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tank-bohr The
self.issue_event_exists?
method checks whether an issue exists or not, but based on the name of the method, it seems that the method is checking for the existence of an event in an issue. What about the nameself.issue_exists?
?@Yegorov What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Suban05 I find it difficult to comment, but the event is called
IssuesEvent
, but on the other hand, an issue is being processed here.@yegor256 what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Yegorov I would call it
self.issue_seen_already?(fact, what)
, since we are checking the presence of a fact with the givenwhat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yegor256
issue_seen_already?
- readable name.@Suban05 @yegor256 What do you think if call
issue_seen_already?
method after getwhat
fact, we may not use the last argument in this method. For example:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Yegorov excellent idea! Maybe, we can do this checking at the end of the entire processing of all events? We don't want to have duplicates with any of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yegor256 Good point, as an option I think yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Yegorov yes, perfect, it looks much better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we set
what
before checking the factbase, will theissue_seen_already?
find this fact exactly?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tank-bohr good point. You can do this:
You should get a count of facts that satisfy the
(and ...)
term. If thecount
is larger than1
, you can doskip_event
.You can also do a simple Ruby counting: