Skip to content

Commit

Permalink
[WIP] Add BuildFailure model
Browse files Browse the repository at this point in the history
This model is in charge of keeping track of build failures that we find
when polling the Travis API.  Used to avoid spamming gitter with extra
notifications, but also can be used to identify that a branch has
previously been broken and now has been fixed.

Makes sense to also notify on the passing cases so others aren't taking
the time to investigate a failure when this has already been
investigated.
  • Loading branch information
NickLaMuro committed Jan 14, 2020
1 parent 1e0b09c commit e8bd93b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
19 changes: 19 additions & 0 deletions app/models/build_failure.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class BuildFailure < ActiveRecord::Base
belongs_to :repo
belongs_to :branch

def notify
if should_notify?
update_attributes(:last_notified_at => Time.now)

BuildFailureNotifier.new(self).post_failure
end
end

def should_notify?
last_notified_at.nil? || last_notified_at > 1.day.ago
end

def still_broken?
end
end
12 changes: 12 additions & 0 deletions db/migrate/20200109223351_create_build_failures.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateBuildFailures < ActiveRecord::Migration
def change
create_table :build_failures do |t|
t.integer :repo_id
t.integer :branch_id
t.integer :travis_build_id

t.datetime :last_notified_at
t.timestamps
end
end
end
11 changes: 10 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20171006050814) do
ActiveRecord::Schema.define(version: 20200109223351) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -48,6 +48,15 @@
t.integer "linter_offense_count"
end

create_table "build_failures", force: :cascade do |t|
t.integer "repo_id"
t.integer "branch_id"
t.integer "travis_build_id"
t.datetime "last_notified_at"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "repos", force: :cascade do |t|
t.string "name", limit: 255
t.datetime "created_at"
Expand Down

0 comments on commit e8bd93b

Please sign in to comment.