-
Notifications
You must be signed in to change notification settings - Fork 39
Remove unnecessary unmergeable comments #415
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
Conversation
6d9bdfb
to
2f55f55
Compare
3db4203
to
23e98a0
Compare
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.
Almost perfect, great job! 👍
@@ -19,6 +19,10 @@ def tag | |||
"<pr-mergeability-checker />" | |||
end | |||
|
|||
def unmergeable_comment | |||
"#{tag}This pull request is not mergeable. Please rebase and repush." |
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.
t(w)oo (many) spaces here
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.
The change of this string will affect older pull requests - ignore them. It will be working only for new ones which will have this "new" string without "two" spaces due to the string comparison at this line in remove_comments
method.
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.
@europ I'd rather fix the line here, and leave the older PR comments as they are. But try asking in https://gitter.im/ManageIQ/miq_bot
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.
I'm fine with orphaning old comments but I am also fine with one or two spaces after a period. It's cute to have the legacy of typewriters still around via the two space after periods 😆
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.
In other words, I'm more in favor of getting this merged than worrying about semantics.
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.
Agreed...only worry about the "new" comments moving forward.
GithubService.issue_comments(fq_repo_name, branch.pr_number).select do |com| | ||
com.user.login == Settings.github_credentials.username && com.body.eql?(unmergeable_comment) | ||
end.map(&:id) | ||
) |
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.
Can you move out the block above to a variable so you don't have the weird )
at the end?
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.
I think the usage of this "one" variable at this point is useless. It will just help with the code readability.
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.
remove_label | ||
end | ||
|
||
# Update columns directly to avoid collisions wrt the serialized column issue | ||
branch.update_columns(:mergeable => currently_mergeable) | ||
end | ||
|
||
def remove_comments | ||
comment_ids = GithubService.issue_comments(fq_repo_name, branch.pr_number).select do |com| | ||
com.user.login == Settings.github_credentials.username && com.body.eql?(unmergeable_comment) |
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.
Only look for the leading tag and not the entire string. The purpose of the tag is to allow us to change the string at any time while still allowing the comment finder to work.
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.
See above
Except for label deletion the bot deletes the comments describing unmergeable status.
@Fryguy I keep the |
Checked commit europ@665c5fc with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
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.
LGTM
com.user.login == Settings.github_credentials.username && com.body.start_with?(tag) | ||
end.map(&:id) | ||
|
||
GithubService.delete_comments(fq_repo_name, comment_ids) |
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.
One quick comment...what happens if there aren't any ids (i.e. it didn't find any comments). Does this just ignore that?
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.
No action is performed.
From: /root/miq_bot/app/workers/pr_mergeability_checker.rb @ line 46 PrMergeabilityChecker#remove_comments:
45: def remove_comments
=> 46: binding.pry
47: comment_ids = GithubService.issue_comments(fq_repo_name, branch.pr_number).select do |com|
48: com.user.login == Settings.github_credentials.username && com.body.start_with?(tag)
49: end.map(&:id)
50:
51: GithubService.delete_comments(fq_repo_name, comment_ids)
52: end
[22] pry(#<PrMergeabilityChecker>)> comment_ids = GithubService.issue_comments(fq_repo_name, branch.pr_number).select do |com|
[22] pry(#<PrMergeabilityChecker>)* com.user.login == Settings.github_credentials.username && com.body.start_with?(tag)
[22] pry(#<PrMergeabilityChecker>)* end.map(&:id)
I, [2018-04-21T22:59:51.679438 #13620] INFO -- : Executed GET https://api.github.com/repos/xtest123/testrepo/issues/4/comments?per_page=100...api calls remaining 4912
=> [383854765]
[23] pry(#<PrMergeabilityChecker>)> comment_ids
=> [383854765]
[24] pry(#<PrMergeabilityChecker>)> GithubService.delete_comments(fq_repo_name, comment_ids)
I, [2018-04-21T23:00:01.528455 #13620] INFO -- : Executed DELETE https://api.github.com/repos/xtest123/testrepo/issues/comments/383854765...api calls remaining 4911
=> [383854765]
[25] pry(#<PrMergeabilityChecker>)> comment_ids = GithubService.issue_comments(fq_repo_name, branch.pr_number).select do |com|
[25] pry(#<PrMergeabilityChecker>)* com.user.login == Settings.github_credentials.username && com.body.start_with?(tag)
[25] pry(#<PrMergeabilityChecker>)* end.map(&:id)
I, [2018-04-21T23:00:21.684062 #13620] INFO -- : Executed GET https://api.github.com/repos/xtest123/testrepo/issues/4/comments?per_page=100...api calls remaining 4909
=> []
[26] pry(#<PrMergeabilityChecker>)> comment_ids
=> []
[27] pry(#<PrMergeabilityChecker>)> GithubService.delete_comments(fq_repo_name, comment_ids)
=> []
Except of label deletion the bot also deletes the comments describing unmergeable status of the pull request.
Comments to delete (example):
\cc
@skateman
@romanblanco