-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpull_request.rb
More file actions
50 lines (38 loc) · 1.12 KB
/
pull_request.rb
File metadata and controls
50 lines (38 loc) · 1.12 KB
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
require 'code/github_api'
module Code
class PullRequest
def initialize(pull_request_info:, github_api: GitHubAPI.new)
@pull_request_info = pull_request_info
@github_api = github_api
end
def self.for_branch(branch)
fetch_pull_requests_for_branch(branch).map do |pull_request_info|
new(pull_request_info: pull_request_info)
end
end
def url
pull_request_info[:html_url]
end
def number
pull_request_info[:number]
end
def add_label(label)
github_api.label_pr(self, label)
end
private
def github_api
@github_api ||= GitHubAPI.new
end
attr_reader :pull_request_info
def self.fetch_pull_requests_for_branch(branch)
github_api.pull_requests_for_branch(branch)
end
# I need a github api instance to create instances
# and also need an api instance once the PullRequest instance is created
# I tried to solve this problem with modules by extending on the two places
# but it seems like overkilling it, I'll duplicate it for now.
def self.github_api
@github_api ||= GitHubAPI.new
end
end
end