lib/ refactoring. Module Gitlabhq renamed to Gitlab

This commit is contained in:
randx 2012-05-26 13:37:49 +03:00
parent 8ceb94081a
commit 3272620f72
20 changed files with 87 additions and 85 deletions

View file

@ -5,7 +5,7 @@ class ApplicationController < ActionController::Base
protect_from_forgery
helper_method :abilities, :can?
rescue_from Gitlabhq::Gitolite::AccessDenied do |exception|
rescue_from Gitlab::Gitolite::AccessDenied do |exception|
render "errors/gitolite", :layout => "error"
end

View file

@ -45,7 +45,7 @@ class ProjectsController < ApplicationController
format.js
end
end
rescue Gitlabhq::Gitolite::AccessDenied
rescue Gitlab::Gitolite::AccessDenied
render :js => "location.href = '#{errors_githost_path}'" and return
rescue StandardError => ex
@project.errors.add(:base, "Cant save project. Please try again later")

View file

@ -143,6 +143,6 @@ module ApplicationHelper
end
def string_to_utf8 str
Gitlabhq::Encode.utf8 str
Gitlab::Encode.utf8 str
end
end

View file

@ -1,6 +1,6 @@
class Commit
include ActiveModel::Conversion
include Gitlabhq::Encode
include Gitlab::Encode
extend ActiveModel::Naming
attr_accessor :commit

View file

@ -38,14 +38,14 @@ class Key < ActiveRecord::Base
end
def update_repository
Gitlabhq::GitHost.system.new.configure do |c|
Gitlab::GitHost.system.new.configure do |c|
c.update_keys(identifier, key)
c.update_projects(projects)
end
end
def repository_delete_key
Gitlabhq::GitHost.system.new.configure do |c|
Gitlab::GitHost.system.new.configure do |c|
#delete key file is there is no identically deploy keys
if !is_deploy_key || Key.where(:identifier => identifier).count() == 0
c.delete_key(identifier)

View file

@ -82,7 +82,7 @@ class MergeRequest < ActiveRecord::Base
end
def check_if_can_be_merged
self.state = if GitlabMerge.new(self, self.author).can_be_merged?
self.state = if Gitlab::Merge.new(self, self.author).can_be_merged?
CAN_BE_MERGED
else
CANNOT_BE_MERGED
@ -184,7 +184,7 @@ class MergeRequest < ActiveRecord::Base
end
def automerge!(current_user)
if GitlabMerge.new(self, current_user).merge
if Gitlab::Merge.new(self, current_user).merge
self.merge!(current_user.id)
true
end

View file

@ -38,7 +38,7 @@ module Project::RepositoryTrait
end
def satellite
@satellite ||= Gitlabhq::Satellite.new(self)
@satellite ||= Gitlab::Satellite.new(self)
end
def write_hook(name, content)
@ -65,7 +65,7 @@ module Project::RepositoryTrait
end
def url_to_repo
Gitlabhq::GitHost.url_to_repo(path)
Gitlab::GitHost.url_to_repo(path)
end
def path_to_repo
@ -73,13 +73,13 @@ module Project::RepositoryTrait
end
def update_repository
Gitlabhq::GitHost.system.update_project(path, self)
Gitlab::GitHost.system.update_project(path, self)
write_hooks if File.exists?(path_to_repo)
end
def destroy_repository
Gitlabhq::GitHost.system.destroy_project(self)
Gitlab::GitHost.system.destroy_project(self)
end
def repo_exists?

View file

@ -7,7 +7,7 @@ class ProtectedBranch < ActiveRecord::Base
after_destroy :update_repository
def update_repository
Gitlabhq::GitHost.system.update_project(project.path, project)
Gitlab::GitHost.system.update_project(project.path, project)
end
def commit

View file

@ -58,7 +58,7 @@ class UsersProject < ActiveRecord::Base
end
def update_repository
Gitlabhq::GitHost.system.new.configure do |c|
Gitlab::GitHost.system.new.configure do |c|
c.update_project(project.path, project)
end
end

View file

@ -4,4 +4,4 @@ require File.expand_path('../application', __FILE__)
# Initialize the rails application
Gitlab::Application.initialize!
require File.join(Rails.root, "lib", "gitlabhq", "git_host")
require File.join(Rails.root, "lib", "gitlab", "git_host")

View file

@ -15,11 +15,11 @@ end
Grit::Diff.class_eval do
def old_path
Gitlabhq::Encode.utf8 a_path
Gitlab::Encode.utf8 a_path
end
def new_path
Gitlabhq::Encode.utf8 b_path
Gitlab::Encode.utf8 b_path
end
end

View file

@ -1,4 +1,4 @@
module Gitlabhq
module Gitlab
module Encode
extend self

View file

