Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
85a792ff7fd1
Commit
85a792ff
authored
Jan 03, 2013
by
Dmitriy Zaporozhets
Browse files
more refactoring using models/concerns
parent
69cfbf2f381f
Changes
11
Hide whitespace changes
Inline
Side-by-side
app/models/concerns/issuable.rb
0 → 100644
View file @
85a792ff
# == Issuable concern
#
# Contains common functionality shared between Issues and MergeRequests
#
# Used by Issue, MergeRequest
#
module
Issuable
extend
ActiveSupport
::
Concern
included
do
belongs_to
:project
belongs_to
:author
,
class_name:
"User"
belongs_to
:assignee
,
class_name:
"User"
belongs_to
:milestone
has_many
:notes
,
as: :noteable
,
dependent: :destroy
validates
:project
,
presence:
true
validates
:author
,
presence:
true
validates
:title
,
presence:
true
,
length:
{
within:
0
..
255
}
validates
:closed
,
inclusion:
{
in:
[
true
,
false
]
}
scope
:opened
,
where
(
closed:
false
)
scope
:closed
,
where
(
closed:
true
)
scope
:of_group
,
->
(
group
)
{
where
(
project_id:
group
.
project_ids
)
}
scope
:assigned
,
->
(
u
)
{
where
(
assignee_id:
u
.
id
)}
scope
:recent
,
order
(
"created_at DESC"
)
delegate
:name
,
:email
,
to: :author
,
prefix:
true
delegate
:name
,
:email
,
to: :assignee
,
allow_nil:
true
,
prefix:
true
attr_accessor
:author_id_of_changes
end
module
ClassMethods
def
search
(
query
)
where
(
"title like :query"
,
query:
"%
#{
query
}
%"
)
end
end
def
today?
Date
.
today
==
created_at
.
to_date
end
def
new?
today?
&&
created_at
==
updated_at
end
def
is_assigned?
!!
assignee_id
end
def
is_being_reassigned?
assignee_id_changed?
end
def
is_being_closed?
closed_changed?
&&
closed
end
def
is_being_reopened?
closed_changed?
&&
!
closed
end
# Return the number of +1 comments (upvotes)
def
upvotes
notes
.
select
(
&
:upvote?
).
size
end
def
upvotes_in_percent
if
votes_count
.
zero?
0
else
100.0
/
votes_count
*
upvotes
end
end
# Return the number of -1 comments (downvotes)
def
downvotes
notes
.
select
(
&
:downvote?
).
size
end
def
downvotes_in_percent
if
votes_count
.
zero?
0
else
100.0
-
upvotes_in_percent
end
end
# Return the total number of votes
def
votes_count
upvotes
+
downvotes
end
end
app/models/issue.rb
View file @
85a792ff
...
...
@@ -17,8 +17,7 @@
#
class
Issue
<
ActiveRecord
::
Base
include
IssueCommonality
include
Votes
include
Issuable
attr_accessible
:title
,
:assignee_id
,
:closed
,
:position
,
:description
,
:milestone_id
,
:label_list
,
:author_id_of_changes
...
...
app/models/merge_request.rb
View file @
85a792ff
...
...
@@ -23,8 +23,7 @@
require
Rails
.
root
.
join
(
"lib/static_model"
)
class
MergeRequest
<
ActiveRecord
::
Base
include
IssueCommonality
include
Votes
include
Issuable
attr_accessible
:title
,
:assignee_id
,
:closed
,
:target_branch
,
:source_branch
,
:milestone_id
,
:author_id_of_changes
...
...
app/models/project.rb
View file @
85a792ff
...
...
@@ -21,7 +21,7 @@
require
"grit"
class
Project
<
ActiveRecord
::
Base
include
Git
Host
include
Git
olited
class
TransferError
<
StandardError
;
end
...
...
@@ -408,7 +408,7 @@
Gitlab
::
ProjectMover
.
new
(
self
,
old_dir
,
new_dir
).
execute
git
_host
.
move_repository
(
old_repo
,
self
)
git
olite
.
move_repository
(
old_repo
,
self
)
save!
end
...
...
@@ -670,7 +670,7 @@
end
def
url_to_repo
git
_host
.
url_to_repo
(
path_with_namespace
)
git
olite
.
url_to_repo
(
path_with_namespace
)
end
def
path_to_repo
...
...
@@ -682,7 +682,7 @@
end
def
update_repository
git
_host
.
update_repository
(
self
)
git
olite
.
update_repository
(
self
)
end
def
destroy_repository
...
...
@@ -686,7 +686,7 @@
end
def
destroy_repository
git
_host
.
remove_repository
(
self
)
git
olite
.
remove_repository
(
self
)
end
def
repo_exists?
...
...
app/models/protected_branch.rb
View file @
85a792ff
...
...
@@ -10,7 +10,7 @@
#
class
ProtectedBranch
<
ActiveRecord
::
Base
include
Git
Host
include
Git
olited
attr_accessible
:name
...
...
@@ -22,7 +22,7 @@
after_destroy
:update_repository
def
update_repository
git
_host
.
update_repository
(
project
)
git
olite
.
update_repository
(
project
)
end
def
commit
...
...
app/models/users_project.rb
View file @
85a792ff
...
...
@@ -11,7 +11,7 @@
#
class
UsersProject
<
ActiveRecord
::
Base
include
Git
Host
include
Git
olited
GUEST
=
10
REPORTER
=
20
...
...
@@ -152,7 +152,7 @@
end
def
update_repository
git
_host
.
update_repository
(
project
)
git
olite
.
update_repository
(
project
)
end
def
project_access_human
...
...
app/observers/key_observer.rb
View file @
85a792ff
class
KeyObserver
<
ActiveRecord
::
Observer
include
Git
Host
include
Git
olited
def
after_save
(
key
)
...
...
@@ -3,7 +3,7 @@
def
after_save
(
key
)
git
_host
.
set_key
(
key
.
identifier
,
key
.
key
,
key
.
projects
)
git
olite
.
set_key
(
key
.
identifier
,
key
.
key
,
key
.
projects
)
end
def
after_destroy
(
key
)
return
if
key
.
is_deploy_key
&&
!
key
.
last_deploy?
...
...
@@ -6,7 +6,7 @@
end
def
after_destroy
(
key
)
return
if
key
.
is_deploy_key
&&
!
key
.
last_deploy?
git
_host
.
remove_key
(
key
.
identifier
,
key
.
projects
)
git
olite
.
remove_key
(
key
.
identifier
,
key
.
projects
)
end
end
lib/git_host.rb
deleted
100644 → 0
View file @
69cfbf2f
# == GitHost role
#
# Provide a shortcut to Gitlab::Gitolite instance
#
# Used by Project, UsersProject
#
module
GitHost
def
git_host
Gitlab
::
Gitolite
.
new
end
end
lib/gitolited.rb
0 → 100644
View file @
85a792ff
# == Gitolited mixin
#
# Provide a shortcut to Gitlab::Gitolite instance by gitolite
#
# Used by Project, UsersProject, etc
#
module
Gitolited
def
gitolite
Gitlab
::
Gitolite
.
new
end
end
lib/issue_commonality.rb
deleted
100644 → 0
View file @
69cfbf2f
# == IssueCommonality role
#
# Contains common functionality shared between Issues and MergeRequests
#
# Used by Issue, MergeRequest
#
module
IssueCommonality
extend
ActiveSupport
::
Concern
included
do
belongs_to
:project
belongs_to
:author
,
class_name:
"User"
belongs_to
:assignee
,
class_name:
"User"
belongs_to
:milestone
has_many
:notes
,
as: :noteable
,
dependent: :destroy
validates
:project
,
presence:
true
validates
:author
,
presence:
true
validates
:title
,
presence:
true
,
length:
{
within:
0
..
255
}
validates
:closed
,
inclusion:
{
in:
[
true
,
false
]
}
scope
:opened
,
where
(
closed:
false
)
scope
:closed
,
where
(
closed:
true
)
scope
:of_group
,
->
(
group
)
{
where
(
project_id:
group
.
project_ids
)
}
scope
:assigned
,
->
(
u
)
{
where
(
assignee_id:
u
.
id
)}
scope
:recent
,
order
(
"created_at DESC"
)
delegate
:name
,
:email
,
to: :author
,
prefix:
true
delegate
:name
,
:email
,
to: :assignee
,
allow_nil:
true
,
prefix:
true
attr_accessor
:author_id_of_changes
end
module
ClassMethods
def
search
(
query
)
where
(
"title like :query"
,
query:
"%
#{
query
}
%"
)
end
end
def
today?
Date
.
today
==
created_at
.
to_date
end
def
new?
today?
&&
created_at
==
updated_at
end
def
is_assigned?
!!
assignee_id
end
def
is_being_reassigned?
assignee_id_changed?
end
def
is_being_closed?
closed_changed?
&&
closed
end
def
is_being_reopened?
closed_changed?
&&
!
closed
end
end
lib/votes.rb
deleted
100644 → 0
View file @
69cfbf2f
# == Votes role
#
# Provides functionality to upvote/downvote entity
# based on +1 and -1 notes
#
# Used for Issue and Merge Request
#
module
Votes
# Return the number of +1 comments (upvotes)
def
upvotes
notes
.
select
(
&
:upvote?
).
size
end
def
upvotes_in_percent
if
votes_count
.
zero?
0
else
100.0
/
votes_count
*
upvotes
end
end
# Return the number of -1 comments (downvotes)
def
downvotes
notes
.
select
(
&
:downvote?
).
size
end
def
downvotes_in_percent
if
votes_count
.
zero?
0
else
100.0
-
upvotes_in_percent
end
end
# Return the total number of votes
def
votes_count
upvotes
+
downvotes
end
end
Write
Preview
Supports
Markdown
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