Skip to content

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

Merged
merged 1 commit into from
May 8, 2018
Merged

Conversation

europ
Copy link
Member

@europ europ commented Mar 22, 2018

Except of label deletion the bot also deletes the comments describing unmergeable status of the pull request.

Comments to delete (example):

image

\cc
@skateman
@romanblanco

@miq-bot miq-bot added the wip label Mar 22, 2018
@europ europ changed the title [WIP] Remove unnecessary unmergeable comments Remove unnecessary unmergeable comments Mar 22, 2018
@miq-bot miq-bot removed the wip label Mar 22, 2018
@europ europ force-pushed the unmerg_coms branch 2 times, most recently from 6d9bdfb to 2f55f55 Compare March 22, 2018 14:51
@europ europ changed the title Remove unnecessary unmergeable comments [WIP] Remove unnecessary unmergeable comments Mar 22, 2018
@miq-bot miq-bot added the wip label Mar 22, 2018
@europ europ changed the title [WIP] Remove unnecessary unmergeable comments Remove unnecessary unmergeable comments Mar 22, 2018
@miq-bot miq-bot removed the wip label Mar 22, 2018
@europ europ force-pushed the unmerg_coms branch 2 times, most recently from 3db4203 to 23e98a0 Compare March 26, 2018 12:07
Copy link
Member

@skateman skateman left a 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."
Copy link
Member

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

Copy link
Member Author

@europ europ Mar 26, 2018

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.

Copy link
Member

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

Copy link
Member

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 😆

Copy link
Member

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. :shipit:

Copy link
Member

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)
)
Copy link
Member

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?

Copy link
Member Author

@europ europ Mar 26, 2018

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.

Copy link
Member

@skateman skateman left a comment

Choose a reason for hiding this comment

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

The Seal of Approval

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)
Copy link
Member

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.

Copy link
Member

@Fryguy Fryguy left a 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.
@europ
Copy link
Member Author

europ commented Mar 26, 2018

@Fryguy I keep the unmergeable_comment method, but I changed the the original string — 2 spaces to 1 space. The remove_comments now search for a comment whose body content starts with the tag.

@miq-bot
Copy link
Member

miq-bot commented Mar 26, 2018

Checked commit europ@665c5fc with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 0 offenses detected
Everything looks fine. 🍰

Copy link
Member

@Fryguy Fryguy left a 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)
Copy link
Member

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?

Copy link
Member Author

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)
=> []

@Fryguy Fryguy merged commit 44a5441 into ManageIQ:master May 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants