-
Notifications
You must be signed in to change notification settings - Fork 400
/
Copy pathbase.rb
79 lines (64 loc) · 1.54 KB
/
base.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
module Linter
class Base
def initialize(hound_config:, build:)
@hound_config = hound_config
@build = build
end
def self.can_lint?(filename)
self::FILE_REGEXP === filename
end
def file_review(commit_file)
attributes = build_review_job_attributes(commit_file)
file_review = FileReview.create!(
build: build,
filename: commit_file.filename,
linter_name: name,
)
enqueue_job(attributes)
file_review
end
def enabled?
hound_config.linter_enabled?(name)
end
def file_included?(*)
true
end
def name
self.class.name.demodulize.underscore
end
private
attr_reader :hound_config, :build
def build_review_job_attributes(commit_file)
{
commit_sha: build.commit_sha,
config: config.serialize,
content: commit_file.content,
filename: commit_file.filename,
linter_name: name,
patch: commit_file.patch,
pull_request_number: build.pull_request_number,
linter_version: version,
suggestions: suggestions?,
}
end
def enqueue_job(attributes)
LintersJob.perform_async(attributes)
end
def owner
build.repo.owner || MissingOwner.new
end
def config
@_config ||= BuildConfig.call(
hound_config: hound_config,
name: name,
owner: owner,
)
end
def version
hound_config.linter_version(name)
end
def suggestions?
hound_config.suggestions?(name)
end
end
end