-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change commit_range workers up to be no longer classified
- Loading branch information
Showing
24 changed files
with
328 additions
and
364 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
app/workers/commit_monitor_handlers/branch_mergeability_checker.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 53 additions & 57 deletions
110
app/workers/commit_monitor_handlers/bugzilla_commenter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,73 @@ | ||
module CommitMonitorHandlers | ||
module CommitRange | ||
class BugzillaCommenter | ||
include Sidekiq::Worker | ||
sidekiq_options :queue => :miq_bot | ||
class CommitMonitorHandlers::BugzillaCommenter | ||
include Sidekiq::Worker | ||
sidekiq_options :queue => :miq_bot | ||
|
||
include BranchWorkerMixin | ||
include BranchWorkerMixin | ||
|
||
def self.handled_branch_modes | ||
[:regular] | ||
end | ||
def self.handled_branch_modes | ||
[:regular] | ||
end | ||
|
||
attr_reader :commit, :message | ||
attr_reader :commit, :message | ||
|
||
def perform(branch_id, new_commits) | ||
return unless find_branch(branch_id, :regular) | ||
def perform(branch_id, new_commits) | ||
return unless find_branch(branch_id, :regular) | ||
|
||
bugs = Hash.new { |h, k| h[k] = [] } | ||
bugs = Hash.new { |h, k| h[k] = [] } | ||
|
||
new_commits.each do |commit| | ||
message = repo.git_service.commit(commit).full_message | ||
BugzillaService.search_in_message(message).each do |bug| | ||
bugs[bug[:bug_id]] << bug.merge(:commit => commit, :commit_message => message) | ||
end | ||
end | ||
new_commits.each do |commit| | ||
message = repo.git_service.commit(commit).full_message | ||
BugzillaService.search_in_message(message).each do |bug| | ||
bugs[bug[:bug_id]] << bug.merge(:commit => commit, :commit_message => message) | ||
end | ||
end | ||
|
||
bugs.each do |bug_id, info| | ||
resolved = info.any? { |i| i[:resolution] } | ||
comment_parts = info.collect { |i| format_comment_part(i[:commit], i[:commit_message]) } | ||
comments = build_comments(comment_parts) | ||
bugs.each do |bug_id, info| | ||
resolved = info.any? { |i| i[:resolution] } | ||
comment_parts = info.collect { |i| format_comment_part(i[:commit], i[:commit_message]) } | ||
comments = build_comments(comment_parts) | ||
|
||
update_bugzilla_status(bug_id, comments, resolved) | ||
end | ||
end | ||
update_bugzilla_status(bug_id, comments, resolved) | ||
end | ||
end | ||
|
||
private | ||
private | ||
|
||
def update_bugzilla_status(bug_id, comments, resolution) | ||
logger.info "Adding #{"comment".pluralize(comments.size)} to bug #{bug_id}." | ||
def update_bugzilla_status(bug_id, comments, resolution) | ||
logger.info "Adding #{"comment".pluralize(comments.size)} to bug #{bug_id}." | ||
|
||
BugzillaService.call do |service| | ||
service.with_bug(bug_id) do |bug| | ||
break if bug.nil? | ||
BugzillaService.call do |service| | ||
service.with_bug(bug_id) do |bug| | ||
break if bug.nil? | ||
|
||
comments.each { |comment| bug.add_comment(comment) } | ||
update_bug_status(bug) if resolution | ||
bug.save | ||
end | ||
end | ||
comments.each { |comment| bug.add_comment(comment) } | ||
update_bug_status(bug) if resolution | ||
bug.save | ||
end | ||
end | ||
end | ||
|
||
def message_header(messages) | ||
@message_header ||= "New #{"commit".pluralize(messages.size)} detected on #{fq_repo_name}/#{branch.name}:\n\n" | ||
end | ||
def message_header(messages) | ||
@message_header ||= "New #{"commit".pluralize(messages.size)} detected on #{fq_repo_name}/#{branch.name}:\n\n" | ||
end | ||
|
||
def build_comments(messages) | ||
message_builder = BugzillaService::MessageBuilder.new(message_header(messages)) | ||
messages.each { |m| message_builder.write("#{m}\n\n\n") } | ||
message_builder.comments | ||
end | ||
def build_comments(messages) | ||
message_builder = BugzillaService::MessageBuilder.new(message_header(messages)) | ||
messages.each { |m| message_builder.write("#{m}\n\n\n") } | ||
message_builder.comments | ||
end | ||
|
||
def format_comment_part(commit, message) | ||
"#{branch.commit_uri_to(commit)}\n#{message}" | ||
end | ||
def format_comment_part(commit, message) | ||
"#{branch.commit_uri_to(commit)}\n#{message}" | ||
end | ||
|
||
def update_bug_status(bug) | ||
case bug.status | ||
when "NEW", "ASSIGNED", "ON_DEV" | ||
logger.info "Changing status of bug #{bug.id} to POST." | ||
bug.status = "POST" | ||
else | ||
logger.info "Not changing status of bug #{bug.id} due to status of #{bug.status}" | ||
end | ||
end | ||
def update_bug_status(bug) | ||
case bug.status | ||
when "NEW", "ASSIGNED", "ON_DEV" | ||
logger.info "Changing status of bug #{bug.id} to POST." | ||
bug.status = "POST" | ||
else | ||
logger.info "Not changing status of bug #{bug.id} due to status of #{bug.status}" | ||
end | ||
end | ||
end |
108 changes: 52 additions & 56 deletions
108
app/workers/commit_monitor_handlers/bugzilla_pr_checker.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,68 @@ | ||
module CommitMonitorHandlers | ||
module CommitRange | ||
class BugzillaPrChecker | ||
include Sidekiq::Worker | ||
sidekiq_options :queue => :miq_bot | ||
class CommitMonitorHandlers::BugzillaPrChecker | ||
include Sidekiq::Worker | ||
sidekiq_options :queue => :miq_bot | ||
|
||
include BranchWorkerMixin | ||
include BranchWorkerMixin | ||
|
||
def self.handled_branch_modes | ||
[:pr] | ||
end | ||
def self.handled_branch_modes | ||
[:pr] | ||
end | ||
|
||
def perform(branch_id, new_commits) | ||
return unless find_branch(branch_id, :pr) | ||
def perform(branch_id, new_commits) | ||
return unless find_branch(branch_id, :pr) | ||
|
||
bug_ids = new_commits.flat_map do |commit| | ||
message = repo.git_service.commit(commit).full_message | ||
BugzillaService.ids_in_git_commit_message(message) | ||
end | ||
bug_ids = new_commits.flat_map do |commit| | ||
message = repo.git_service.commit(commit).full_message | ||
BugzillaService.ids_in_git_commit_message(message) | ||
end | ||
|
||
bug_ids.uniq.each do |bug_id| | ||
update_bugzilla_status(bug_id) | ||
end | ||
end | ||
bug_ids.uniq.each do |bug_id| | ||
update_bugzilla_status(bug_id) | ||
end | ||
end | ||
|
||
private | ||
private | ||
|
||
def update_bugzilla_status(bug_id) | ||
BugzillaService.call do |service| | ||
service.with_bug(bug_id) do |bug| | ||
break if bug.nil? | ||
def update_bugzilla_status(bug_id) | ||
BugzillaService.call do |service| | ||
service.with_bug(bug_id) do |bug| | ||
break if bug.nil? | ||
|
||
add_pr_comment(bug) | ||
update_bug_status(bug) | ||
bug.save | ||
end | ||
end | ||
add_pr_comment(bug) | ||
update_bug_status(bug) | ||
bug.save | ||
end | ||
end | ||
end | ||
|
||
def add_pr_comment(bug) | ||
if bug_has_pr_uri_comment?(bug) | ||
logger.info "Not commenting on bug #{bug.id} due to duplicate comment." | ||
return | ||
end | ||
def add_pr_comment(bug) | ||
if bug_has_pr_uri_comment?(bug) | ||
logger.info "Not commenting on bug #{bug.id} due to duplicate comment." | ||
return | ||
end | ||
|
||
case bug.status | ||
when "NEW", "ASSIGNED", "ON_DEV" | ||
logger.info "Adding comment to bug #{bug.id}." | ||
bug.add_comment(@branch.github_pr_uri) | ||
else | ||
logger.info "Not commenting on bug #{bug.id} due to status of #{bug.status}" | ||
end | ||
end | ||
case bug.status | ||
when "NEW", "ASSIGNED", "ON_DEV" | ||
logger.info "Adding comment to bug #{bug.id}." | ||
bug.add_comment(@branch.github_pr_uri) | ||
else | ||
logger.info "Not commenting on bug #{bug.id} due to status of #{bug.status}" | ||
end | ||
end | ||
|
||
def bug_has_pr_uri_comment?(bug) | ||
bug.comments.any? do |c| | ||
c.text.include?(@branch.github_pr_uri) | ||
end | ||
end | ||
def bug_has_pr_uri_comment?(bug) | ||
bug.comments.any? do |c| | ||
c.text.include?(@branch.github_pr_uri) | ||
end | ||
end | ||
|
||
def update_bug_status(bug) | ||
case bug.status | ||
when "NEW", "ASSIGNED" | ||
logger.info "Changing status of bug #{bug.id} to ON_DEV." | ||
bug.status = "ON_DEV" | ||
else | ||
logger.info "Not changing status of bug #{bug.id} due to status of #{bug.status}" | ||
end | ||
end | ||
def update_bug_status(bug) | ||
case bug.status | ||
when "NEW", "ASSIGNED" | ||
logger.info "Changing status of bug #{bug.id} to ON_DEV." | ||
bug.status = "ON_DEV" | ||
else | ||
logger.info "Not changing status of bug #{bug.id} due to status of #{bug.status}" | ||
end | ||
end | ||
end |
94 changes: 46 additions & 48 deletions
94
app/workers/commit_monitor_handlers/github_pr_commenter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,65 @@ | ||
module CommitMonitorHandlers::CommitRange | ||
class GithubPrCommenter | ||
include Sidekiq::Worker | ||
sidekiq_options :queue => :miq_bot_glacial | ||
class CommitMonitorHandlers::GithubPrCommenter | ||
include Sidekiq::Worker | ||
sidekiq_options :queue => :miq_bot_glacial | ||
|
||
include BatchJobWorkerMixin | ||
include BranchWorkerMixin | ||
include BatchJobWorkerMixin | ||
include BranchWorkerMixin | ||
|
||
def self.batch_workers | ||
[DiffContentChecker, DiffFilenameChecker] | ||
end | ||
def self.batch_workers | ||
[DiffContentChecker, DiffFilenameChecker] | ||
end | ||
|
||
def self.handled_branch_modes | ||
[:pr] | ||
end | ||
def self.handled_branch_modes | ||
[:pr] | ||
end | ||
|
||
def perform(batch_job_id, branch_id, _new_commits) | ||
return unless find_batch_job(batch_job_id) | ||
return skip_batch_job unless find_branch(branch_id, :pr) | ||
def perform(batch_job_id, branch_id, _new_commits) | ||
return unless find_batch_job(batch_job_id) | ||
return skip_batch_job unless find_branch(branch_id, :pr) | ||
|
||
replace_batch_comments | ||
complete_batch_job | ||
end | ||
replace_batch_comments | ||
complete_batch_job | ||
end | ||
|
||
private | ||
private | ||
|
||
def tag | ||
"<github-pr-commenter-batch />" | ||
end | ||
def tag | ||
"<github-pr-commenter-batch />" | ||
end | ||
|
||
def header | ||
"#{tag}Some comments on #{"commit".pluralize(commits.length)} #{commit_range_text}\n" | ||
end | ||
def header | ||
"#{tag}Some comments on #{"commit".pluralize(commits.length)} #{commit_range_text}\n" | ||
end | ||
|
||
def continuation_header | ||
"#{tag}**...continued**\n" | ||
end | ||
def continuation_header | ||
"#{tag}**...continued**\n" | ||
end | ||
|
||
def replace_batch_comments | ||
logger.info("Adding batch comment to PR #{pr_number}.") | ||
def replace_batch_comments | ||
logger.info("Adding batch comment to PR #{pr_number}.") | ||
|
||
GithubService.replace_comments(fq_repo_name, pr_number, new_comments) do |old_comment| | ||
batch_comment?(old_comment) | ||
end | ||
GithubService.replace_comments(fq_repo_name, pr_number, new_comments) do |old_comment| | ||
batch_comment?(old_comment) | ||
end | ||
end | ||
|
||
def batch_comment?(comment) | ||
comment.body.start_with?(tag) | ||
end | ||
def batch_comment?(comment) | ||
comment.body.start_with?(tag) | ||
end | ||
|
||
def new_comments | ||
return [] unless merged_results.any? | ||
def new_comments | ||
return [] unless merged_results.any? | ||
|
||
content = OffenseMessage.new | ||
content.entries = merged_results | ||
content = OffenseMessage.new | ||
content.entries = merged_results | ||
|
||
message_builder = GithubService::MessageBuilder.new(header, continuation_header) | ||
message_builder.write("") | ||
message_builder.write_lines(content.lines) | ||
message_builder.comments | ||
end | ||
message_builder = GithubService::MessageBuilder.new(header, continuation_header) | ||
message_builder.write("") | ||
message_builder.write_lines(content.lines) | ||
message_builder.comments | ||
end | ||
|
||
def merged_results | ||
@merged_results ||= batch_job.entries.collect(&:result).flatten.compact | ||
end | ||
def merged_results | ||
@merged_results ||= batch_job.entries.collect(&:result).flatten.compact | ||
end | ||
end |
Oops, something went wrong.