Skip to content

Commit

Permalink
Activity log
Browse files Browse the repository at this point in the history
* Refactored code a little bit
* The display of commits is grouped on a per-author mode on a daily
* basis.
* For every day, all the commits under one author are listed under a
* single group in order to avoid repetition of avatars.
* Now has a separate link and it is tucked away under "Contributors"
* part.
* Shows 50 commits by default.
* Shows gravatars of the committers.
* No longer inside the side-nav element
* Spacing changes
  • Loading branch information
kgrz committed Apr 16, 2013
1 parent 536382a commit 8d071f0
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 31 deletions.
3 changes: 2 additions & 1 deletion activity/README.md
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,4 @@
# Activity # Activity


Showing the last 100 commits Showing the last 50 commits. Or, you can View all the commits on
[GitHub](https://github.com/sinatra/sinatra/commits/master)
98 changes: 68 additions & 30 deletions app.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,34 +24,54 @@
Tilt.prefer Sinatra::Glorify::Template Tilt.prefer Sinatra::Glorify::Template
set :markdown, :layout_engine => :slim set :markdown, :layout_engine => :slim
set :views, File.dirname(__FILE__) set :views, File.dirname(__FILE__)
set :ignored_dirs, %w[tmp log config public bin, activity] set :ignored_dirs, %w[tmp log config public bin activity]


before do before do
@menu = Dir.glob("./*/").map do |file| @menu = Dir.glob("./*/").map do |file|
next if settings.ignored_dirs.any? {|ignore| /#{ignore}/i =~ file} next if settings.ignored_dirs.any? {|ignore| /#{ignore}/i =~ file}
file.split('/')[1] file.split('/')[1]
end.compact.sort end.compact.sort
@menu.push "activity"
end end


helpers do helpers do
def get_activity
open("https://api.github.com/repos/sinatra/sinatra-recipes/commits?per_page=100") do |commits| def commits_url
@commits = JSON.parse(commits.read) "https://api.github.com/repos/sinatra/sinatra-recipes/commits"
@activity = @commits.map {|x| { end
"author_name" => x["commit"]["author"]["name"],
"committer_name" => x["commit"]["committer"]["name"], def commits
"merge_date" => Time.parse(x["commit"]["author"]["date"]).strftime("%d-%b-%Y"), JSON.parse(open(commits_url).read)
"commit_message" => x["commit"]["message"], end
"author_url" => x["author"]["html_url"],
"commit_url" => "https://github.com/sinatra/sinatra-recipes/commit/#{x['sha']}" def get_authors
} } commits.map do |x|
puts @activity.count {
@activity.group_by {|x| x["merge_date"] } :name => x['author']['login'],
end :avatar => x['author']['avatar_url'],
:url => x['author']['html_url']
}
end.uniq.flatten.group_by {|x| x[:name]}
end end


def get_activity
commits.map do |x|
{
:author_name => x['author']['login'],
:merge_date => Time.parse(x['commit']['author']['date']).strftime("%d-%B-%Y"),
:commit_message => x['commit']['message'],
:commit_url => "https://github.com/sinatra/sinatra-recipes/commit/#{x['sha']}"
}
end.group_by {|x| x[:merge_date] }
end


def get_activity_by_author
get_activity.map do |k,v|
{
:date => k,
:activity_by_author => v.group_by {|z| z[:author_name] }
}
end
end
end end


get '/' do get '/' do
Expand All @@ -67,7 +87,6 @@ def get_activity
get '/p/:topic' do get '/p/:topic' do
pass if params[:topic] == '..' pass if params[:topic] == '..'
@readme = true @readme = true
@activity = get_activity if params[:topic] == 'activity'
@children = Dir.glob("./#{params[:topic]}/*.md").map do |file| @children = Dir.glob("./#{params[:topic]}/*.md").map do |file|
next if file =~ /README/ next if file =~ /README/
next if file.empty? or file.nil? next if file.empty? or file.nil?
Expand All @@ -84,6 +103,12 @@ def get_activity
markdown md markdown md
end end


get '/activity' do
pass if params[:topic] == '..'
@authors = get_authors
@activity = get_activity_by_author
markdown :'activity/README'
end


get '/style.css' do get '/style.css' do
sass :style sass :style
Expand Down Expand Up @@ -145,23 +170,30 @@ def get_activity
a href="/p/#{params[:topic]}/#{child}?#article" a href="/p/#{params[:topic]}/#{child}?#article"
== child.capitalize.sub('_', ' ') == child.capitalize.sub('_', ' ')
- if @activity - if @activity
- @activity.each do |date, activities| #activity
h3 #{date} - @activity.each do |x|
h3 #{x[:date]}
hr hr
ul.nodec ul.nodec
- activities.each do |activity| - x[:activity_by_author].each do |author_name, activities|
- author = @authors[author_name].first
li li
| <a href="#{activity['author_url']}">#{activity['author_name']}</a> | <img src="#{author[:avatar]}">
| merged the changes: | <a href="#{author[:url]}">#{author[:name]}</a>
pre | authored the changes:
= "#{activity['commit_message']}" ul.nodec
small - activities.each do |activity|
a href="#{activity['commit_url']}" li
| View this commit on github pre

= "#{activity[:commit_message]}"
#contributors small
a href="#{activity[:commit_url]}"
| View this commit on github
#contributors
- if @contributors - if @contributors
h2 Contributors h2 Contributors
p
|Browse the <a href="/activity">latest activity</a>
p p
| These recipes are provided by the following outsanding members of the Sinatra | These recipes are provided by the following outsanding members of the Sinatra
| community: | community:
Expand Down Expand Up @@ -277,7 +309,13 @@ def get_activity
color: #CCC color: #CCC
a:hover, a:active a:hover, a:active
color: #8F8F8F color: #8F8F8F

#activity
img
height: 50px
width: 50px
padding-right: 15px
ul
padding-left: 0px
#sidebar #sidebar
width: 25% width: 25%
float: right float: right
Expand Down

0 comments on commit 8d071f0

Please sign in to comment.