@ -1,9 +1,9 @@
require File.join(Rails.root, "lib", "gitlabhq", "gitolite")
require File.join(Rails.root, "lib", "gitlab", "gitolite")
module Gitlabhq
module Gitlab
class GitHost
def self.system
Gitlabhq::Gitolite
Gitlab::Gitolite
end
def self.admin_uri

View file

@ -2,7 +2,7 @@ require 'gitolite'
require 'timeout'
require 'fileutils'
module Gitlabhq
module Gitlab
class Gitolite
class AccessDenied < StandardError; end
@ -46,7 +46,7 @@ module Gitlabhq
end
end
rescue Exception => ex
Gitlabhq::Logger.error(ex.message)
Gitlab::Logger.error(ex.message)
raise Gitolite::AccessDenied.new("gitolite timeout")
end

View file

@ -1,4 +1,4 @@
module Gitlabhq
module Gitlab
class Logger
def self.error(message)
@@logger ||= ::Logger.new(File.join(Rails.root, "log/githost.log"))

60
lib/gitlab/merge.rb Normal file
View file

@ -0,0 +1,60 @@
module Gitlab
class Merge
attr_accessor :project, :merge_request, :user
def initialize(merge_request, user)
self.user = user
self.merge_request = merge_request
self.project = merge_request.project
end
def can_be_merged?
result = false
process do |repo, output|
result = !(output =~ /CONFLICT/)
end
result
end
def merge
process do |repo, output|
if output =~ /CONFLICT/
false
else
repo.git.push({}, "origin", merge_request.target_branch)
true
end
end
end
def process
Grit::Git.with_timeout(30.seconds) do
lock_file = File.join(Rails.root, "tmp", "merge_repo_#{project.path}.lock")
File.open(lock_file, "w+") do |f|
f.flock(File::LOCK_EX)
unless project.satellite.exists?
raise "You should run: rake gitlab:app:enable_automerge"
end
project.satellite.clear
Dir.chdir(project.satellite.path) do
merge_repo = Grit::Repo.new('.')
merge_repo.git.sh "git reset --hard"
merge_repo.git.sh "git fetch origin"
merge_repo.git.sh "git config user.name \"#{user.name}\""
merge_repo.git.sh "git config user.email \"#{user.email}\""
merge_repo.git.sh "git checkout -b #{merge_request.target_branch} origin/#{merge_request.target_branch}"
output = merge_repo.git.pull({}, "--no-ff", "origin", merge_request.source_branch)
yield(merge_repo, output)
end
end
end
rescue Grit::Git::GitTimeout
return false
end
end
end

View file

@ -1,4 +1,4 @@
module Gitlabhq
module Gitlab
class Satellite
PARKING_BRANCH = "__parking_branch"

View file

@ -1,58 +0,0 @@
class GitlabMerge
attr_accessor :project, :merge_request, :user
def initialize(merge_request, user)
self.user = user
self.merge_request = merge_request
self.project = merge_request.project
end
def can_be_merged?
result = false
process do |repo, output|
result = !(output =~ /CONFLICT/)
end
result
end
def merge
process do |repo, output|
if output =~ /CONFLICT/
false
else
repo.git.push({}, "origin", merge_request.target_branch)
true
end
end
end
def process
Grit::Git.with_timeout(30.seconds) do
lock_file = File.join(Rails.root, "tmp", "merge_repo_#{project.path}.lock")
File.open(lock_file, "w+") do |f|
f.flock(File::LOCK_EX)
unless project.satellite.exists?
raise "You should run: rake gitlab:app:enable_automerge"
end
project.satellite.clear
Dir.chdir(project.satellite.path) do
merge_repo = Grit::Repo.new('.')
merge_repo.git.sh "git reset --hard"
merge_repo.git.sh "git fetch origin"
merge_repo.git.sh "git config user.name \"#{user.name}\""
merge_repo.git.sh "git config user.email \"#{user.email}\""
merge_repo.git.sh "git checkout -b #{merge_request.target_branch} origin/#{merge_request.target_branch}"
output = merge_repo.git.pull({}, "--no-ff", "origin", merge_request.source_branch)
yield(merge_repo, output)
end
end
end
rescue Grit::Git::GitTimeout
return false
end
end

View file

@ -2,7 +2,7 @@ namespace :gitlab do
namespace :app do
desc "GITLAB | Enable auto merge"
task :enable_automerge => :environment do
Gitlabhq::GitHost.system.new.configure do |git|
Gitlab::GitHost.system.new.configure do |git|
git.admin_all_repo
end

View file

@ -43,7 +43,7 @@ describe ProtectedBranch do
subject { ProtectedBranch.new(:project => project) }
it "updates the branch's project repo permissions" do
Gitlabhq::GitHost.should_receive(:system).and_return(gitolite)
Gitlab::GitHost.should_receive(:system).and_return(gitolite)
gitolite.should_receive(:update_project).with(project.path, project)
subject.update_repository