diff --git a/app/workers/commit_monitor.rb b/app/workers/commit_monitor.rb
index e7991762..2180075e 100644
--- a/app/workers/commit_monitor.rb
+++ b/app/workers/commit_monitor.rb
@@ -1,5 +1,3 @@
-require 'yaml'
-
class CommitMonitor
include Sidekiq::Worker
sidekiq_options :queue => :miq_bot_glacial, :retry => false
@@ -9,36 +7,20 @@ class CommitMonitor
include SidekiqWorkerMixin
- # commit handlers expect to handle a specific commit at a time.
- #
- # Example: A commit message checker that will check for URLs and act upon them.
- def self.commit_handlers
- @commit_handlers ||= handlers_for(:commit)
- end
-
- # commit_range handlers expect to handle a range of commits as a group.
- #
- # Example: A style/syntax/warning checker on a PR branch, where we only want
- # to check the new commits, but as a group, since newer commits may fix
- # issues in prior commits.
- def self.commit_range_handlers
- @commit_range_handlers ||= handlers_for(:commit_range).select { |h| !h.respond_to?(:perform_batch_async) }
- end
-
- # branch handlers expect to handle an entire branch at once.
- #
- # Example: A PR branch mergability tester to see if the entire branch can be
- # merged or not.
- def self.branch_handlers
- @branch_handlers ||= handlers_for(:branch)
+ def self.handlers
+ @handlers ||= begin
+ workers_path = Rails.root.join("app/workers")
+ Dir.glob(workers_path.join("commit_monitor_handlers/*.rb")).collect do |f|
+ path = Pathname.new(f).relative_path_from(workers_path).to_s
+ path.chomp(".rb").classify.constantize
+ end
+ end
end
- # batch handlers expect to handle a batch of workers at once and will need
- # a wider range of information
- #
- # Example: A general commenter to GitHub for a number of issues
- def self.batch_handlers
- @batch_handlers ||= handlers_for(:commit_range).select { |h| h.respond_to?(:perform_batch_async) }
+ def self.handlers_for(branch)
+ handlers.select do |h|
+ h.handled_branch_modes.include?(branch.mode) && h.enabled_for?(branch.repo)
+ end
end
def perform
@@ -55,11 +37,9 @@ def process_repos
private
- attr_reader :repo, :branch, :new_commits, :all_commits, :statistics
+ attr_reader :repo, :branch, :new_commits, :all_commits
def process_repo(repo)
- @statistics = {}
-
@repo = repo
repo.git_fetch
@@ -67,7 +47,6 @@ def process_repo(repo)
sorted_branches = repo.branches.sort_by { |b| b.pull_request? ? 1 : -1 }
sorted_branches.each do |branch|
- @new_commits_details = nil
@branch = branch
process_branch
end
@@ -78,8 +57,6 @@ def process_branch
@new_commits, @all_commits = detect_commits
- statistics[branch.name] = {:new_commits => new_commits} unless branch.pull_request?
-
logger.info "Detected new commits #{new_commits}" if new_commits.any?
save_branch_record
@@ -112,17 +89,6 @@ def compare_commits_list(left, right)
{:same => same, :left_only => left_only, :right_only => right_only}
end
- def new_commits_details
- @new_commits_details ||=
- new_commits.each_with_object({}) do |commit, h|
- git_commit = branch.git_service.commit(commit)
- h[commit] = {
- "message" => git_commit.full_message,
- "files" => git_commit.diff.file_status.keys
- }
- end
- end
-
def save_branch_record
attrs = {:last_checked_on => Time.now.utc}
attrs[:last_commit] = new_commits.last if new_commits.any?
@@ -135,102 +101,10 @@ def save_branch_record
branch.update_columns(attrs)
end
- #
- # Handler processing methods
- #
-
- def self.handlers_for(type)
- workers_path = Rails.root.join("app/workers")
- Dir.glob(workers_path.join("commit_monitor_handlers/#{type}/*.rb")).collect do |f|
- path = Pathname.new(f).relative_path_from(workers_path).to_s
- path.chomp(".rb").classify.constantize
- end
- end
- private_class_method(:handlers_for)
-
- def filter_handlers(handlers)
- handlers.select do |h|
- h.handled_branch_modes.include?(branch.mode) && h.enabled_for?(repo)
- end
- end
-
- def commit_handlers
- filter_handlers(self.class.commit_handlers)
- end
-
- def commit_range_handlers
- filter_handlers(self.class.commit_range_handlers)
- end
-
- def branch_handlers
- filter_handlers(self.class.branch_handlers)
- end
-
- def batch_handlers
- filter_handlers(self.class.batch_handlers)
- end
-
def process_handlers
- process_commit_handlers if process_commit_handlers?
- process_commit_range_handlers if process_commit_range_handlers?
- process_branch_handlers if process_branch_handlers?
- process_batch_handlers if process_batch_handlers?
- end
-
- def process_commit_handlers?
- commit_handlers.any? && new_commits.any?
- end
-
- def process_commit_range_handlers?
- commit_range_handlers.any? && new_commits.any?
- end
-
- def process_branch_handlers?
- branch_handlers.any? && send("process_#{branch.mode}_branch_handlers?")
- end
-
- def process_batch_handlers?
- batch_handlers.any? && new_commits.any?
- end
-
- def process_pr_branch_handlers?
- parent_branch_new_commits = statistics.fetch_path("master", :new_commits)
- new_commits.any? || parent_branch_new_commits.any?
- end
-
- def process_regular_branch_handlers?
- new_commits.any?
- end
-
- def process_commit_handlers
- new_commits_details.each do |commit, details|
- commit_handlers.each do |h|
- logger.info("Queueing #{h.name.split("::").last} for commit #{commit} on branch #{branch.name}")
- h.perform_async(branch.id, commit, details)
- end
- end
- end
-
- def process_commit_range_handlers
- commit_range = [new_commits.first, new_commits.last].uniq.join("..")
-
- commit_range_handlers.each do |h|
- logger.info("Queueing #{h.name.split("::").last} for commit range #{commit_range} on branch #{branch.name}")
- h.perform_async(branch.id, new_commits)
- end
- end
-
- def process_branch_handlers
- branch_handlers.each do |h|
- logger.info("Queueing #{h.name.split("::").last} for branch #{branch.name}")
- h.perform_async(branch.id)
- end
- end
-
- def process_batch_handlers
- batch_handlers.each do |h|
- logger.info("Queueing #{h.name} for branch #{branch.name}")
- h.perform_batch_async(branch.id, new_commits_details)
+ self.class.handlers_for(branch).each do |handler|
+ method = handler.respond_to?(:perform_batch_async) ? :perform_batch_async : :perform_async
+ handler.public_send(method, branch.id, new_commits)
end
end
end
diff --git a/app/workers/commit_monitor_handlers/commit_range/branch_mergeability_checker.rb b/app/workers/commit_monitor_handlers/branch_mergeability_checker.rb
similarity index 86%
rename from app/workers/commit_monitor_handlers/commit_range/branch_mergeability_checker.rb
rename to app/workers/commit_monitor_handlers/branch_mergeability_checker.rb
index a7945ff2..60fcdd39 100644
--- a/app/workers/commit_monitor_handlers/commit_range/branch_mergeability_checker.rb
+++ b/app/workers/commit_monitor_handlers/branch_mergeability_checker.rb
@@ -1,4 +1,4 @@
-class CommitMonitorHandlers::CommitRange::BranchMergeabilityChecker
+class CommitMonitorHandlers::BranchMergeabilityChecker
include Sidekiq::Worker
sidekiq_options :queue => :miq_bot
diff --git a/app/workers/commit_monitor_handlers/bugzilla_commenter.rb b/app/workers/commit_monitor_handlers/bugzilla_commenter.rb
new file mode 100644
index 00000000..a2618474
--- /dev/null
+++ b/app/workers/commit_monitor_handlers/bugzilla_commenter.rb
@@ -0,0 +1,73 @@
+class CommitMonitorHandlers::BugzillaCommenter
+ include Sidekiq::Worker
+ sidekiq_options :queue => :miq_bot
+
+ include BranchWorkerMixin
+
+ def self.handled_branch_modes
+ [:regular]
+ end
+
+ attr_reader :commit, :message
+
+ def perform(branch_id, new_commits)
+ return unless find_branch(branch_id, :regular)
+
+ 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
+
+ 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
+
+ private
+
+ 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?
+
+ 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 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 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
diff --git a/app/workers/commit_monitor_handlers/bugzilla_pr_checker.rb b/app/workers/commit_monitor_handlers/bugzilla_pr_checker.rb
new file mode 100644
index 00000000..4b018b43
--- /dev/null
+++ b/app/workers/commit_monitor_handlers/bugzilla_pr_checker.rb
@@ -0,0 +1,68 @@
+class CommitMonitorHandlers::BugzillaPrChecker
+ include Sidekiq::Worker
+ sidekiq_options :queue => :miq_bot
+
+ include BranchWorkerMixin
+
+ def self.handled_branch_modes
+ [:pr]
+ end
+
+ 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.uniq.each do |bug_id|
+ update_bugzilla_status(bug_id)
+ end
+ end
+
+ private
+
+ 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
+ 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
+
+ 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
+end
diff --git a/app/workers/commit_monitor_handlers/commit_range/bugzilla_commenter.rb b/app/workers/commit_monitor_handlers/commit_range/bugzilla_commenter.rb
deleted file mode 100644
index 2e3314b5..00000000
--- a/app/workers/commit_monitor_handlers/commit_range/bugzilla_commenter.rb
+++ /dev/null
@@ -1,77 +0,0 @@
-module CommitMonitorHandlers
- module CommitRange
- class BugzillaCommenter
- include Sidekiq::Worker
- sidekiq_options :queue => :miq_bot
-
- include BranchWorkerMixin
-
- def self.handled_branch_modes
- [:regular]
- end
-
- attr_reader :commit, :message
-
- def perform(branch_id, new_commits)
- return unless find_branch(branch_id, :regular)
-
- 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
-
- 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
-
- private
-
- 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?
-
- 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 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 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
- end
-end
diff --git a/app/workers/commit_monitor_handlers/commit_range/bugzilla_pr_checker.rb b/app/workers/commit_monitor_handlers/commit_range/bugzilla_pr_checker.rb
deleted file mode 100644
index 4abf3a31..00000000
--- a/app/workers/commit_monitor_handlers/commit_range/bugzilla_pr_checker.rb
+++ /dev/null
@@ -1,72 +0,0 @@
-module CommitMonitorHandlers
- module CommitRange
- class BugzillaPrChecker
- include Sidekiq::Worker
- sidekiq_options :queue => :miq_bot
-
- include BranchWorkerMixin
-
- def self.handled_branch_modes
- [:pr]
- end
-
- 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.uniq.each do |bug_id|
- update_bugzilla_status(bug_id)
- end
- end
-
- private
-
- 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
- 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
-
- 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
- end
- end
-end
diff --git a/app/workers/commit_monitor_handlers/commit_range/github_pr_commenter.rb b/app/workers/commit_monitor_handlers/commit_range/github_pr_commenter.rb
deleted file mode 100644
index be706734..00000000
--- a/app/workers/commit_monitor_handlers/commit_range/github_pr_commenter.rb
+++ /dev/null
@@ -1,67 +0,0 @@
-module CommitMonitorHandlers::CommitRange
- class GithubPrCommenter
- include Sidekiq::Worker
- sidekiq_options :queue => :miq_bot_glacial
-
- include BatchJobWorkerMixin
- include BranchWorkerMixin
-
- def self.batch_workers
- [DiffContentChecker, DiffFilenameChecker]
- 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)
-
- replace_batch_comments
- complete_batch_job
- end
-
- private
-
- def tag
- ""
- end
-
- def header
- "#{tag}Some comments on #{"commit".pluralize(commits.length)} #{commit_range_text}\n"
- end
-
- def continuation_header
- "#{tag}**...continued**\n"
- end
-
- 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
- end
-
- def batch_comment?(comment)
- comment.body.start_with?(tag)
- end
-
- def new_comments
- return [] unless merged_results.any?
-
- 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
-
- def merged_results
- @merged_results ||= batch_job.entries.collect(&:result).flatten.compact
- end
- end
-end
diff --git a/app/workers/commit_monitor_handlers/commit_range/github_pr_commenter/diff_content_checker.rb b/app/workers/commit_monitor_handlers/commit_range/github_pr_commenter/diff_content_checker.rb
deleted file mode 100644
index 77dd687c..00000000
--- a/app/workers/commit_monitor_handlers/commit_range/github_pr_commenter/diff_content_checker.rb
+++ /dev/null
@@ -1,54 +0,0 @@
-require 'rugged'
-
-module CommitMonitorHandlers::CommitRange
- class GithubPrCommenter::DiffContentChecker
- include Sidekiq::Worker
- sidekiq_options :queue => :miq_bot
-
- include BatchEntryWorkerMixin
- include BranchWorkerMixin
-
- def perform(batch_entry_id, branch_id, _new_commits)
- return unless find_batch_entry(batch_entry_id)
- return skip_batch_entry unless find_branch(branch_id, :pr)
-
- complete_batch_entry(:result => process_lines)
- end
-
- private
-
- def process_lines
- @offenses = []
-
- check_diff_lines
-
- @offenses
- end
-
- def check_diff_lines
- branch.git_service.diff.with_each_line do |line, _parent_hunk, parent_patch|
- next unless line.addition?
- check_line(line, parent_patch)
- end
- rescue GitService::UnmergeableError
- nil # Avoid working on unmergeable PRs
- end
-
- def check_line(line, patch)
- file_path = patch.delta.new_file[:path]
- Settings.diff_content_checker.offenses.each do |offender, options|
- next if options.except.try(:any?) { |except| file_path.start_with?(except) }
-
- regexp = options.type == :regexp ? Regexp.new(offender.to_s) : /\b#{Regexp.escape(offender.to_s)}\b/i
- add_offense(offender, options, file_path, line) if regexp.match(line.content)
- end
- end
-
- def add_offense(offender, options, file_path, line)
- line_number = line.new_lineno
- message = options.message || "Detected `#{offender}`"
-
- @offenses << OffenseMessage::Entry.new(options.severity, message, file_path, line_number)
- end
- end
-end
diff --git a/app/workers/commit_monitor_handlers/commit_range/github_pr_commenter/diff_filename_checker.rb b/app/workers/commit_monitor_handlers/commit_range/github_pr_commenter/diff_filename_checker.rb
deleted file mode 100644
index df461131..00000000
--- a/app/workers/commit_monitor_handlers/commit_range/github_pr_commenter/diff_filename_checker.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-require 'rugged'
-
-module CommitMonitorHandlers::CommitRange
- class GithubPrCommenter::DiffFilenameChecker
- include Sidekiq::Worker
- sidekiq_options :queue => :miq_bot_glacial
-
- include BatchEntryWorkerMixin
- include BranchWorkerMixin
-
- def perform(batch_entry_id, branch_id, _new_commits)
- return unless find_batch_entry(batch_entry_id)
- return skip_batch_entry unless find_branch(branch_id, :pr)
-
- complete_batch_entry(:result => process_files)
- end
-
- private
-
- def process_files
- @offenses = []
-
- check_diff_files
-
- @offenses
- end
-
- def check_diff_files
- branch.git_service.diff.new_files.each do |file|
- validate_migration_timestamp(file)
- end
- rescue GitService::UnmergeableError
- nil # Avoid working on unmergeable PRs
- end
-
- def validate_migration_timestamp(file)
- return unless file.include?("db/migrate/")
- ts = File.basename(file).split("_").first
- return if valid_timestamp?(ts)
-
- @offenses << OffenseMessage::Entry.new(:error, "Bad Migration Timestamp", file)
- end
-
- def valid_timestamp?(ts)
- Time.parse(ts)
- rescue ArgumentError
- false
- end
- end
-end
diff --git a/app/workers/commit_monitor_handlers/commit_range/pivotal_pr_checker.rb b/app/workers/commit_monitor_handlers/commit_range/pivotal_pr_checker.rb
deleted file mode 100644
index 56dffceb..00000000
--- a/app/workers/commit_monitor_handlers/commit_range/pivotal_pr_checker.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-module CommitMonitorHandlers
- module CommitRange
- class PivotalPrChecker
- include Sidekiq::Worker
- sidekiq_options :queue => :miq_bot
-
- include BranchWorkerMixin
-
- def self.handled_branch_modes
- [:pr]
- end
-
- def perform(branch_id, new_commits)
- return unless find_branch(branch_id, :pr)
-
- story_ids = new_commits.flat_map do |commit|
- message = repo.git_service.commit(commit).full_message
- PivotalService.ids_in_git_commit_message(message)
- end
-
- story_ids.uniq.each do |story_id|
- update_pivotal_story(story_id)
- end
- end
-
- private
-
- def update_pivotal_story(story_id)
- PivotalService.call do |client|
- story = client.story(story_id)
- story.create_comment(:text => branch.github_pr_uri) unless already_linked?(story)
- end
- end
-
- def already_linked?(story)
- github_pr_uri?(story.description) || story.comments.any? { |comment| github_pr_uri?(comment.text) }
- end
-
- def github_pr_uri?(text)
- text.to_s.include?(branch.github_pr_uri)
- end
- end
- end
-end
diff --git a/app/workers/commit_monitor_handlers/commit_range/rubocop_checker/rubocop_results_filter.rb b/app/workers/commit_monitor_handlers/commit_range/rubocop_checker/rubocop_results_filter.rb
deleted file mode 100644
index 98a660cf..00000000
--- a/app/workers/commit_monitor_handlers/commit_range/rubocop_checker/rubocop_results_filter.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-module CommitMonitorHandlers
- module CommitRange
- class RubocopChecker
- class RubocopResultsFilter
- attr_reader :filtered
-
- def initialize(results, diff_details)
- @results = results
- @diff_details = diff_details
- @filtered = filter_rubocop_results
- end
-
- private
-
- def filter_rubocop_results
- filter_on_diff
- filter_void_warnings_in_spec_files
-
- @results["summary"]["offense_count"] =
- @results["files"].inject(0) { |sum, f| sum + f["offenses"].length }
-
- @results
- end
-
- def filter_on_diff
- @results["files"].each do |f|
- f["offenses"].select! do |o|
- o["severity"].in?(%w(error fatal)) ||
- @diff_details[f["path"]].include?(o["location"]["line"])
- end
- end
- end
-
- def filter_void_warnings_in_spec_files
- @results["files"].each do |f|
- next unless f["path"].match %r{(?:^|/)spec/.+_spec.rb}
-
- f["offenses"].reject! do |o|
- o["cop_name"].in?(%w(Void Lint/Void))
- end
- end
- end
- end
- end
- end
-end
diff --git a/app/workers/commit_monitor_handlers/github_pr_commenter.rb b/app/workers/commit_monitor_handlers/github_pr_commenter.rb
new file mode 100644
index 00000000..b3e8c720
--- /dev/null
+++ b/app/workers/commit_monitor_handlers/github_pr_commenter.rb
@@ -0,0 +1,65 @@
+class CommitMonitorHandlers::GithubPrCommenter
+ include Sidekiq::Worker
+ sidekiq_options :queue => :miq_bot_glacial
+
+ include BatchJobWorkerMixin
+ include BranchWorkerMixin
+
+ def self.batch_workers
+ [DiffContentChecker, DiffFilenameChecker]
+ 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)
+
+ replace_batch_comments
+ complete_batch_job
+ end
+
+ private
+
+ def tag
+ ""
+ end
+
+ def header
+ "#{tag}Some comments on #{"commit".pluralize(commits.length)} #{commit_range_text}\n"
+ end
+
+ def continuation_header
+ "#{tag}**...continued**\n"
+ end
+
+ 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
+ end
+
+ def batch_comment?(comment)
+ comment.body.start_with?(tag)
+ end
+
+ def new_comments
+ return [] unless merged_results.any?
+
+ 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
+
+ def merged_results
+ @merged_results ||= batch_job.entries.collect(&:result).flatten.compact
+ end
+end
diff --git a/app/workers/commit_monitor_handlers/github_pr_commenter/diff_content_checker.rb b/app/workers/commit_monitor_handlers/github_pr_commenter/diff_content_checker.rb
new file mode 100644
index 00000000..000dc63b
--- /dev/null
+++ b/app/workers/commit_monitor_handlers/github_pr_commenter/diff_content_checker.rb
@@ -0,0 +1,50 @@
+class CommitMonitorHandlers::GithubPrCommenter::DiffContentChecker
+ include Sidekiq::Worker
+ sidekiq_options :queue => :miq_bot
+
+ include BatchEntryWorkerMixin
+ include BranchWorkerMixin
+
+ def perform(batch_entry_id, branch_id, _new_commits)
+ return unless find_batch_entry(batch_entry_id)
+ return skip_batch_entry unless find_branch(branch_id, :pr)
+
+ complete_batch_entry(:result => process_lines)
+ end
+
+ private
+
+ def process_lines
+ @offenses = []
+
+ check_diff_lines
+
+ @offenses
+ end
+
+ def check_diff_lines
+ branch.git_service.diff.with_each_line do |line, _parent_hunk, parent_patch|
+ next unless line.addition?
+ check_line(line, parent_patch)
+ end
+ rescue GitService::UnmergeableError
+ nil # Avoid working on unmergeable PRs
+ end
+
+ def check_line(line, patch)
+ file_path = patch.delta.new_file[:path]
+ Settings.diff_content_checker.offenses.each do |offender, options|
+ next if options.except.try(:any?) { |except| file_path.start_with?(except) }
+
+ regexp = options.type == :regexp ? Regexp.new(offender.to_s) : /\b#{Regexp.escape(offender.to_s)}\b/i
+ add_offense(offender, options, file_path, line) if regexp.match(line.content)
+ end
+ end
+
+ def add_offense(offender, options, file_path, line)
+ line_number = line.new_lineno
+ message = options.message || "Detected `#{offender}`"
+
+ @offenses << OffenseMessage::Entry.new(options.severity, message, file_path, line_number)
+ end
+end
diff --git a/app/workers/commit_monitor_handlers/github_pr_commenter/diff_filename_checker.rb b/app/workers/commit_monitor_handlers/github_pr_commenter/diff_filename_checker.rb
new file mode 100644
index 00000000..97dcf4b9
--- /dev/null
+++ b/app/workers/commit_monitor_handlers/github_pr_commenter/diff_filename_checker.rb
@@ -0,0 +1,46 @@
+class CommitMonitorHandlers::GithubPrCommenter::DiffFilenameChecker
+ include Sidekiq::Worker
+ sidekiq_options :queue => :miq_bot_glacial
+
+ include BatchEntryWorkerMixin
+ include BranchWorkerMixin
+
+ def perform(batch_entry_id, branch_id, _new_commits)
+ return unless find_batch_entry(batch_entry_id)
+ return skip_batch_entry unless find_branch(branch_id, :pr)
+
+ complete_batch_entry(:result => process_files)
+ end
+
+ private
+
+ def process_files
+ @offenses = []
+
+ check_diff_files
+
+ @offenses
+ end
+
+ def check_diff_files
+ branch.git_service.diff.new_files.each do |file|
+ validate_migration_timestamp(file)
+ end
+ rescue GitService::UnmergeableError
+ nil # Avoid working on unmergeable PRs
+ end
+
+ def validate_migration_timestamp(file)
+ return unless file.include?("db/migrate/")
+ ts = File.basename(file).split("_").first
+ return if valid_timestamp?(ts)
+
+ @offenses << OffenseMessage::Entry.new(:error, "Bad Migration Timestamp", file)
+ end
+
+ def valid_timestamp?(ts)
+ Time.parse(ts)
+ rescue ArgumentError
+ false
+ end
+end
diff --git a/app/workers/commit_monitor_handlers/commit_range/path_based_labeler.rb b/app/workers/commit_monitor_handlers/path_based_labeler.rb
similarity index 91%
rename from app/workers/commit_monitor_handlers/commit_range/path_based_labeler.rb
rename to app/workers/commit_monitor_handlers/path_based_labeler.rb
index dc76c998..7696d835 100644
--- a/app/workers/commit_monitor_handlers/commit_range/path_based_labeler.rb
+++ b/app/workers/commit_monitor_handlers/path_based_labeler.rb
@@ -1,4 +1,4 @@
-class CommitMonitorHandlers::CommitRange::PathBasedLabeler
+class CommitMonitorHandlers::PathBasedLabeler
include Sidekiq::Worker
sidekiq_options :queue => :miq_bot
diff --git a/app/workers/commit_monitor_handlers/pivotal_pr_checker.rb b/app/workers/commit_monitor_handlers/pivotal_pr_checker.rb
new file mode 100644
index 00000000..3833f806
--- /dev/null
+++ b/app/workers/commit_monitor_handlers/pivotal_pr_checker.rb
@@ -0,0 +1,40 @@
+class CommitMonitorHandlers::PivotalPrChecker
+ include Sidekiq::Worker
+ sidekiq_options :queue => :miq_bot
+
+ include BranchWorkerMixin
+
+ def self.handled_branch_modes
+ [:pr]
+ end
+
+ def perform(branch_id, new_commits)
+ return unless find_branch(branch_id, :pr)
+
+ story_ids = new_commits.flat_map do |commit|
+ message = repo.git_service.commit(commit).full_message
+ PivotalService.ids_in_git_commit_message(message)
+ end
+
+ story_ids.uniq.each do |story_id|
+ update_pivotal_story(story_id)
+ end
+ end
+
+ private
+
+ def update_pivotal_story(story_id)
+ PivotalService.call do |client|
+ story = client.story(story_id)
+ story.create_comment(:text => branch.github_pr_uri) unless already_linked?(story)
+ end
+ end
+
+ def already_linked?(story)
+ github_pr_uri?(story.description) || story.comments.any? { |comment| github_pr_uri?(comment.text) }
+ end
+
+ def github_pr_uri?(text)
+ text.to_s.include?(branch.github_pr_uri)
+ end
+end
diff --git a/app/workers/commit_monitor_handlers/commit_range/rubocop_checker.rb b/app/workers/commit_monitor_handlers/rubocop_checker.rb
similarity index 93%
rename from app/workers/commit_monitor_handlers/commit_range/rubocop_checker.rb
rename to app/workers/commit_monitor_handlers/rubocop_checker.rb
index 23fdd432..0e47d779 100644
--- a/app/workers/commit_monitor_handlers/commit_range/rubocop_checker.rb
+++ b/app/workers/commit_monitor_handlers/rubocop_checker.rb
@@ -1,6 +1,4 @@
-require 'rugged'
-
-class CommitMonitorHandlers::CommitRange::RubocopChecker
+class CommitMonitorHandlers::RubocopChecker
include Sidekiq::Worker
sidekiq_options :queue => :miq_bot_glacial
diff --git a/app/workers/commit_monitor_handlers/commit_range/rubocop_checker/message_builder.rb b/app/workers/commit_monitor_handlers/rubocop_checker/message_builder.rb
similarity index 97%
rename from app/workers/commit_monitor_handlers/commit_range/rubocop_checker/message_builder.rb
rename to app/workers/commit_monitor_handlers/rubocop_checker/message_builder.rb
index 3e9d043b..1c426a69 100644
--- a/app/workers/commit_monitor_handlers/commit_range/rubocop_checker/message_builder.rb
+++ b/app/workers/commit_monitor_handlers/rubocop_checker/message_builder.rb
@@ -1,7 +1,7 @@
require 'rubocop'
require 'haml_lint'
-class CommitMonitorHandlers::CommitRange::RubocopChecker::MessageBuilder
+class CommitMonitorHandlers::RubocopChecker::MessageBuilder
include BranchWorkerMixin
def initialize(results, branch)
diff --git a/app/workers/commit_monitor_handlers/rubocop_checker/rubocop_results_filter.rb b/app/workers/commit_monitor_handlers/rubocop_checker/rubocop_results_filter.rb
new file mode 100644
index 00000000..b2a64a5f
--- /dev/null
+++ b/app/workers/commit_monitor_handlers/rubocop_checker/rubocop_results_filter.rb
@@ -0,0 +1,40 @@
+class CommitMonitorHandlers::RubocopChecker::RubocopResultsFilter
+ attr_reader :filtered
+
+ def initialize(results, diff_details)
+ @results = results
+ @diff_details = diff_details
+ @filtered = filter_rubocop_results
+ end
+
+ private
+
+ def filter_rubocop_results
+ filter_on_diff
+ filter_void_warnings_in_spec_files
+
+ @results["summary"]["offense_count"] =
+ @results["files"].inject(0) { |sum, f| sum + f["offenses"].length }
+
+ @results
+ end
+
+ def filter_on_diff
+ @results["files"].each do |f|
+ f["offenses"].select! do |o|
+ o["severity"].in?(%w(error fatal)) ||
+ @diff_details[f["path"]].include?(o["location"]["line"])
+ end
+ end
+ end
+
+ def filter_void_warnings_in_spec_files
+ @results["files"].each do |f|
+ next unless f["path"].match %r{(?:^|/)spec/.+_spec.rb}
+
+ f["offenses"].reject! do |o|
+ o["cop_name"].in?(%w(Void Lint/Void))
+ end
+ end
+ end
+end
diff --git a/spec/workers/commit_monitor_handlers/commit_range/branch_mergeability_checker_spec.rb b/spec/workers/commit_monitor_handlers/branch_mergeability_checker_spec.rb
similarity index 86%
rename from spec/workers/commit_monitor_handlers/commit_range/branch_mergeability_checker_spec.rb
rename to spec/workers/commit_monitor_handlers/branch_mergeability_checker_spec.rb
index d23944e5..5fd88f1b 100644
--- a/spec/workers/commit_monitor_handlers/commit_range/branch_mergeability_checker_spec.rb
+++ b/spec/workers/commit_monitor_handlers/branch_mergeability_checker_spec.rb
@@ -1,4 +1,4 @@
-describe CommitMonitorHandlers::CommitRange::BranchMergeabilityChecker do
+describe CommitMonitorHandlers::BranchMergeabilityChecker do
let!(:branch) { create(:branch) }
let!(:pr_branch) { create(:pr_branch, :repo => branch.repo, :merge_target => branch.name) }
let!(:pr_branch2) { create(:pr_branch, :repo => branch.repo) }
diff --git a/spec/workers/commit_monitor_handlers/commit_range/github_pr_commenter/diff_content_checker_spec.rb b/spec/workers/commit_monitor_handlers/github_pr_commenter/diff_content_checker_spec.rb
similarity index 96%
rename from spec/workers/commit_monitor_handlers/commit_range/github_pr_commenter/diff_content_checker_spec.rb
rename to spec/workers/commit_monitor_handlers/github_pr_commenter/diff_content_checker_spec.rb
index 3aa987e9..88a489c3 100644
--- a/spec/workers/commit_monitor_handlers/commit_range/github_pr_commenter/diff_content_checker_spec.rb
+++ b/spec/workers/commit_monitor_handlers/github_pr_commenter/diff_content_checker_spec.rb
@@ -1,6 +1,4 @@
-require 'spec_helper'
-
-describe CommitMonitorHandlers::CommitRange::GithubPrCommenter::DiffContentChecker do
+describe CommitMonitorHandlers::GithubPrCommenter::DiffContentChecker do
let(:batch_entry) { BatchEntry.create!(:job => BatchJob.create!) }
let(:branch) { create(:pr_branch) }
let(:content_1) { "def a(variable)" }
diff --git a/spec/workers/commit_monitor_handlers/commit_range/github_pr_commenter/diff_filename_checker_spec.rb b/spec/workers/commit_monitor_handlers/github_pr_commenter/diff_filename_checker_spec.rb
similarity index 96%
rename from spec/workers/commit_monitor_handlers/commit_range/github_pr_commenter/diff_filename_checker_spec.rb
rename to spec/workers/commit_monitor_handlers/github_pr_commenter/diff_filename_checker_spec.rb
index 15f44187..43b0f8fc 100644
--- a/spec/workers/commit_monitor_handlers/commit_range/github_pr_commenter/diff_filename_checker_spec.rb
+++ b/spec/workers/commit_monitor_handlers/github_pr_commenter/diff_filename_checker_spec.rb
@@ -1,4 +1,4 @@
-describe CommitMonitorHandlers::CommitRange::GithubPrCommenter::DiffFilenameChecker do
+describe CommitMonitorHandlers::GithubPrCommenter::DiffFilenameChecker do
let(:batch_entry) { BatchEntry.create!(:job => BatchJob.create!) }
let(:branch) { create(:pr_branch) }
let(:git_service) { double("GitService", :diff => double("RuggedDiff", :new_files => new_files)) }
diff --git a/spec/workers/commit_monitor_handlers/commit_range/path_based_labeler_spec.rb b/spec/workers/commit_monitor_handlers/path_based_labeler_spec.rb
similarity index 98%
rename from spec/workers/commit_monitor_handlers/commit_range/path_based_labeler_spec.rb
rename to spec/workers/commit_monitor_handlers/path_based_labeler_spec.rb
index 9d95a86b..42e97055 100644
--- a/spec/workers/commit_monitor_handlers/commit_range/path_based_labeler_spec.rb
+++ b/spec/workers/commit_monitor_handlers/path_based_labeler_spec.rb
@@ -1,4 +1,4 @@
-describe CommitMonitorHandlers::CommitRange::PathBasedLabeler do
+describe CommitMonitorHandlers::PathBasedLabeler do
subject(:labeler) { described_class.new }
let(:branch) { create(:pr_branch) }
diff --git a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_haml_file_using_haml-lint/example.haml b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_haml_file_using_haml-lint/example.haml
similarity index 100%
rename from spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_haml_file_using_haml-lint/example.haml
rename to spec/workers/commit_monitor_handlers/rubocop_checker/data/with_haml_file_using_haml-lint/example.haml
diff --git a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_haml_file_using_haml-lint/results.json b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_haml_file_using_haml-lint/results.json
similarity index 83%
rename from spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_haml_file_using_haml-lint/results.json
rename to spec/workers/commit_monitor_handlers/rubocop_checker/data/with_haml_file_using_haml-lint/results.json
index f788e646..27cecb38 100644
--- a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_haml_file_using_haml-lint/results.json
+++ b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_haml_file_using_haml-lint/results.json
@@ -8,7 +8,7 @@
},
"files": [
{
- "path": "spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_haml_file_using_haml-lint/example.haml",
+ "path": "spec/workers/commit_monitor_handlers/rubocop_checker/data/with_haml_file_using_haml-lint/example.haml",
"offenses": [
{
"severity": "error",
@@ -25,4 +25,4 @@
"target_file_count": 1,
"inspected_file_count": 1
}
-}
\ No newline at end of file
+}
diff --git a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_lines_not_in_the_diff/example.rb b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_lines_not_in_the_diff/example.rb
similarity index 100%
rename from spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_lines_not_in_the_diff/example.rb
rename to spec/workers/commit_monitor_handlers/rubocop_checker/data/with_lines_not_in_the_diff/example.rb
diff --git a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_lines_not_in_the_diff/results.json b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_lines_not_in_the_diff/results.json
similarity index 92%
rename from spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_lines_not_in_the_diff/results.json
rename to spec/workers/commit_monitor_handlers/rubocop_checker/data/with_lines_not_in_the_diff/results.json
index 8594d9d5..694d17ab 100644
--- a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_lines_not_in_the_diff/results.json
+++ b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_lines_not_in_the_diff/results.json
@@ -8,7 +8,7 @@
},
"files": [
{
- "path": "spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_lines_not_in_the_diff/example.rb",
+ "path": "spec/workers/commit_monitor_handlers/rubocop_checker/data/with_lines_not_in_the_diff/example.rb",
"offenses": [
{
"severity": "convention",
@@ -63,4 +63,4 @@
"target_file_count": 1,
"inspected_file_count": 1
}
-}
\ No newline at end of file
+}
diff --git a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_generating_multiple_comments/lots_of_issues.rb b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_generating_multiple_comments/lots_of_issues.rb
similarity index 100%
rename from spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_generating_multiple_comments/lots_of_issues.rb
rename to spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_generating_multiple_comments/lots_of_issues.rb
diff --git a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_generating_multiple_comments/results.json b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_generating_multiple_comments/results.json
similarity index 99%
rename from spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_generating_multiple_comments/results.json
rename to spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_generating_multiple_comments/results.json
index f1dad9d8..dba56f75 100644
--- a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_generating_multiple_comments/results.json
+++ b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_generating_multiple_comments/results.json
@@ -8,7 +8,7 @@
},
"files": [
{
- "path": "spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_generating_multiple_comments/lots_of_issues.rb",
+ "path": "spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_generating_multiple_comments/lots_of_issues.rb",
"offenses": [
{
"severity": "convention",
@@ -4398,4 +4398,4 @@
"target_file_count": 1,
"inspected_file_count": 1
}
-}
\ No newline at end of file
+}
diff --git a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_with_no_offenses/no_offenses.rb b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_with_no_offenses/no_offenses.rb
similarity index 100%
rename from spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_with_no_offenses/no_offenses.rb
rename to spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_with_no_offenses/no_offenses.rb
diff --git a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_with_no_offenses/results.json b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_with_no_offenses/results.json
similarity index 71%
rename from spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_with_no_offenses/results.json
rename to spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_with_no_offenses/results.json
index ad236c22..b3e9662b 100644
--- a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_with_no_offenses/results.json
+++ b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_with_no_offenses/results.json
@@ -8,7 +8,7 @@
},
"files": [
{
- "path": "spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_with_no_offenses/no_offenses.rb",
+ "path": "spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_with_no_offenses/no_offenses.rb",
"offenses": [
]
@@ -19,4 +19,4 @@
"target_file_count": 1,
"inspected_file_count": 1
}
-}
\ No newline at end of file
+}
diff --git a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_with_offenses/coding_convention.rb b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_with_offenses/coding_convention.rb
similarity index 100%
rename from spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_with_offenses/coding_convention.rb
rename to spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_with_offenses/coding_convention.rb
diff --git a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_with_offenses/no_offenses.rb b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_with_offenses/no_offenses.rb
similarity index 100%
rename from spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_with_offenses/no_offenses.rb
rename to spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_with_offenses/no_offenses.rb
diff --git a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_with_offenses/results.json b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_with_offenses/results.json
similarity index 81%
rename from spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_with_offenses/results.json
rename to spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_with_offenses/results.json
index bb7c3aae..4c191e27 100644
--- a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_with_offenses/results.json
+++ b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_with_offenses/results.json
@@ -8,7 +8,7 @@
},
"files": [
{
- "path": "spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_with_offenses/coding_convention.rb",
+ "path": "spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_with_offenses/coding_convention.rb",
"offenses": [
{
"severity": "convention",
@@ -43,13 +43,13 @@
]
},
{
- "path": "spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_with_offenses/no_offenses.rb",
+ "path": "spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_with_offenses/no_offenses.rb",
"offenses": [
]
},
{
- "path": "spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_with_offenses/ruby_syntax_error.rb",
+ "path": "spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_with_offenses/ruby_syntax_error.rb",
"offenses": [
{
"severity": "error",
@@ -69,7 +69,7 @@
]
},
{
- "path": "spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_with_offenses/ruby_warning.rb",
+ "path": "spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_with_offenses/ruby_warning.rb",
"offenses": [
{
"severity": "warning",
@@ -94,4 +94,4 @@
"target_file_count": 4,
"inspected_file_count": 4
}
-}
\ No newline at end of file
+}
diff --git a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_with_offenses/ruby_syntax_error.rb b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_with_offenses/ruby_syntax_error.rb
similarity index 100%
rename from spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_with_offenses/ruby_syntax_error.rb
rename to spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_with_offenses/ruby_syntax_error.rb
diff --git a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_with_offenses/ruby_warning.rb b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_with_offenses/ruby_warning.rb
similarity index 100%
rename from spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_with_offenses/ruby_warning.rb
rename to spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_with_offenses/ruby_warning.rb
diff --git a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_without_column_numbers_and_cop_names/example.haml b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_without_column_numbers_and_cop_names/example.haml
similarity index 100%
rename from spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_without_column_numbers_and_cop_names/example.haml
rename to spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_without_column_numbers_and_cop_names/example.haml
diff --git a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_without_column_numbers_and_cop_names/results.json b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_without_column_numbers_and_cop_names/results.json
similarity index 79%
rename from spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_without_column_numbers_and_cop_names/results.json
rename to spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_without_column_numbers_and_cop_names/results.json
index 52f829ee..a5c6484d 100644
--- a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_without_column_numbers_and_cop_names/results.json
+++ b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_without_column_numbers_and_cop_names/results.json
@@ -8,7 +8,7 @@
},
"files": [
{
- "path": "spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_without_column_numbers_and_cop_names/example.haml",
+ "path": "spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_without_column_numbers_and_cop_names/example.haml",
"offenses": [
{
"severity": "warning",
@@ -26,4 +26,4 @@
"target_file_count": 1,
"inspected_file_count": 1
}
-}
\ No newline at end of file
+}
diff --git a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_void_warnings_in_spec_files/non_spec_file_with_void_warning.rb b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_void_warnings_in_spec_files/non_spec_file_with_void_warning.rb
similarity index 100%
rename from spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_void_warnings_in_spec_files/non_spec_file_with_void_warning.rb
rename to spec/workers/commit_monitor_handlers/rubocop_checker/data/with_void_warnings_in_spec_files/non_spec_file_with_void_warning.rb
diff --git a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_void_warnings_in_spec_files/results.json b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_void_warnings_in_spec_files/results.json
similarity index 76%
rename from spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_void_warnings_in_spec_files/results.json
rename to spec/workers/commit_monitor_handlers/rubocop_checker/data/with_void_warnings_in_spec_files/results.json
index ac6b5858..1f0aaab5 100644
--- a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_void_warnings_in_spec_files/results.json
+++ b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_void_warnings_in_spec_files/results.json
@@ -8,7 +8,7 @@
},
"files": [
{
- "path": "spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_void_warnings_in_spec_files/non_spec_file_with_void_warning.rb",
+ "path": "spec/workers/commit_monitor_handlers/rubocop_checker/data/with_void_warnings_in_spec_files/non_spec_file_with_void_warning.rb",
"offenses": [
{
"severity": "warning",
@@ -28,7 +28,7 @@
]
},
{
- "path": "spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_void_warnings_in_spec_files/spec/non_spec_file_in_spec_dir_with_void_warning.rb",
+ "path": "spec/workers/commit_monitor_handlers/rubocop_checker/data/with_void_warnings_in_spec_files/spec/non_spec_file_in_spec_dir_with_void_warning.rb",
"offenses": [
{
"severity": "warning",
@@ -48,7 +48,7 @@
]
},
{
- "path": "spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_void_warnings_in_spec_files/spec/spec_file_with_void_warning_spec.rb",
+ "path": "spec/workers/commit_monitor_handlers/rubocop_checker/data/with_void_warnings_in_spec_files/spec/spec_file_with_void_warning_spec.rb",
"offenses": [
{
"severity": "warning",
@@ -73,4 +73,4 @@
"target_file_count": 3,
"inspected_file_count": 3
}
-}
\ No newline at end of file
+}
diff --git a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_void_warnings_in_spec_files/spec/non_spec_file_in_spec_dir_with_void_warning.rb b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_void_warnings_in_spec_files/spec/non_spec_file_in_spec_dir_with_void_warning.rb
similarity index 100%
rename from spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_void_warnings_in_spec_files/spec/non_spec_file_in_spec_dir_with_void_warning.rb
rename to spec/workers/commit_monitor_handlers/rubocop_checker/data/with_void_warnings_in_spec_files/spec/non_spec_file_in_spec_dir_with_void_warning.rb
diff --git a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_void_warnings_in_spec_files/spec/spec_file_with_void_warning_spec.rb b/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_void_warnings_in_spec_files/spec/spec_file_with_void_warning_spec.rb
similarity index 100%
rename from spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_void_warnings_in_spec_files/spec/spec_file_with_void_warning_spec.rb
rename to spec/workers/commit_monitor_handlers/rubocop_checker/data/with_void_warnings_in_spec_files/spec/spec_file_with_void_warning_spec.rb
diff --git a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/message_builder_spec.rb b/spec/workers/commit_monitor_handlers/rubocop_checker/message_builder_spec.rb
similarity index 68%
rename from spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/message_builder_spec.rb
rename to spec/workers/commit_monitor_handlers/rubocop_checker/message_builder_spec.rb
index ab8e0e51..ac8bd7c0 100644
--- a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/message_builder_spec.rb
+++ b/spec/workers/commit_monitor_handlers/rubocop_checker/message_builder_spec.rb
@@ -1,6 +1,4 @@
-require 'spec_helper'
-
-describe CommitMonitorHandlers::CommitRange::RubocopChecker::MessageBuilder do
+describe CommitMonitorHandlers::RubocopChecker::MessageBuilder do
let(:branch) do
Branch.new(
:name => "pr/123",
@@ -23,16 +21,16 @@
Checked commits https://github.com/some_user/some_repo/compare/1ec36efd33279f79f8ddcf12984bb2aa48f3fbd6~...8942a195a0bfa69ceb82c020c60565408cb46d3e with ruby #{RUBY_VERSION}, rubocop #{rubocop_version}, haml-lint #{hamllint_version}, and yamllint #{yamllint_version}
4 files checked, 4 offenses detected
-**spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/#{rubocop_check_directory}/coding_convention.rb**
-- [ ] :exclamation: - [Line 3](https://github.com/some_user/some_repo/blob/8942a195a0bfa69ceb82c020c60565408cb46d3e/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/#{rubocop_check_directory}/coding_convention.rb#L3), Col 5 - [Layout/AlignHash](http://rubydoc.info/gems/rubocop/#{rubocop_version}/RuboCop/Cop/Layout/AlignHash) - Align the elements of a hash literal if they span more than one line.
-- [ ] :exclamation: - [Line 4](https://github.com/some_user/some_repo/blob/8942a195a0bfa69ceb82c020c60565408cb46d3e/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/#{rubocop_check_directory}/coding_convention.rb#L4), Col 5 - [Layout/AlignHash](http://rubydoc.info/gems/rubocop/#{rubocop_version}/RuboCop/Cop/Layout/AlignHash) - Align the elements of a hash literal if they span more than one line.
+**spec/workers/commit_monitor_handlers/rubocop_checker/data/#{rubocop_check_directory}/coding_convention.rb**
+- [ ] :exclamation: - [Line 3](https://github.com/some_user/some_repo/blob/8942a195a0bfa69ceb82c020c60565408cb46d3e/spec/workers/commit_monitor_handlers/rubocop_checker/data/#{rubocop_check_directory}/coding_convention.rb#L3), Col 5 - [Layout/AlignHash](http://rubydoc.info/gems/rubocop/#{rubocop_version}/RuboCop/Cop/Layout/AlignHash) - Align the elements of a hash literal if they span more than one line.
+- [ ] :exclamation: - [Line 4](https://github.com/some_user/some_repo/blob/8942a195a0bfa69ceb82c020c60565408cb46d3e/spec/workers/commit_monitor_handlers/rubocop_checker/data/#{rubocop_check_directory}/coding_convention.rb#L4), Col 5 - [Layout/AlignHash](http://rubydoc.info/gems/rubocop/#{rubocop_version}/RuboCop/Cop/Layout/AlignHash) - Align the elements of a hash literal if they span more than one line.
-**spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/#{rubocop_check_directory}/ruby_syntax_error.rb**
+**spec/workers/commit_monitor_handlers/rubocop_checker/data/#{rubocop_check_directory}/ruby_syntax_error.rb**
- [ ] :bomb: :boom: :fire: :fire_engine: - [Line 3](https://github.com/some_user/some_repo/blob/8942a195a0bfa69ceb82c020c60565408cb46d3e/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/#{rubocop_check_directory}/ruby_syntax_error.rb#L3), Col 1 - [Lint/Syntax](http://rubydoc.info/gems/rubocop/0.52.1/RuboCop/Cop/Lint/Syntax) - unexpected token kEND
(Using Ruby 2.3 parser; configure using `TargetRubyVersion` parameter, under `AllCops`)
-**spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/#{rubocop_check_directory}/ruby_warning.rb**
-- [ ] :warning: - [Line 3](https://github.com/some_user/some_repo/blob/8942a195a0bfa69ceb82c020c60565408cb46d3e/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/#{rubocop_check_directory}/ruby_warning.rb#L3), Col 5 - [Lint/UselessAssignment](http://rubydoc.info/gems/rubocop/#{rubocop_version}/RuboCop/Cop/Lint/UselessAssignment) - Useless assignment to variable - `unused_variable`.
+**spec/workers/commit_monitor_handlers/rubocop_checker/data/#{rubocop_check_directory}/ruby_warning.rb**
+- [ ] :warning: - [Line 3](https://github.com/some_user/some_repo/blob/8942a195a0bfa69ceb82c020c60565408cb46d3e/spec/workers/commit_monitor_handlers/rubocop_checker/data/#{rubocop_check_directory}/ruby_warning.rb#L3), Col 5 - [Lint/UselessAssignment](http://rubydoc.info/gems/rubocop/#{rubocop_version}/RuboCop/Cop/Lint/UselessAssignment) - Useless assignment to variable - `unused_variable`.
EOMSG
end
@@ -61,8 +59,8 @@
Checked commits https://github.com/some_user/some_repo/compare/1ec36efd33279f79f8ddcf12984bb2aa48f3fbd6~...8942a195a0bfa69ceb82c020c60565408cb46d3e with ruby #{RUBY_VERSION}, rubocop #{rubocop_version}, haml-lint #{hamllint_version}, and yamllint #{yamllint_version}
1 file checked, 1 offense detected
-**spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/#{rubocop_check_directory}/example.haml**
-- [ ] :warning: - [Line 2](https://github.com/some_user/some_repo/blob/8942a195a0bfa69ceb82c020c60565408cb46d3e/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_without_column_numbers_and_cop_names/example.haml#L2) - The - symbol should have one space separating it from code
+**spec/workers/commit_monitor_handlers/rubocop_checker/data/#{rubocop_check_directory}/example.haml**
+- [ ] :warning: - [Line 2](https://github.com/some_user/some_repo/blob/8942a195a0bfa69ceb82c020c60565408cb46d3e/spec/workers/commit_monitor_handlers/rubocop_checker/data/with_results_without_column_numbers_and_cop_names/example.haml#L2) - The - symbol should have one space separating it from code
EOMSG
end
end
diff --git a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/rubocop_results_filter_spec.rb b/spec/workers/commit_monitor_handlers/rubocop_checker/rubocop_results_filter_spec.rb
similarity index 94%
rename from spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/rubocop_results_filter_spec.rb
rename to spec/workers/commit_monitor_handlers/rubocop_checker/rubocop_results_filter_spec.rb
index a9108496..6d66d3c6 100644
--- a/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/rubocop_results_filter_spec.rb
+++ b/spec/workers/commit_monitor_handlers/rubocop_checker/rubocop_results_filter_spec.rb
@@ -1,6 +1,4 @@
-require 'spec_helper'
-
-describe CommitMonitorHandlers::CommitRange::RubocopChecker::RubocopResultsFilter do
+describe CommitMonitorHandlers::RubocopChecker::RubocopResultsFilter do
describe "#filtered" do
subject { described_class.new(rubocop_results, @diff_details) }