From 91f1d61bf9cb95213c5f5a5ec9f96d18ca6ebb6f Mon Sep 17 00:00:00 2001 From: Bret Doucette Date: Tue, 27 Oct 2015 13:43:07 -0600 Subject: [PATCH 1/2] current streaks --- Gemfile | 1 + Gemfile.lock | 7 +++++++ app/presenters/github_presenter.rb | 10 +++++++++- app/services/github_service.rb | 13 +++++++++++-- app/views/dashboard/show.html.erb | 3 +++ 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index dcca53a..faac95a 100644 --- a/Gemfile +++ b/Gemfile @@ -15,6 +15,7 @@ gem "whenever", require: false gem "hurley" gem "omniauth-github" gem "figaro" +gem "githubstats" group :development, :test do gem "byebug" diff --git a/Gemfile.lock b/Gemfile.lock index 30c4afb..32fbecf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -41,6 +41,7 @@ GEM autoprefixer-rails (6.0.3) execjs json + basiccache (1.0.0) better_errors (2.1.1) coderay (>= 1.0.0) erubis (>= 2.6.6) @@ -69,6 +70,7 @@ GEM coffee-script-source execjs coffee-script-source (1.9.1.1) + curb (0.8.8) database_cleaner (1.5.0) debug_inspector (0.0.2) diff-lcs (1.2.5) @@ -78,6 +80,10 @@ GEM multipart-post (>= 1.2, < 3) figaro (1.1.1) thor (~> 0.14) + githubstats (1.1.0) + basiccache (~> 1.0.0) + curb (~> 0.8.6) + nokogiri (~> 1.6.5) globalid (0.3.6) activesupport (>= 4.1.0) hashie (3.4.2) @@ -224,6 +230,7 @@ DEPENDENCIES coffee-rails (~> 4.1.0) database_cleaner figaro + githubstats hurley jbuilder (~> 2.0) jquery-rails diff --git a/app/presenters/github_presenter.rb b/app/presenters/github_presenter.rb index 556a720..3ff8177 100644 --- a/app/presenters/github_presenter.rb +++ b/app/presenters/github_presenter.rb @@ -32,7 +32,15 @@ def organizations end def year_commits - list = service.find_user_total_commits(user).map {|data| build_object(data)} + list = service.find_user_total_commits(user) + end + + def current_streaks + list = service.find_user_current_streak(user) + end + + def longest_streaks + list = service.find_user_longest_streak(user) end def starred_repos diff --git a/app/services/github_service.rb b/app/services/github_service.rb index c05fb5f..2ec4008 100644 --- a/app/services/github_service.rb +++ b/app/services/github_service.rb @@ -2,8 +2,9 @@ class GithubService attr_reader :connection def initialize(user) - @connection = Hurley::Client.new("https://api.github.com") + @connection = Hurley::Client.new("https://api.github.com") @connection.query[:access_token] = user.token + @stats = GithubStats.new('#{user.nickname}') end def find_user_repos(user) @@ -23,7 +24,15 @@ def find_user_organizations(user) end def find_user_total_commits(user) - parse(connection.get("repos/#{user.nickname}/gitcommit/stats/commit_activity")) + @stats.data.scores.reduce(:+) + end + + def find_user_current_streak(user) + @stats.stats.streak.count + end + + def find_user_longest_streak(user) + @stats.stats.longest_streak.count end def total_starred_repos(user) diff --git a/app/views/dashboard/show.html.erb b/app/views/dashboard/show.html.erb index c4f565a..e04b6b6 100644 --- a/app/views/dashboard/show.html.erb +++ b/app/views/dashboard/show.html.erb @@ -10,12 +10,15 @@

Total Commits

+

<%= @info.year_commits %>

Current Streak

+

<%= @info.current_streaks %>

Longest Streak

+

<%= @info.longest_streaks %>

From e29abfba3c04df59ba13c7732184af3cd1ff608b Mon Sep 17 00:00:00 2001 From: Bret Doucette Date: Tue, 27 Oct 2015 13:45:23 -0600 Subject: [PATCH 2/2] Finished stats --- app/services/github_service.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/services/github_service.rb b/app/services/github_service.rb index 2ec4008..6f1848f 100644 --- a/app/services/github_service.rb +++ b/app/services/github_service.rb @@ -4,7 +4,7 @@ class GithubService def initialize(user) @connection = Hurley::Client.new("https://api.github.com") @connection.query[:access_token] = user.token - @stats = GithubStats.new('#{user.nickname}') + @stats = GithubStats.new('bad6e') end def find_user_repos(user) @@ -28,11 +28,11 @@ def find_user_total_commits(user) end def find_user_current_streak(user) - @stats.stats.streak.count + @stats.streak.count end def find_user_longest_streak(user) - @stats.stats.longest_streak.count + @stats.longest_streak.count end def total_starred_repos(user)