diff options
author | randx <dmitriy.zaporozhets@gmail.com> | 2012-05-26 14:37:49 +0400 |
---|---|---|
committer | randx <dmitriy.zaporozhets@gmail.com> | 2012-05-26 14:37:49 +0400 |
commit | 3272620f724737f4dbb5e8c02f1610946435cd29 (patch) | |
tree | ae9fb3daccdf6b008ccb9c31d435e9548113c6ee | |
parent | 8ceb94081ac516ccaed43f0f4841725a4f9fe2db (diff) |
lib/ refactoring. Module Gitlabhq renamed to Gitlab
-rw-r--r-- | app/controllers/application_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/projects_controller.rb | 2 | ||||
-rw-r--r-- | app/helpers/application_helper.rb | 2 | ||||
-rw-r--r-- | app/models/commit.rb | 2 | ||||
-rw-r--r-- | app/models/key.rb | 4 | ||||
-rw-r--r-- | app/models/merge_request.rb | 4 | ||||
-rw-r--r-- | app/models/project/repository_trait.rb | 8 | ||||
-rw-r--r-- | app/models/protected_branch.rb | 2 | ||||
-rw-r--r-- | app/models/users_project.rb | 2 | ||||
-rw-r--r-- | config/environment.rb | 2 | ||||
-rw-r--r-- | config/initializers/gitlabhq/20_grit_ext.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/encode.rb (renamed from lib/gitlabhq/encode.rb) | 2 | ||||
-rw-r--r-- | lib/gitlab/git_host.rb (renamed from lib/gitlabhq/git_host.rb) | 6 | ||||
-rw-r--r-- | lib/gitlab/gitolite.rb (renamed from lib/gitlabhq/gitolite.rb) | 4 | ||||
-rw-r--r-- | lib/gitlab/logger.rb (renamed from lib/gitlabhq/logger.rb) | 2 | ||||
-rw-r--r-- | lib/gitlab/merge.rb | 60 | ||||
-rw-r--r-- | lib/gitlab/satellite.rb (renamed from lib/gitlabhq/satellite.rb) | 2 | ||||
-rw-r--r-- | lib/gitlab_merge.rb | 58 | ||||
-rw-r--r-- | lib/tasks/gitlab/enable_automerge.rake | 2 | ||||
-rw-r--r-- | spec/models/protected_branch_spec.rb | 2 |
20 files changed, 87 insertions, 85 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 8dd407ac16b..a96c59b6787 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 38fd6f3e57e..246d43e8703 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -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") diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7cbc6c4f41c..7b15513a25b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -143,6 +143,6 @@ module ApplicationHelper end def string_to_utf8 str - Gitlabhq::Encode.utf8 str + Gitlab::Encode.utf8 str end end diff --git a/app/models/commit.rb b/app/models/commit.rb index ad6d7127e76..09635d0e21c 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -1,6 +1,6 @@ class Commit include ActiveModel::Conversion - include Gitlabhq::Encode + include Gitlab::Encode extend ActiveModel::Naming attr_accessor :commit diff --git a/app/models/key.rb b/app/models/key.rb index 1d7aae359f4..8fe8716cc63 100644 --- a/app/models/key.rb +++ b/app/models/key.rb @@ -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) diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 248bbdacad4..ded12601417 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -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 diff --git a/app/models/project/repository_trait.rb b/app/models/project/repository_trait.rb index 8757d844217..a759ead569c 100644 --- a/app/models/project/repository_trait.rb +++ b/app/models/project/repository_trait.rb @@ -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? diff --git a/app/models/protected_branch.rb b/app/models/protected_branch.rb index 36e65633f58..e24412b245f 100644 --- a/app/models/protected_branch.rb +++ b/app/models/protected_branch.rb @@ -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 diff --git a/app/models/users_project.rb b/app/models/users_project.rb index b00ab96b6f2..808ed64ca4c 100644 --- a/app/models/users_project.rb +++ b/app/models/users_project.rb @@ -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 diff --git a/config/environment.rb b/config/environment.rb index 9b09be0557d..c880a7adc42 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -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") diff --git a/config/initializers/gitlabhq/20_grit_ext.rb b/config/initializers/gitlabhq/20_grit_ext.rb index 13e692cf20d..33c33ccc77a 100644 --- a/config/initializers/gitlabhq/20_grit_ext.rb +++ b/config/initializers/gitlabhq/20_grit_ext.rb @@ -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 diff --git a/lib/gitlabhq/encode.rb b/lib/gitlab/encode.rb index df40206d5eb..a9660fa513e 100644 --- a/lib/gitlabhq/encode.rb +++ b/lib/gitlab/encode.rb @@ -1,4 +1,4 @@ -module Gitlabhq +module Gitlab module Encode extend self diff --git a/lib/gitlabhq/git_host.rb b/lib/gitlab/git_host.rb index 9a6eecb3f0a..3d8d17473c5 100644 --- a/lib/gitlabhq/git_host.rb +++ b/lib/gitlab/git_host.rb @@ -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 diff --git a/lib/gitlabhq/gitolite.rb b/lib/gitlab/gitolite.rb index 48c67082b22..c7b407ddf23 100644 --- a/lib/gitlabhq/gitolite.rb +++ b/lib/gitlab/gitolite.rb @@ -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 diff --git a/lib/gitlabhq/logger.rb b/lib/gitlab/logger.rb index 08b4bde0b0c..45a990713f2 100644 --- a/lib/gitlabhq/logger.rb +++ b/lib/gitlab/logger.rb @@ -1,4 +1,4 @@ -module Gitlabhq +module Gitlab class Logger def self.error(message) @@logger ||= ::Logger.new(File.join(Rails.root, "log/githost.log")) diff --git a/lib/gitlab/merge.rb b/lib/gitlab/merge.rb new file mode 100644 index 00000000000..695e41e528d --- /dev/null +++ b/lib/gitlab/merge.rb @@ -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 diff --git a/lib/gitlabhq/satellite.rb b/lib/gitlab/satellite.rb index cd713a647cc..4bcbfe8db88 100644 --- a/lib/gitlabhq/satellite.rb +++ b/lib/gitlab/satellite.rb @@ -1,4 +1,4 @@ -module Gitlabhq +module Gitlab class Satellite PARKING_BRANCH = "__parking_branch" diff --git a/lib/gitlab_merge.rb b/lib/gitlab_merge.rb deleted file mode 100644 index 2ca7b26d865..00000000000 --- a/lib/gitlab_merge.rb +++ /dev/null @@ -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 diff --git a/lib/tasks/gitlab/enable_automerge.rake b/lib/tasks/gitlab/enable_automerge.rake index 647e06f675e..07f80586c60 100644 --- a/lib/tasks/gitlab/enable_automerge.rake +++ b/lib/tasks/gitlab/enable_automerge.rake @@ -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 diff --git a/spec/models/protected_branch_spec.rb b/spec/models/protected_branch_spec.rb index ce79f674787..024b45f2cab 100644 --- a/spec/models/protected_branch_spec.rb +++ b/spec/models/protected_branch_spec.rb @@ -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 |