-
Notifications
You must be signed in to change notification settings - Fork 245
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
Removing old bitbucket pull request commits #421
base: master
Are you sure you want to change the base?
Changes from all commits
a3dbb9b
7c6f84e
89f4a1d
335624e
7db5488
9517ae8
519652e
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 |
---|---|---|
@@ -1,6 +1,27 @@ | ||
module Pronto | ||
module Formatter | ||
class BitbucketPullRequestFormatter < PullRequestFormatter | ||
def format(messages, repo, patches) | ||
client = client_module.new(repo) | ||
existing = existing_comments(messages, client, repo) | ||
comments = new_comments(messages, patches) | ||
additions = remove_duplicate_comments(existing, comments) | ||
|
||
remove_comments(client, existing, comments) if existing.any? | ||
|
||
submit_comments(client, additions) | ||
|
||
approve_pull_request(comments.count, additions.count, client) if defined?(approve_pull_request) | ||
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. Why do you need to check this? It's defined below. |
||
|
||
"#{additions.count} Pronto messages posted to #{pretty_name}" | ||
end | ||
|
||
def remove_comments(client, existing, comments) | ||
removed_comments = dedupe_comments(ungrouped_comments(comments), | ||
ungrouped_comments(existing)) | ||
removed_comments.map { |c| client.delete_comment(c.client_id) } | ||
end | ||
|
||
def client_module | ||
Bitbucket | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,12 @@ def grouped_comments(comments) | |
comments.group_by { |comment| [comment.path, comment.position] } | ||
end | ||
|
||
def ungrouped_comments(comments) | ||
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. I don't see why this should be in |
||
return [] unless comments.any? | ||
|
||
comments.values.flatten | ||
end | ||
|
||
def consolidate_comments(comments) | ||
comment = comments.first | ||
if comments.length > 1 | ||
|
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.
This should be optional. I'm not sure how we'd go about it, maybe a separate
PullRequestFormatter
which deletes comments?