Add LinterCheck and LinterCheckRun
This commit is contained in:
5
app/models/linter_check.rb
Normal file
5
app/models/linter_check.rb
Normal file
@ -0,0 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class LinterCheck < ApplicationRecord
|
||||
has_many :linter_check_runs
|
||||
end
|
30
app/models/linter_check_run.rb
Normal file
30
app/models/linter_check_run.rb
Normal file
@ -0,0 +1,30 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class LinterCheckRun < ApplicationRecord
|
||||
belongs_to :linter_check
|
||||
belongs_to :testrun
|
||||
belongs_to :file, class_name: 'CodeOcean::File'
|
||||
|
||||
def self.create_from(testrun, assessment)
|
||||
assessment[:detailed_linter_results].each do |linter_result|
|
||||
check = LinterCheck.find_or_create_by!(code: linter_result[:code]) do |new_check|
|
||||
new_check.name = linter_result[:name]
|
||||
new_check.severity = linter_result[:severity]
|
||||
end
|
||||
|
||||
file = testrun.submission.file_by_name(linter_result[:file_name])
|
||||
|
||||
LinterCheckRun.create!(
|
||||
linter_check: check,
|
||||
result: linter_result[:result],
|
||||
line: linter_result[:line],
|
||||
scope: linter_result[:scope],
|
||||
testrun: testrun,
|
||||
file: file
|
||||
)
|
||||
end
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
# Something bad happened. Probably, the RegEx in lib/py_lint_adapter.rb didn't work.
|
||||
Raven.extra_context(testrun: testrun, linter_result: linter_result)
|
||||
end
|
||||
end
|
19
db/migrate/20201026184633_create_linter_checks.rb
Normal file
19
db/migrate/20201026184633_create_linter_checks.rb
Normal file
@ -0,0 +1,19 @@
|
||||
class CreateLinterChecks < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :linter_checks do |t|
|
||||
t.string :name, null: false
|
||||
t.string :code, null: false
|
||||
t.string :severity
|
||||
end
|
||||
|
||||
create_table :linter_check_runs do |t|
|
||||
t.references :linter_check, null: false
|
||||
t.string :scope
|
||||
t.integer :line
|
||||
t.text :result
|
||||
t.references :testrun, null: false
|
||||
t.references :file, null: false
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
22
db/schema.rb
22
db/schema.rb
@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2020_10_19_090123) do
|
||||
ActiveRecord::Schema.define(version: 2020_10_26_184633) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@ -265,6 +265,26 @@ ActiveRecord::Schema.define(version: 2020_10_19_090123) do
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "linter_check_runs", force: :cascade do |t|
|
||||
t.bigint "linter_check_id", null: false
|
||||
t.string "scope"
|
||||
t.integer "line"
|
||||
t.text "result"
|
||||
t.bigint "testrun_id", null: false
|
||||
t.bigint "file_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["file_id"], name: "index_linter_check_runs_on_file_id"
|
||||
t.index ["linter_check_id"], name: "index_linter_check_runs_on_linter_check_id"
|
||||
t.index ["testrun_id"], name: "index_linter_check_runs_on_testrun_id"
|
||||
end
|
||||
|
||||
create_table "linter_checks", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.string "code", null: false
|
||||
t.string "severity"
|
||||
end
|
||||
|
||||
create_table "lti_parameters", id: :serial, force: :cascade do |t|
|
||||
t.integer "external_users_id"
|
||||
t.integer "consumers_id"
|
||||
|
Reference in New Issue
Block a user