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
iv
gitlab-ce
Commits
da03a5c7
Commit
da03a5c7
authored
Jan 03, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more refactoring using models/concerns
parent
40a956eb
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
58 additions
and
68 deletions
+58
-68
app/models/concerns/issuable.rb
app/models/concerns/issuable.rb
+33
-2
app/models/issue.rb
app/models/issue.rb
+1
-2
app/models/merge_request.rb
app/models/merge_request.rb
+1
-2
app/models/project.rb
app/models/project.rb
+5
-5
app/models/protected_branch.rb
app/models/protected_branch.rb
+2
-2
app/models/users_project.rb
app/models/users_project.rb
+2
-2
app/observers/key_observer.rb
app/observers/key_observer.rb
+3
-3
lib/git_host.rb
lib/git_host.rb
+0
-11
lib/gitolited.rb
lib/gitolited.rb
+11
-0
lib/votes.rb
lib/votes.rb
+0
-39
No files found.
lib/issue_commonality
.rb
→
app/models/concerns/issuable
.rb
View file @
da03a5c7
# == Issu
eCommonality role
# == Issu
able concern
#
#
# Contains common functionality shared between Issues and MergeRequests
# Contains common functionality shared between Issues and MergeRequests
#
#
# Used by Issue, MergeRequest
# Used by Issue, MergeRequest
#
#
module
Issu
eCommonality
module
Issu
able
extend
ActiveSupport
::
Concern
extend
ActiveSupport
::
Concern
included
do
included
do
...
@@ -68,4 +68,35 @@ module IssueCommonality
...
@@ -68,4 +68,35 @@ module IssueCommonality
def
is_being_reopened?
def
is_being_reopened?
closed_changed?
&&
!
closed
closed_changed?
&&
!
closed
end
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
end
app/models/issue.rb
View file @
da03a5c7
...
@@ -17,8 +17,7 @@
...
@@ -17,8 +17,7 @@
#
#
class
Issue
<
ActiveRecord
::
Base
class
Issue
<
ActiveRecord
::
Base
include
IssueCommonality
include
Issuable
include
Votes
attr_accessible
:title
,
:assignee_id
,
:closed
,
:position
,
:description
,
attr_accessible
:title
,
:assignee_id
,
:closed
,
:position
,
:description
,
:milestone_id
,
:label_list
,
:author_id_of_changes
:milestone_id
,
:label_list
,
:author_id_of_changes
...
...
app/models/merge_request.rb
View file @
da03a5c7
...
@@ -23,8 +23,7 @@ require Rails.root.join("app/models/commit")
...
@@ -23,8 +23,7 @@ require Rails.root.join("app/models/commit")
require
Rails
.
root
.
join
(
"lib/static_model"
)
require
Rails
.
root
.
join
(
"lib/static_model"
)
class
MergeRequest
<
ActiveRecord
::
Base
class
MergeRequest
<
ActiveRecord
::
Base
include
IssueCommonality
include
Issuable
include
Votes
attr_accessible
:title
,
:assignee_id
,
:closed
,
:target_branch
,
:source_branch
,
:milestone_id
,
attr_accessible
:title
,
:assignee_id
,
:closed
,
:target_branch
,
:source_branch
,
:milestone_id
,
:author_id_of_changes
:author_id_of_changes
...
...
app/models/project.rb
View file @
da03a5c7
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
require
"grit"
require
"grit"
class
Project
<
ActiveRecord
::
Base
class
Project
<
ActiveRecord
::
Base
include
Git
Host
include
Git
olited
class
TransferError
<
StandardError
;
end
class
TransferError
<
StandardError
;
end
...
@@ -408,7 +408,7 @@ class Project < ActiveRecord::Base
...
@@ -408,7 +408,7 @@ class Project < ActiveRecord::Base
Gitlab
::
ProjectMover
.
new
(
self
,
old_dir
,
new_dir
).
execute
Gitlab
::
ProjectMover
.
new
(
self
,
old_dir
,
new_dir
).
execute
git
_host
.
move_repository
(
old_repo
,
self
)
git
olite
.
move_repository
(
old_repo
,
self
)
save!
save!
end
end
...
@@ -670,7 +670,7 @@ class Project < ActiveRecord::Base
...
@@ -670,7 +670,7 @@ class Project < ActiveRecord::Base
end
end
def
url_to_repo
def
url_to_repo
git
_host
.
url_to_repo
(
path_with_namespace
)
git
olite
.
url_to_repo
(
path_with_namespace
)
end
end
def
path_to_repo
def
path_to_repo
...
@@ -682,11 +682,11 @@ class Project < ActiveRecord::Base
...
@@ -682,11 +682,11 @@ class Project < ActiveRecord::Base
end
end
def
update_repository
def
update_repository
git
_host
.
update_repository
(
self
)
git
olite
.
update_repository
(
self
)
end
end
def
destroy_repository
def
destroy_repository
git
_host
.
remove_repository
(
self
)
git
olite
.
remove_repository
(
self
)
end
end
def
repo_exists?
def
repo_exists?
...
...
app/models/protected_branch.rb
View file @
da03a5c7
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
#
#
class
ProtectedBranch
<
ActiveRecord
::
Base
class
ProtectedBranch
<
ActiveRecord
::
Base
include
Git
Host
include
Git
olited
attr_accessible
:name
attr_accessible
:name
...
@@ -22,7 +22,7 @@ class ProtectedBranch < ActiveRecord::Base
...
@@ -22,7 +22,7 @@ class ProtectedBranch < ActiveRecord::Base
after_destroy
:update_repository
after_destroy
:update_repository
def
update_repository
def
update_repository
git
_host
.
update_repository
(
project
)
git
olite
.
update_repository
(
project
)
end
end
def
commit
def
commit
...
...
app/models/users_project.rb
View file @
da03a5c7
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#
#
class
UsersProject
<
ActiveRecord
::
Base
class
UsersProject
<
ActiveRecord
::
Base
include
Git
Host
include
Git
olited
GUEST
=
10
GUEST
=
10
REPORTER
=
20
REPORTER
=
20
...
@@ -152,7 +152,7 @@ class UsersProject < ActiveRecord::Base
...
@@ -152,7 +152,7 @@ class UsersProject < ActiveRecord::Base
end
end
def
update_repository
def
update_repository
git
_host
.
update_repository
(
project
)
git
olite
.
update_repository
(
project
)
end
end
def
project_access_human
def
project_access_human
...
...
app/observers/key_observer.rb
View file @
da03a5c7
class
KeyObserver
<
ActiveRecord
::
Observer
class
KeyObserver
<
ActiveRecord
::
Observer
include
Git
Host
include
Git
olited
def
after_save
(
key
)
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
end
def
after_destroy
(
key
)
def
after_destroy
(
key
)
return
if
key
.
is_deploy_key
&&
!
key
.
last_deploy?
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
end
end
lib/git_host.rb
deleted
100644 → 0
View file @
40a956eb
# == 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 @
da03a5c7
# == 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/votes.rb
deleted
100644 → 0
View file @
40a956eb
# == 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
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