-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathgithub_repos.rb
53 lines (43 loc) · 1.03 KB
/
github_repos.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
require 'octokit'
require 'date'
class GithubRepos
attr_reader :repo
def initialize(repo)
@repo = repo.gsub(' ', '')
end
def original
current = client.repo(repo)
if current.fork?
current = current.parent
end
Repo.new(current)
end
def popular_forks
client.forks(repo, sort: 'stargazers').map { |repo| Repo.new(repo) }
end
def client
@client ||= Octokit::Client.new(client_id: ENV['GITHUB_CLIENT_ID'],
client_secret: ENV['GITHUB_CLIENT_SECRET'])
end
end
class Repo
attr_reader :octokit_repo
def initialize(octokit_repo)
@octokit_repo = octokit_repo
end
def score
stargazers_count + forks_count - open_issues_count
end
def pushed_at_score
if ((Date.today - 30).to_time..(Date.today + 1).to_time).cover? pushed_at
50
elsif ((Date.today - 90).to_time..(Date.today - 31).to_time).cover? pushed_at
25
else
0
end
end
def method_missing(name, *args, &block)
octokit_repo.send(name, *args, &block)
end
end