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
Tatuya Kamada
gitlab-ce
Commits
43afe46b
Commit
43afe46b
authored
Mar 22, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor contributions events and write tests for calendar
parent
20a12438
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
59 additions
and
18 deletions
+59
-18
app/controllers/users_controller.rb
app/controllers/users_controller.rb
+4
-6
app/models/event.rb
app/models/event.rb
+6
-0
app/models/user.rb
app/models/user.rb
+2
-5
app/views/users/_projects.html.haml
app/views/users/_projects.html.haml
+1
-1
features/steps/user.rb
features/steps/user.rb
+35
-0
features/user.feature
features/user.feature
+9
-0
lib/gitlab/contributions_calendar.rb
lib/gitlab/contributions_calendar.rb
+2
-6
No files found.
app/controllers/users_controller.rb
View file @
43afe46b
...
@@ -4,10 +4,7 @@ class UsersController < ApplicationController
...
@@ -4,10 +4,7 @@ class UsersController < ApplicationController
layout
:determine_layout
layout
:determine_layout
def
show
def
show
@contributed_projects
=
Project
.
@contributed_projects
=
contributed_projects
.
joined
(
@user
).
where
(
id:
authorized_projects_ids
&
@user
.
contributed_projects_ids
).
in_group_namespace
.
includes
(
:namespace
).
reject
(
&
:forked?
)
reject
(
&
:forked?
)
@projects
=
@user
.
personal_projects
.
@projects
=
@user
.
personal_projects
.
...
@@ -76,11 +73,12 @@ class UsersController < ApplicationController
...
@@ -76,11 +73,12 @@ class UsersController < ApplicationController
def
contributed_projects
def
contributed_projects
@contributed_projects
=
Project
.
@contributed_projects
=
Project
.
where
(
id:
authorized_projects_ids
&
@user
.
contributed_projects_ids
).
reject
(
&
:forked?
)
where
(
id:
authorized_projects_ids
&
@user
.
contributed_projects_ids
).
includes
(
:namespace
)
end
end
def
contributions_calendar
def
contributions_calendar
@contributions_calendar
||=
Gitlab
::
ContributionsCalendar
.
@contributions_calendar
||=
Gitlab
::
ContributionsCalendar
.
new
(
contributed_projects
,
@user
)
new
(
contributed_projects
.
reject
(
&
:forked?
)
,
@user
)
end
end
end
end
app/models/event.rb
View file @
43afe46b
...
@@ -55,6 +55,12 @@ class Event < ActiveRecord::Base
...
@@ -55,6 +55,12 @@ class Event < ActiveRecord::Base
order
(
'id DESC'
).
limit
(
100
).
order
(
'id DESC'
).
limit
(
100
).
update_all
(
updated_at:
Time
.
now
)
update_all
(
updated_at:
Time
.
now
)
end
end
def
contributions
where
(
"action = ? OR (target_type in (?) AND action in (?))"
,
Event
::
PUSHED
,
[
"MergeRequest"
,
"Issue"
],
[
Event
::
CREATED
,
Event
::
CLOSED
,
Event
::
MERGED
])
end
end
end
def
proper?
def
proper?
...
...
app/models/user.rb
View file @
43afe46b
...
@@ -603,13 +603,10 @@ class User < ActiveRecord::Base
...
@@ -603,13 +603,10 @@ class User < ActiveRecord::Base
end
end
def
contributed_projects_ids
def
contributed_projects_ids
Event
.
where
(
author_id:
self
).
Event
.
contributions
.
where
(
author_id:
self
).
where
(
"created_at > ?"
,
Time
.
now
-
1
.
year
).
where
(
"created_at > ?"
,
Time
.
now
-
1
.
year
).
where
(
"action = :pushed OR (target_type = 'MergeRequest' AND action = :created)"
,
pushed:
Event
::
PUSHED
,
created:
Event
::
CREATED
).
reorder
(
project_id: :desc
).
reorder
(
project_id: :desc
).
select
(
:project_id
).
select
(
:project_id
).
uniq
uniq
.
map
(
&
:project_id
)
.
map
(
&
:project_id
)
end
end
end
end
app/views/users/_projects.html.haml
View file @
43afe46b
-
if
@contributed_projects
.
present?
-
if
@contributed_projects
.
present?
.panel.panel-default
.panel.panel-default
.contributed-projects
.panel-heading
Projects contributed to
.panel-heading
Projects contributed to
=
render
'shared/projects_list'
,
=
render
'shared/projects_list'
,
projects:
@contributed_projects
.
sort_by
(
&
:star_count
).
reverse
,
projects:
@contributed_projects
.
sort_by
(
&
:star_count
).
reverse
,
...
...
features/steps/user.rb
View file @
43afe46b
...
@@ -7,4 +7,39 @@ class Spinach::Features::User < Spinach::FeatureSteps
...
@@ -7,4 +7,39 @@ class Spinach::Features::User < Spinach::FeatureSteps
step
'I should see user "John Doe" page'
do
step
'I should see user "John Doe" page'
do
expect
(
title
).
to
match
(
/^\s*John Doe/
)
expect
(
title
).
to
match
(
/^\s*John Doe/
)
end
end
step
'"John Doe" has contributions'
do
user
=
User
.
find_by
(
name:
'John Doe'
)
project
=
contributed_project
# Issue controbution
issue_params
=
{
title:
'Bug in old browser'
}
Issues
::
CreateService
.
new
(
project
,
user
,
issue_params
).
execute
# Push code contribution
push_params
=
{
project:
project
,
action:
Event
::
PUSHED
,
author_id:
user
.
id
,
data:
{
commit_count:
3
}
}
Event
.
create
(
push_params
)
end
step
'I should see contributed projects'
do
within
'.contributed-projects'
do
page
.
should
have_content
(
@contributed_project
.
name
)
end
end
step
'I should see contributions calendar'
do
within
'.calendar'
do
page
.
should
have_css
(
'.graph-rect.r2.q2'
)
end
end
def
contributed_project
@contributed_project
||=
create
(
:project
,
:public
)
end
end
end
features/user.feature
View file @
43afe46b
...
@@ -67,3 +67,12 @@ Feature: User
...
@@ -67,3 +67,12 @@ Feature: User
And
I should see project
"Enterprise"
And
I should see project
"Enterprise"
And
I should not see project
"Internal"
And
I should not see project
"Internal"
And
I should not see project
"Community"
And
I should not see project
"Community"
@javascript
Scenario
:
"John Doe" contribution profile
Given
I sign in as a user
And
"John Doe"
has contributions
When
I visit user
"John Doe"
page
Then
I should see user
"John Doe"
page
And
I should see contributed projects
And
I should see contributions calendar
lib/gitlab/contributions_calendar.rb
View file @
43afe46b
...
@@ -14,7 +14,7 @@ module Gitlab
...
@@ -14,7 +14,7 @@ module Gitlab
date_from
=
1
.
year
.
ago
date_from
=
1
.
year
.
ago
date_to
=
Date
.
today
date_to
=
Date
.
today
events
=
Event
.
where
(
author_id:
user
.
id
).
where
(
action:
event_type
).
events
=
Event
.
contributions
.
where
(
author_id:
user
.
id
).
where
(
"created_at > ?"
,
date_from
).
where
(
project_id:
projects
)
where
(
"created_at > ?"
,
date_from
).
where
(
project_id:
projects
)
grouped_events
=
events
.
to_a
.
group_by
{
|
event
|
event
.
created_at
.
to_date
.
to_s
}
grouped_events
=
events
.
to_a
.
group_by
{
|
event
|
event
.
created_at
.
to_date
.
to_s
}
...
@@ -41,7 +41,7 @@ module Gitlab
...
@@ -41,7 +41,7 @@ module Gitlab
end
end
def
events_by_date
(
date
)
def
events_by_date
(
date
)
events
=
Event
.
where
(
author_id:
user
.
id
).
where
(
action:
event_type
).
events
=
Event
.
contributions
.
where
(
author_id:
user
.
id
).
where
(
"created_at > ? AND created_at < ?"
,
date
.
beginning_of_day
,
date
.
end_of_day
).
where
(
"created_at > ? AND created_at < ?"
,
date
.
beginning_of_day
,
date
.
end_of_day
).
where
(
project_id:
projects
)
where
(
project_id:
projects
)
...
@@ -57,9 +57,5 @@ module Gitlab
...
@@ -57,9 +57,5 @@ module Gitlab
def
starting_month
def
starting_month
Date
.
today
.
strftime
(
"%m"
).
to_i
Date
.
today
.
strftime
(
"%m"
).
to_i
end
end
def
event_type
[
Event
::
PUSHED
,
Event
::
CREATED
,
Event
::
CLOSED
,
Event
::
MERGED
]
end
end
end
end
end
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