Module: Wassup::Helpers::GitHub
- Defined in:
- lib/wassup/helpers/github.rb,
lib/wassup/helpers/github.rb,
lib/wassup/helpers/github_rate_limiter.rb
Defined Under Namespace
Modules: Formatter
Classes: RateLimiter, Repo, RequestFuture
Class Method Summary
collapse
Class Method Details
.api(path:, method: :get, params: {}, body: nil) ⇒ Object
Generic GitHub API method for any endpoint
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/wassup/helpers/github.rb', line 75
def self.api(path:, method: :get, params: {}, body: nil)
if path.start_with?('http')
url = path
else
path = "/#{path}" unless path.start_with?('/')
url = "https://api.github.com#{path}"
end
if params.any?
query_string = params.map { |k, v| "#{k}=#{v}" }.join('&')
url += "?#{query_string}"
end
options = {}
if body
options[:payload] = body.is_a?(String) ? body : body.to_json
end
resp = RateLimiter.execute_request(
method: method,
url: url,
**options
)
return JSON.parse(resp)
end
|
.issues(org:, repo: nil, q: nil) ⇒ Object
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
|
# File 'lib/wassup/helpers/github.rb', line 9
def self.issues(org:, repo:nil, q: nil)
q_parts = []
if repo.nil?
q_parts << "org:#{org}"
else
q_parts << "repo:#{org}/#{repo}"
end
if q
q_parts << q
end
q = q_parts.join(' ')
items = []
resp = RateLimiter.execute_request(
method: :get,
url: "https://api.github.com/search/issues?q=#{q}"
)
partial_items = JSON.parse(resp)["items"]
items += partial_items
return items
end
|
.pull_requests(org:, repo: nil) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/wassup/helpers/github.rb', line 45
def self.pull_requests(org:, repo: nil)
repos = []
if repo.nil?
repos += self.repos(org: org).map do |repo|
Repo.new(org, repo["name"])
end
else
repos << Repo.new(org, repo)
end
return repos.map do |repo|
resp = RateLimiter.execute_request(
method: :get,
url: "https://api.github.com/repos/#{repo.org}/#{repo.repo}/pulls?per_page=100"
)
JSON.parse(resp)
end.flatten(1)
end
|
.releases(org:, repo:) ⇒ Object
65
66
67
68
69
70
71
72
|
# File 'lib/wassup/helpers/github.rb', line 65
def self.releases(org:, repo:)
resp = RateLimiter.execute_request(
method: :get,
url: "https://api.github.com/repos/#{org}/#{repo}/releases"
)
return JSON.parse(resp)
end
|
.repos(org:) ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/wassup/helpers/github.rb', line 36
def self.repos(org:)
resp = RateLimiter.execute_request(
method: :get,
url: "https://api.github.com/orgs/#{org}/repos"
)
return JSON.parse(resp)
end
|