From e8bd93b71e95b539da5bb5fac9aef2f526d625ec Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Mon, 13 Jan 2020 18:14:40 -0600 Subject: [PATCH] [WIP] Add BuildFailure model 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. --- app/models/build_failure.rb | 19 +++++++++++++++++++ .../20200109223351_create_build_failures.rb | 12 ++++++++++++ db/schema.rb | 11 ++++++++++- 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 app/models/build_failure.rb create mode 100644 db/migrate/20200109223351_create_build_failures.rb diff --git a/app/models/build_failure.rb b/app/models/build_failure.rb new file mode 100644 index 00000000..3cf857e9 --- /dev/null +++ b/app/models/build_failure.rb @@ -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 diff --git a/db/migrate/20200109223351_create_build_failures.rb b/db/migrate/20200109223351_create_build_failures.rb new file mode 100644 index 00000000..7a0850a8 --- /dev/null +++ b/db/migrate/20200109223351_create_build_failures.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 6120ecb7..63875090 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" @@ -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"