forked from tip4commit/tip4commit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.rb
More file actions
52 lines (43 loc) · 1.28 KB
/
Copy pathgithub.rb
File metadata and controls
52 lines (43 loc) · 1.28 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
51
52
class Github
def initialize
options = { client_id: CONFIG['github']['key'], client_secret: CONFIG['github']['secret'] }
if CONFIG['github']['auto_paginate']
options.merge! :auto_paginate => true
else
options.merge! :per_page => 100
end
@client = Octokit::Client.new(options)
end
attr_reader :client
def commits project
commits = client.commits project.full_name
last_response = client.last_response
(CONFIG['github']['pages'].to_i - 1).times do
if last_response.rels[:next]
last_response = last_response.rels[:next].get
commits += last_response.data
end
end
commits
end
def repository_info project
if project.github_id.present?
client.get "/repositories/#{project.github_id}"
else
client.repo project.full_name
end
end
def collaborators_info project
client.get("/repos/#{project.full_name}/collaborators") +
(client.get("/orgs/#{project.full_name.split('/').first}/members") rescue [])
end
def repository_url project
"https://github.com/#{project.full_name}"
end
def source_repository_url project
"https://github.com/#{project.source_full_name}"
end
def commit_url project, commit
"https://github.com/#{project.full_name}/commit/#{commit}"
end
end