Skip to content

Commit d1323c9

Browse files
committed
Merge pull request #9 from bad6e/current_stats
Current stats
2 parents a094263 + e29abfb commit d1323c9

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ gem "whenever", require: false
1515
gem "hurley"
1616
gem "omniauth-github"
1717
gem "figaro"
18+
gem "githubstats"
1819

1920
group :development, :test do
2021
gem "byebug"

Gemfile.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ GEM
4141
autoprefixer-rails (6.0.3)
4242
execjs
4343
json
44+
basiccache (1.0.0)
4445
better_errors (2.1.1)
4546
coderay (>= 1.0.0)
4647
erubis (>= 2.6.6)
@@ -69,6 +70,7 @@ GEM
6970
coffee-script-source
7071
execjs
7172
coffee-script-source (1.9.1.1)
73+
curb (0.8.8)
7274
database_cleaner (1.5.0)
7375
debug_inspector (0.0.2)
7476
diff-lcs (1.2.5)
@@ -78,6 +80,10 @@ GEM
7880
multipart-post (>= 1.2, < 3)
7981
figaro (1.1.1)
8082
thor (~> 0.14)
83+
githubstats (1.1.0)
84+
basiccache (~> 1.0.0)
85+
curb (~> 0.8.6)
86+
nokogiri (~> 1.6.5)
8187
globalid (0.3.6)
8288
activesupport (>= 4.1.0)
8389
hashie (3.4.2)
@@ -224,6 +230,7 @@ DEPENDENCIES
224230
coffee-rails (~> 4.1.0)
225231
database_cleaner
226232
figaro
233+
githubstats
227234
hurley
228235
jbuilder (~> 2.0)
229236
jquery-rails

app/presenters/github_presenter.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@ def organizations
3232
end
3333

3434
def year_commits
35-
list = service.find_user_total_commits(user).map {|data| build_object(data)}
35+
list = service.find_user_total_commits(user)
36+
end
37+
38+
def current_streaks
39+
list = service.find_user_current_streak(user)
40+
end
41+
42+
def longest_streaks
43+
list = service.find_user_longest_streak(user)
3644
end
3745

3846
def starred_repos

app/services/github_service.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ class GithubService
22
attr_reader :connection
33

44
def initialize(user)
5-
@connection = Hurley::Client.new("https://api.github.com")
5+
@connection = Hurley::Client.new("https://api.github.com")
66
@connection.query[:access_token] = user.token
7+
@stats = GithubStats.new('bad6e')
78
end
89

910
def find_user_repos(user)
@@ -23,7 +24,15 @@ def find_user_organizations(user)
2324
end
2425

2526
def find_user_total_commits(user)
26-
parse(connection.get("repos/#{user.nickname}/gitcommit/stats/commit_activity"))
27+
@stats.data.scores.reduce(:+)
28+
end
29+
30+
def find_user_current_streak(user)
31+
@stats.streak.count
32+
end
33+
34+
def find_user_longest_streak(user)
35+
@stats.longest_streak.count
2736
end
2837

2938
def total_starred_repos(user)

app/views/dashboard/show.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010
<br>
1111
<div class="col-md-4 home">
1212
<h4>Total Commits</h4>
13+
<p><%= @info.year_commits %></pr>
1314
</div>
1415
<div class="col-md-4 home">
1516
<h4>Current Streak</h4>
17+
<p><%= @info.current_streaks %></pr>
1618
</div>
1719
<div class="col-md-4 home">
1820
<h4>Longest Streak</h4>
21+
<p><%= @info.longest_streaks %></pr>
1922
</div>
2023
</div>
2124

0 commit comments

Comments
 (0)