Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
a9288e55
Commit
a9288e55
authored
Jan 29, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup and make contribution calendar faster
parent
6e1f9e74
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
40 additions
and
163 deletions
+40
-163
app/assets/javascripts/calendar.js.coffee
app/assets/javascripts/calendar.js.coffee
+3
-39
app/controllers/users_controller.rb
app/controllers/users_controller.rb
+3
-16
app/models/repository.rb
app/models/repository.rb
+14
-17
app/views/users/_calendar.html.haml
app/views/users/_calendar.html.haml
+2
-4
app/views/users/_calendar_onclick.html.haml
app/views/users/_calendar_onclick.html.haml
+0
-25
app/views/users/show.html.haml
app/views/users/show.html.haml
+3
-1
lib/gitlab/commits_calendar.rb
lib/gitlab/commits_calendar.rb
+13
-59
spec/controllers/users_controller_spec.rb
spec/controllers/users_controller_spec.rb
+2
-2
No files found.
app/assets/javascripts/calendar.js.coffee
View file @
a9288e55
...
...
@@ -4,11 +4,13 @@ class @calendar
day
:
"numeric"
year
:
"numeric"
constructor
:
(
timestamps
,
starting_year
,
starting_month
,
activities_path
)
->
constructor
:
(
timestamps
,
starting_year
,
starting_month
)
->
cal
=
new
CalHeatMap
()
cal
.
init
itemName
:
[
"commit"
]
data
:
timestamps
domain
:
"year"
subDomain
:
"month"
start
:
new
Date
(
starting_year
,
starting_month
)
domainLabelFormat
:
"%b"
id
:
"cal-heatmap"
...
...
@@ -29,43 +31,5 @@ class @calendar
]
legendCellPadding
:
3
onClick
:
(
date
,
count
)
->
$
.
ajax
url
:
activities_path
data
:
date
:
date
dataType
:
"json"
success
:
(
data
)
->
$
(
"#loading_commits"
).
fadeIn
()
calendar
.
calendarOnClick
data
,
date
,
count
setTimeout
(
->
$
(
"#calendar_onclick_placeholder"
).
fadeIn
500
return
),
400
setTimeout
(
->
$
(
"#loading_commits"
).
hide
()
return
),
400
return
return
return
@
calendarOnClick
:
(
data
,
date
,
nb
)
->
$
(
"#calendar_onclick_placeholder"
).
hide
()
$
(
"#calendar_onclick_placeholder"
).
html
->
"<span class='calendar_onclick_second'><b>"
+
((
if
nb
is
null
then
"no"
else
nb
))
+
"</b><span class='calendar_commit_date'> commit"
+
((
if
(
nb
isnt
1
)
then
"s"
else
""
))
+
" "
+
date
.
toLocaleDateString
(
"en-US"
,
options
)
+
"</span><hr class='calendar_onclick_hr'></span>"
$
.
each
data
,
(
key
,
data
)
->
$
.
each
data
,
(
index
,
data
)
->
$
(
"#calendar_onclick_placeholder"
).
append
->
"Pushed <b>"
+
((
if
data
is
null
then
"no"
else
data
))
+
" commit"
+
((
if
(
data
isnt
1
)
then
"s"
else
""
))
+
"</b> to <a href='/"
+
index
+
"'>"
+
index
+
"</a><hr class='calendar_onclick_hr'>"
return
return
return
app/controllers/users_controller.rb
View file @
a9288e55
...
...
@@ -25,12 +25,12 @@ class UsersController < ApplicationController
@title
=
@user
.
name
# Get user repositories and collect timestamps for commits
user_repositories
=
visible_projects
.
map
(
&
:repository
)
@timestamps
=
Gitlab
::
CommitsCalendar
.
create_timestamp
(
user_repositories
,
@user
,
false
)
calendar
=
Gitlab
::
CommitsCalendar
.
new
(
user_repositories
,
@user
)
@timestamps
=
calendar
.
timestamps
@starting_year
=
(
Time
.
now
-
1
.
year
).
strftime
(
"%Y"
)
@starting_month
=
Date
.
today
.
strftime
(
"%m"
).
to_i
@last_commit_date
=
Gitlab
::
CommitsCalendar
.
last_commit_date
(
@timestamps
)
respond_to
do
|
format
|
format
.
html
...
...
@@ -38,19 +38,6 @@ class UsersController < ApplicationController
end
end
def
activities
user
=
User
.
find_by_username!
(
params
[
:username
])
# Projects user can view
visible_projects
=
ProjectsFinder
.
new
.
execute
(
current_user
)
user_repositories
=
visible_projects
.
map
(
&
:repository
)
user_activities
=
Gitlab
::
CommitsCalendar
.
create_timestamp
(
user_repositories
,
user
,
true
)
user_activities
=
Gitlab
::
CommitsCalendar
.
commit_activity_match
(
user_activities
,
params
[
:date
])
render
json:
user_activities
.
to_json
end
def
determine_layout
if
current_user
'navless'
...
...
app/models/repository.rb
View file @
a9288e55
...
...
@@ -139,39 +139,36 @@ class Repository
def
graph_log
Rails
.
cache
.
fetch
(
cache_key
(
:graph_log
))
do
# handle empty repos that don't have a root_ref set yet
unless
raw_repository
.
root_ref
.
present?
raw_repository
.
root_ref
=
'refs/heads/master'
end
commits
=
raw_repository
.
log
(
limit:
6000
,
skip_merges:
true
,
ref:
raw_repository
.
root_ref
)
commits
=
raw_repository
.
log
(
limit:
6000
,
skip_merges:
true
,
ref:
root_ref
)
commits
.
map
do
|
rugged_commit
|
commit
=
Gitlab
::
Git
::
Commit
.
new
(
rugged_commit
)
{
author_name:
commit
.
author_name
.
force_encoding
(
'UTF-8'
),
author_email:
commit
.
author_email
.
force_encoding
(
'UTF-8'
),
additions:
commit
.
stats
.
additions
,
deletions:
commit
.
stats
.
deletions
,
date:
commit
.
committed_date
}
end
end
end
def
graph_logs_by_user_email
(
user
)
graph_log
.
select
{
|
u_email
|
u_email
[
:author_email
]
==
user
.
email
}
end
def
timestamps_by_user_log
(
user
)
args
=
%W(git log --author=
#{
user
.
email
}
--since=
#{
(
Date
.
today
-
1
.
year
).
to_s
}
--pretty=format:%cd --date=short)
dates
=
Gitlab
::
Popen
.
popen
(
args
,
path_to_repo
).
first
.
split
(
"
\n
"
)
def
timestamps_by_user_from_graph_log
(
user
)
graph_logs_by_user_email
(
user
).
map
{
|
graph_log
|
graph_log
[
:date
].
to_time
.
to_i
}
if
dates
.
present?
dates
else
[]
end
end
def
commits_
log_of_user_by_date
(
user
)
timestamps_by_user_
from_graph_
log
(
user
).
def
commits_
per_day_for_user
(
user
)
timestamps_by_user_log
(
user
).
group_by
{
|
commit_date
|
commit_date
}.
inject
({})
do
|
hash
,
(
timestamp_date
,
commits
)
|
hash
[
timestamp_date
]
=
commits
.
count
...
...
app/views/users/_calendar.html.haml
View file @
a9288e55
#cal-heatmap
.calendar
:javascript
:javascript
new
calendar
(
#{
@timestamps
.
to_json
}
,
#{
@starting_year
}
,
#{
@starting_month
}
,
'
#{
user_activities_path
}
'
#{
@starting_month
}
);
=
render
"calendar_onclick"
app/views/users/_calendar_onclick.html.haml
deleted
100644 → 0
View file @
6e1f9e74
#calendar_commit_activity
.calendar_commit_activity
%h4
.activity_title
Commit Activity:
#loading_commits
%section
.text-center
%h3
%i
.icon-spinner.icon-spin
#calendar_onclick_placeholder
.calendar_onclick_placeholder
%span
.calendar_onclick_second.calendar_onclick_second
-
if
@timestamps
.
empty?
%span
.calendar_activity_summary
%strong
>
#{
@user
.
username
}
has no activity
-
else
%span
.calendar_activity_summary
%strong
>
#{
@user
.
username
}
's last commit was on
%span
.commit_date
#{
@last_commit_date
}
%hr
.calendar_onclick_hr
:javascript
$
(
"
#loading_commits
"
).
hide
();
app/views/users/show.html.haml
View file @
a9288e55
...
...
@@ -18,8 +18,10 @@
%h4
Groups:
=
render
'groups'
,
groups:
@groups
%hr
%h4
Calendar:
=
render
'calendar'
%div
=
render
'calendar'
%hr
%h4
User Activity:
...
...
lib/gitlab/commits_calendar.rb
View file @
a9288e55
module
Gitlab
class
CommitsCalendar
def
self
.
create_timestamp
(
repositories
,
user
,
show_activity
)
timestamps
=
{}
repositories
.
each
do
|
raw_repository
|
if
raw_repository
.
exists?
commits_log
=
raw_repository
.
commits_log_of_user_by_date
(
user
)
attr_reader
:timestamps
populated_timestamps
=
if
show_activity
populate_timestamps_by_project
(
commits_log
,
timestamps
,
raw_repository
)
else
populate_timestamps
(
commits_log
,
timestamps
)
end
timestamps
.
merge!
(
populated_timestamps
)
end
end
timestamps
end
def
initialize
(
repositories
,
user
)
@timestamps
=
{}
date_timestamps
=
[]
def
self
.
populate_timestamps
(
commits_log
,
timestamps
)
commits_log
.
each
do
|
timestamp_date
,
commits_count
|
hash
=
{
"
#{
timestamp_date
}
"
=>
commits_count
}
if
timestamps
.
has_key?
(
"
#{
timestamp_date
}
"
)
timestamps
.
merge!
(
hash
)
do
|
timestamp_date
,
commits_count
,
new_commits_count
|
commits_count
=
commits_count
.
to_i
+
new_commits_count
end
else
timestamps
.
merge!
(
hash
)
end
repositories
.
select
(
&
:exists?
).
reject
(
&
:empty?
).
each
do
|
raw_repository
|
commits_log
=
raw_repository
.
commits_per_day_for_user
(
user
)
date_timestamps
<<
commits_log
end
timestamps
end
def
self
.
populate_timestamps_by_project
(
commits_log
,
timestamps
,
project
)
commits_log
.
each
do
|
timestamp_date
,
commits_count
|
if
timestamps
.
has_key?
(
"
#{
timestamp_date
}
"
)
timestamps
[
"
#{
timestamp_date
}
"
].
merge!
(
project
.
path_with_namespace
=>
commits_count
)
else
hash
=
{
"
#{
timestamp_date
}
"
=>
{
project
.
path_with_namespace
=>
commits_count
}
}
timestamps
.
merge!
(
hash
)
end
date_timestamps
=
date_timestamps
.
inject
do
|
collection
,
date
|
collection
.
merge
(
date
)
{
|
k
,
old_v
,
new_v
|
old_v
+
new_v
}
end
timestamps
end
def
self
.
latest_commit_date
(
timestamps
)
if
timestamps
.
nil?
||
timestamps
.
empty?
DateTime
.
now
.
to_date
else
Time
.
at
(
timestamps
.
keys
.
first
.
to_i
).
to_date
date_timestamps
||=
[]
date_timestamps
.
each
do
|
date
,
commits
|
timestamp
=
Date
.
parse
(
date
).
to_time
.
to_i
.
to_s
@timestamps
[
timestamp
]
=
commits
end
end
def
self
.
last_commit_date
(
timestamps
)
latest_commit_date
(
timestamps
).
to_formatted_s
(
:long
).
to_s
end
def
self
.
commit_activity_match
(
user_activities
,
date
)
user_activities
.
select
{
|
x
|
Time
.
at
(
x
.
to_i
)
==
Time
.
parse
(
date
)
}
end
end
end
spec/controllers/users_controller_spec.rb
View file @
a9288e55
...
...
@@ -2,12 +2,12 @@ require 'spec_helper'
describe
UsersController
do
let
(
:user
)
{
create
(
:user
,
username:
"user1"
,
name:
"User 1"
,
email:
"user1@gitlab.com"
)
}
before
do
sign_in
(
user
)
end
describe
"GET #show"
do
describe
"GET #show"
do
render_views
before
do
get
:show
,
username:
user
.
username
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment