BigW Consortium Gitlab

Commit da03a5c7 by Dmitriy Zaporozhets

more refactoring using models/concerns

parent 40a956eb
# == IssueCommonality role
# == Issuable concern
#
# Contains common functionality shared between Issues and MergeRequests
#
# Used by Issue, MergeRequest
#
module IssueCommonality
module Issuable
extend ActiveSupport::Concern
included do
......@@ -68,4 +68,35 @@ module IssueCommonality
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
......@@ -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
......
......@@ -23,8 +23,7 @@ require Rails.root.join("app/models/commit")
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
......
......@@ -21,7 +21,7 @@
require "grit"
class Project < ActiveRecord::Base
include GitHost
include Gitolited
class TransferError < StandardError; end
......@@ -408,7 +408,7 @@ class Project < ActiveRecord::Base
Gitlab::ProjectMover.new(self, old_dir, new_dir).execute
git_host.move_repository(old_repo, self)
gitolite.move_repository(old_repo, self)
save!
end
......@@ -670,7 +670,7 @@ class Project < ActiveRecord::Base
end
def url_to_repo
git_host.url_to_repo(path_with_namespace)
gitolite.url_to_repo(path_with_namespace)
end
def path_to_repo
......@@ -682,11 +682,11 @@ class Project < ActiveRecord::Base
end
def update_repository
git_host.update_repository(self)
gitolite.update_repository(self)
end
def destroy_repository
git_host.remove_repository(self)
gitolite.remove_repository(self)
end
def repo_exists?
......
......@@ -10,7 +10,7 @@
#
class ProtectedBranch < ActiveRecord::Base
include GitHost
include Gitolited
attr_accessible :name
......@@ -22,7 +22,7 @@ class ProtectedBranch < ActiveRecord::Base
after_destroy :update_repository
def update_repository
git_host.update_repository(project)
gitolite.update_repository(project)
end
def commit
......
......@@ -11,7 +11,7 @@
#
class UsersProject < ActiveRecord::Base
include GitHost
include Gitolited
GUEST = 10
REPORTER = 20
......@@ -152,7 +152,7 @@ class UsersProject < ActiveRecord::Base
end
def update_repository
git_host.update_repository(project)
gitolite.update_repository(project)
end
def project_access_human
......
class KeyObserver < ActiveRecord::Observer
include GitHost
include Gitolited
def after_save(key)
git_host.set_key(key.identifier, key.key, key.projects)
gitolite.set_key(key.identifier, key.key, key.projects)
end
def after_destroy(key)
return if key.is_deploy_key && !key.last_deploy?
git_host.remove_key(key.identifier, key.projects)
gitolite.remove_key(key.identifier, key.projects)
end
end
# == GitHost role
# == Gitolited mixin
#
# Provide a shortcut to Gitlab::Gitolite instance
# Provide a shortcut to Gitlab::Gitolite instance by gitolite
#
# Used by Project, UsersProject
# Used by Project, UsersProject, etc
#
module GitHost
def git_host
module Gitolited
def gitolite
Gitlab::Gitolite.new
end
end
# == 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment