diff --git a/app/workers/travis_branch_monitor.rb b/app/workers/travis_branch_monitor.rb index dc2397ec..1ad31120 100644 --- a/app/workers/travis_branch_monitor.rb +++ b/app/workers/travis_branch_monitor.rb @@ -63,30 +63,29 @@ def process_repo(repo) end def process_branch(repo, branch) - v3_client = TravisV3Client.new(:repo => Travis::Repository.find(repo.name)) branch_record = repo.regular_branches.where(:name => branch).first - branch_builds = v3_client.repo_branch_builds(branch) failure = BuildFailure.where(:repo => repo, :branch => branch_record).first + # If we already have a failure record, call notify with that record + return failure.notify if failure + + # otherwise, check if any builds exist with a failures, and if so, create a + # new BuildFailure record. + v3_client = TravisV3Client.new(:repo => Travis::Repository.find(repo.name)) + branch_builds = v3_client.repo_branch_builds(branch) + if branch_builds.first.failed? first_failure = find_first_recent_failure(branch_builds) - failure ||= BuildFailure.create(:repo => repo, + failure = BuildFailure.create(:repo => repo, :branch => branch_record, :travis_build_id => first_failure.id) failure.notify - elsif failure - post_passing(failure) end end private - def post_passing(failure) - BuildFailureNotifier.new(failure).report_passing - failure.delete - end - def find_first_recent_failure(builds) first_recent_failure = nil builds.each do |build|