-
Notifications
You must be signed in to change notification settings - Fork 401
/
pull_request.rb
71 lines (56 loc) · 1.3 KB
/
pull_request.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
class PullRequest
CONFIG_FILE = '.hound.yml'
def initialize(payload, github_token)
@payload = payload
@github_token = github_token
end
def head_includes?(line)
head_commit_files.detect { |file| file.modified_lines.include?(line) }
end
def comments
api.pull_request_comments(full_repo_name, number)
end
def pull_request_files
api.pull_request_files(full_repo_name, number).map do |file|
build_commit_file(file)
end
end
def add_comment(filename, patch_position, message)
github = GithubApi.new(ENV['HOUND_GITHUB_TOKEN'])
github.add_comment(
pull_request_number: number,
comment: message,
commit: head_commit,
filename: filename,
patch_position: patch_position
)
end
def config
head_commit.file_content(CONFIG_FILE)
end
def opened?
@payload.action == 'opened'
end
def synchronize?
@payload.action == 'synchronize'
end
private
def head_commit_files
head_commit.files
end
def build_commit_file(file)
CommitFile.new(file, head_commit)
end
def api
@api ||= GithubApi.new(@github_token)
end
def number
@payload.number
end
def full_repo_name
@payload.full_repo_name
end
def head_commit
@head_commit ||= Commit.new(full_repo_name, @payload.head_sha, api)
end
end