forked from netlify/staticgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.rb
More file actions
98 lines (79 loc) · 1.9 KB
/
project.rb
File metadata and controls
98 lines (79 loc) · 1.9 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
module Github
module Project
[:title, :repo, :startertemplaterepo, :homepage, :language, :license, :templates, :description].each do |attr|
define_method attr do
data[attr]
end
end
def stars
repo_data[:stargazers_count]
end
def forks
repo_data[:forks]
end
def issues
repo_data[:open_issues]
end
def stars_last_week
last_week.stars
end
def forks_last_week
last_week.forks
end
def issues_last_week
last_week.issues
end
def stars_diff
return 0 unless stars_last_week
stars - stars_last_week
end
def forks_diff
return 0 unless forks_last_week
forks - forks_last_week
end
def issues_diff
return 0 unless issues_last_week
issues - issues_last_week
end
def stars_trend
trend(stars_diff)
end
def forks_trend
trend(forks_diff)
end
def issues_trend
trend(issues_diff)
end
def trend(diff)
diff == 0 ? "" : (diff > 0 ? "up" : "down")
end
def last_week
days_ago(7)
end
def week_history
(0..7).map do |days|
days_ago(days)
end.reverse.tap do |days|
days.each_with_index do |day,index|
if index > 0 && day.stars.nil?
days[index] = days[index - 1]
end
end
end
end
def days_ago(days)
time = Time.now.to_i / API::DAY - days
point_in_time(time * API::DAY, repo_data(time) || {})
end
def repo_data(day = nil)
day ? API.repo_data_for(repo, day) : API.repo_data(repo)
end
def render(opts={}, locs={}, &block)
super(opts.merge(:layout => "project.erb"), locs, &block)
end
def point_in_time(time, data)
data = data || {}
Struct.new(:timestamp, :stars, :forks, :issues).new(time, data[:stargazers_count], data[:forks], data[:open_issues])
end
end
end