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
|
Reference in New Issue
Block a user