From 5fd830f01c483dcccd8312caf289d5d03e7f389c Mon Sep 17 00:00:00 2001 From: Sato Hiroyuki Date: Wed, 12 Dec 2012 20:23:49 +0900 Subject: Improve network-graph --- lib/gitlab/graph/json_builder.rb | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/graph/json_builder.rb b/lib/gitlab/graph/json_builder.rb index c2c3fa662a6..abaa375ba19 100644 --- a/lib/gitlab/graph/json_builder.rb +++ b/lib/gitlab/graph/json_builder.rb @@ -98,7 +98,7 @@ module Gitlab if leaves.empty? return end - space = find_free_space(leaves.last.time..leaves.first.time) + space = find_free_space(leaves, map) leaves.each{|l| l.space = space} # and mark it as reserved min_time = leaves.last.time @@ -120,7 +120,7 @@ module Gitlab # Visit branching chains leaves.each do |l| - parents = l.parents.collect.select{|p| map.include? p.id and map[p.id].space == 0} + parents = l.parents.collect.select{|p| map.include? p.id and map[p.id].space.zero?} for p in parents place_chain(map[p.id], map, l.time) end @@ -133,18 +133,29 @@ module Gitlab end end - def find_free_space(time_range) + def find_free_space(leaves, map) + time_range = leaves.last.time..leaves.first.time reserved = [] for day in time_range reserved += @_reserved[day] end - space = 1 + space = base_space(leaves, map) while reserved.include? space do space += 1 end space end + def base_space(leaves, map) + parents = [] + leaves.each do |l| + parents.concat l.parents.collect.select{|p| map.include? p.id and map[p.id].space.nonzero?} + end + + space = parents.map{|p| map[p.id].space}.max || 0 + space += 1 + end + # Takes most left subtree branch of commits # which don't have space mark yet. # @@ -157,13 +168,13 @@ module Gitlab leaves.push(commit) if commit.space.zero? while true - parent = commit.parents.collect.select do |p| - map.include? p.id and map[p.id].space == 0 - end + return leaves if commit.parents.count.zero? + return leaves unless map.include? commit.parents.first.id + + commit = map[commit.parents.first.id] - return leaves if parent.count.zero? + return leaves unless commit.space.zero? - commit = map[parent.first.id] leaves.push(commit) end end -- cgit v1.2.1 From 328e0d80cabcb0d0a37cefb0f796a312505e87d0 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sat, 22 Dec 2012 23:45:22 +0200 Subject: Log if satellite creation failed --- lib/gitlab/satellite/satellite.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/gitlab/satellite/satellite.rb b/lib/gitlab/satellite/satellite.rb index 91c83d81029..784b146b98a 100644 --- a/lib/gitlab/satellite/satellite.rb +++ b/lib/gitlab/satellite/satellite.rb @@ -18,7 +18,13 @@ module Gitlab end def create - `git clone #{project.url_to_repo} #{path}` + create_cmd = "git clone #{project.url_to_repo} #{path}" + if system(create_cmd) + true + else + Gitlab::GitLogger.error("Failed to create satellite for #{project.name_with_namespace}") + false + end end def exists? -- cgit v1.2.1 From fa8f8343745deb7b677a525d12dc69435a98ae21 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sun, 23 Dec 2012 00:15:48 +0200 Subject: Fix import rake task and tests --- lib/tasks/gitlab/import.rake | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/tasks/gitlab/import.rake b/lib/tasks/gitlab/import.rake index 81f66e2e406..9f1288135c1 100644 --- a/lib/tasks/gitlab/import.rake +++ b/lib/tasks/gitlab/import.rake @@ -15,15 +15,20 @@ namespace :gitlab do git_base_path = Gitlab.config.gitolite.repos_path repos_to_import = Dir.glob(git_base_path + '/*') + namespaces = Namespace.pluck(:path) + repos_to_import.each do |repo_path| repo_name = File.basename repo_path + # Skip if group or user + next if namespaces.include?(repo_name) + # skip gitolite admin next if repo_name == 'gitolite-admin.git' path = repo_name.sub(/\.git$/, '') - project = Project.find_by_path(path) + project = Project.find_with_namespace(path) puts "Processing #{repo_name}".yellow @@ -34,8 +39,6 @@ namespace :gitlab do project_params = { :name => path, - :code => path, - :path => path, } project = Project.create_by_user(project_params, user) -- cgit v1.2.1 From 60038a99ca591c3520cf76831369be88a77f0c04 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sun, 23 Dec 2012 00:18:39 +0200 Subject: Import: Skip if not git repo --- lib/tasks/gitlab/import.rake | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib') diff --git a/lib/tasks/gitlab/import.rake b/lib/tasks/gitlab/import.rake index 9f1288135c1..4bf9110508e 100644 --- a/lib/tasks/gitlab/import.rake +++ b/lib/tasks/gitlab/import.rake @@ -23,6 +23,9 @@ namespace :gitlab do # Skip if group or user next if namespaces.include?(repo_name) + # skip if not git repo + next unless repo_name =~ /.git$/ + # skip gitolite admin next if repo_name == 'gitolite-admin.git' -- cgit v1.2.1 From 3bf0b4e25b4fa4bc865167542391cbd29e40cb53 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Sun, 23 Dec 2012 20:47:31 +0100 Subject: Fix satellite check for projects with empty repo Fixes #2349 --- lib/tasks/gitlab/check.rake | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index baa706d2bee..24bad9d5bba 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -189,6 +189,8 @@ namespace :gitlab do if project.satellite.exists? puts "yes".green + elsif project.empty_repo? + puts "can't create, repository is empty".magenta else puts "no".red try_fixing_it( -- cgit v1.2.1 From a9e2fa4c35604da4be37493cf7378e247d84f739 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Sun, 23 Dec 2012 20:47:55 +0100 Subject: Fix output of gitlab:check --- lib/tasks/gitlab/check.rake | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index 24bad9d5bba..540299c592e 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -53,14 +53,14 @@ namespace :gitlab do end def check_database_is_not_sqlite - print "Database is not SQLite ... " + print "Database is SQLite ... " database_config_file = Rails.root.join("config", "database.yml") unless File.read(database_config_file) =~ /sqlite/ - puts "yes".green + puts "no".green else - puts "no".red + puts "yes".red for_more_information( "https://github.com/gitlabhq/gitlabhq/wiki/Migrate-from-SQLite-to-MySQL", see_database_guide @@ -505,7 +505,6 @@ namespace :gitlab do puts "yes".green else puts "no".red - puts "#{gitolite_config_path} is not writable".red try_fixing_it( "sudo chmod 750 #{gitolite_config_path}" ) -- cgit v1.2.1 From 9655350c79e33ed765c62f892d65dd8c52284427 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Sun, 23 Dec 2012 01:33:58 +0100 Subject: Fix check.rake --- lib/tasks/gitlab/check.rake | 64 ++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'lib') diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index 540299c592e..843517aabaf 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -48,7 +48,7 @@ namespace :gitlab do see_database_guide, "http://guides.rubyonrails.org/getting_started.html#configuring-a-database" ) - check_failed + fix_and_rerun end end @@ -65,7 +65,7 @@ namespace :gitlab do "https://github.com/gitlabhq/gitlabhq/wiki/Migrate-from-SQLite-to-MySQL", see_database_guide ) - check_failed + fix_and_rerun end end @@ -85,7 +85,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "GitLab" ) - check_failed + fix_and_rerun end end @@ -110,7 +110,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "GitLab" ) - check_failed + fix_and_rerun end end @@ -129,7 +129,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Install Init Script" ) - check_failed + fix_and_rerun end end @@ -155,7 +155,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Install Init Script" ) - check_failed + fix_and_rerun end end @@ -171,7 +171,7 @@ namespace :gitlab do try_fixing_it( "sudo -u gitlab -H bundle exec rake db:migrate" ) - check_failed + fix_and_rerun end end @@ -201,7 +201,7 @@ namespace :gitlab do for_more_information( "doc/raketasks/maintenance.md " ) - check_failed + fix_and_rerun end end end @@ -222,7 +222,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "GitLab" ) - check_failed + fix_and_rerun end end @@ -242,7 +242,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "GitLab" ) - check_failed + fix_and_rerun end end end @@ -290,7 +290,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "GitLab" ) - check_failed + fix_and_rerun end end @@ -308,7 +308,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "System Users" ) - check_failed + fix_and_rerun end end @@ -332,7 +332,7 @@ namespace :gitlab do see_installation_guide_section("Gitolite"), "https://github.com/gitlabhq/gitlabhq/issues/1059" ) - check_failed + fix_and_rerun end end @@ -352,7 +352,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Packages / Dependencies" ) - check_failed + fix_and_rerun end end @@ -378,7 +378,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Packages / Dependencies" ) - check_failed + fix_and_rerun end end end @@ -434,7 +434,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Gitolite" ) - check_failed + fix_and_rerun end # assumes #check_can_clone_gitolite_admin has been run before @@ -466,7 +466,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Gitolite" ) - check_failed + fix_and_rerun ensure FileUtils.rm_rf("/tmp/gitolite_gitlab_test") end @@ -488,7 +488,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Gitolite" ) - check_failed + fix_and_rerun end end @@ -511,7 +511,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Gitolite" ) - check_failed + fix_and_rerun end end @@ -537,7 +537,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Gitolite" ) - check_failed + fix_and_rerun end end @@ -582,7 +582,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Gitolite" ) - check_failed + fix_and_rerun end end @@ -611,7 +611,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Gitolite" ) - check_failed + fix_and_rerun end end @@ -635,7 +635,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Setup GitLab Hooks" ) - check_failed + fix_and_rerun end end @@ -666,7 +666,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Setup GitLab Hooks" ) - check_failed + fix_and_rerun end end @@ -688,7 +688,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Gitolite" ) - check_failed + fix_and_rerun end end @@ -712,7 +712,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Gitolite" ) - check_failed + fix_and_rerun end end @@ -738,7 +738,7 @@ namespace :gitlab do for_more_information( see_installation_guide_section "Gitolite" ) - check_failed + fix_and_rerun end end @@ -772,7 +772,7 @@ namespace :gitlab do for_more_information( "doc/raketasks/maintenance.md" ) - check_failed + fix_and_rerun end end end @@ -808,7 +808,7 @@ namespace :gitlab do for_more_information( "lib/support/rewrite-hooks.sh" ) - check_failed + fix_and_rerun next end @@ -822,7 +822,7 @@ namespace :gitlab do for_more_information( "lib/support/rewrite-hooks.sh" ) - check_failed + fix_and_rerun end end end @@ -880,7 +880,7 @@ namespace :gitlab do see_installation_guide_section("Install Init Script"), "see log/resque.log for possible errors" ) - check_failed + fix_and_rerun end end end @@ -889,7 +889,7 @@ namespace :gitlab do # Helper methods ########################## - def check_failed + def fix_and_rerun puts " Please #{"fix the error above"} and rerun the checks.".red end -- cgit v1.2.1 From 224da71177a0e79c436fff530af60260f33ade6c Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Sun, 23 Dec 2012 03:20:13 +0100 Subject: Extract task helper methods --- lib/tasks/gitlab/check.rake | 37 ------------------------------------ lib/tasks/gitlab/info.rake | 26 ------------------------- lib/tasks/gitlab/task_helpers.rake | 39 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 63 deletions(-) create mode 100644 lib/tasks/gitlab/task_helpers.rake (limited to 'lib') diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index 843517aabaf..0abcfbb955f 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -908,29 +908,6 @@ namespace :gitlab do puts "" end - # Runs the given command - # - # Returns nil if the command was not found - # Returns the output of the command otherwise - # - # see also #run_and_match - def run(command) - unless `#{command} 2>/dev/null`.blank? - `#{command}` - end - end - - # Runs the given command and matches the output agains the given pattern - # - # Returns nil if nothing matched - # Retunrs the MatchData if the pattern matched - # - # see also #run - # see also String#match - def run_and_match(command, pattern) - run(command).try(:match, pattern) - end - def see_database_guide "doc/install/databases.md" end @@ -952,18 +929,4 @@ namespace :gitlab do puts " #{step}" end end - - def warn_user_is_not_gitlab - unless @warned_user_not_gitlab - current_user = run("whoami").chomp - unless current_user == "gitlab" - puts "#{Colored.color(:black)+Colored.color(:on_yellow)} Warning #{Colored.extra(:clear)}" - puts " You are running as user #{current_user.magenta}, we hope you know what you are doing." - puts " Some tests may pass\/fail for the wrong reason." - puts " For meaningful results you should run this as user #{"gitlab".magenta}." - puts "" - end - @warned_user_not_gitlab = true - end - end end diff --git a/lib/tasks/gitlab/info.rake b/lib/tasks/gitlab/info.rake index 85458fe2c43..3fbedda7721 100644 --- a/lib/tasks/gitlab/info.rake +++ b/lib/tasks/gitlab/info.rake @@ -80,31 +80,5 @@ namespace :gitlab do puts "Git:\t\t#{Gitlab.config.git.bin_path}" end - - - # Helper methods - - # Runs the given command and matches the output agains the given pattern - # - # Returns nil if nothing matched - # Retunrs the MatchData if the pattern matched - # - # see also #run - # see also String#match - def run_and_match(command, regexp) - run(command).try(:match, regexp) - end - - # Runs the given command - # - # Returns nil if the command was not found - # Returns the output of the command otherwise - # - # see also #run_and_match - def run(command) - unless `#{command} 2>/dev/null`.blank? - `#{command}` - end - end end end diff --git a/lib/tasks/gitlab/task_helpers.rake b/lib/tasks/gitlab/task_helpers.rake new file mode 100644 index 00000000000..c9635f058ee --- /dev/null +++ b/lib/tasks/gitlab/task_helpers.rake @@ -0,0 +1,39 @@ +namespace :gitlab do + + # Runs the given command and matches the output agains the given pattern + # + # Returns nil if nothing matched + # Retunrs the MatchData if the pattern matched + # + # see also #run + # see also String#match + def run_and_match(command, regexp) + run(command).try(:match, regexp) + end + + # Runs the given command + # + # Returns nil if the command was not found + # Returns the output of the command otherwise + # + # see also #run_and_match + def run(command) + unless `#{command} 2>/dev/null`.blank? + `#{command}` + end + end + + def warn_user_is_not_gitlab + unless @warned_user_not_gitlab + current_user = run("whoami").chomp + unless current_user == "gitlab" + puts "#{Colored.color(:black)+Colored.color(:on_yellow)} Warning #{Colored.extra(:clear)}" + puts " You are running as user #{current_user.magenta}, we hope you know what you are doing." + puts " Things may work\/fail for the wrong reasons." + puts " For correct results you should run this as user #{"gitlab".magenta}." + puts "" + end + @warned_user_not_gitlab = true + end + end +end -- cgit v1.2.1 From 430d3ad45b524943fb3b62890c5a3cdc72e70325 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Sun, 23 Dec 2012 21:14:30 +0100 Subject: Update output of gitlab:enable_automerge --- lib/tasks/gitlab/enable_automerge.rake | 36 +++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/tasks/gitlab/enable_automerge.rake b/lib/tasks/gitlab/enable_automerge.rake index ed3d6368a99..d412f8b3837 100644 --- a/lib/tasks/gitlab/enable_automerge.rake +++ b/lib/tasks/gitlab/enable_automerge.rake @@ -1,16 +1,42 @@ namespace :gitlab do desc "GITLAB | Enable auto merge" task :enable_automerge => :environment do + warn_user_is_not_gitlab + + puts "Updating repo permissions ..." Gitlab::Gitolite.new.enable_automerge + puts "... #{"done".green}" + puts "" + + print "Creating satellites for ..." + unless Project.count > 0 + puts "skipping, because you have no projects".magenta + return + end + puts "" + + Project.find_each(batch_size: 100) do |project| + print "#{project.name_with_namespace.yellow} ... " - Project.find_each do |project| - if project.repo_exists? && !project.satellite.exists? - puts "Creating satellite for #{project.name}...".green + unless project.repo_exists? + puts "skipping, because the repo is empty".magenta + next + end + + if project.satellite.exists? + puts "exists already".green + else + puts "" project.satellite.create + + print "... " + if $?.success? + puts "created".green + else + puts "error".red + end end end - - puts "Done!".green end namespace :satellites do -- cgit v1.2.1 From 1b6c28b9766aff2075bcd6e8c394ac4b9ed66f96 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Sun, 23 Dec 2012 21:15:25 +0100 Subject: Update output of gitlab:backup:resore --- lib/tasks/gitlab/backup.rake | 74 +++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 35 deletions(-) (limited to 'lib') diff --git a/lib/tasks/gitlab/backup.rake b/lib/tasks/gitlab/backup.rake index 44da6d671e0..3595ba222a2 100644 --- a/lib/tasks/gitlab/backup.rake +++ b/lib/tasks/gitlab/backup.rake @@ -5,6 +5,8 @@ namespace :gitlab do # Create backup of GitLab system desc "GITLAB | Create a backup of the GitLab system" task :create => :environment do + warn_user_is_not_gitlab + Rake::Task["gitlab:backup:db:create"].invoke Rake::Task["gitlab:backup:repo:create"].invoke @@ -22,23 +24,23 @@ namespace :gitlab do end # create archive - print "Creating backup archive: #{Time.now.to_i}_gitlab_backup.tar " + print "Creating backup archive: #{Time.now.to_i}_gitlab_backup.tar ... " if Kernel.system("tar -cf #{Time.now.to_i}_gitlab_backup.tar repositories/ db/ backup_information.yml") - puts "[DONE]".green + puts "done".green else - puts "[FAILED]".red + puts "failed".red end # cleanup: remove tmp files - print "Deleting tmp directories..." + print "Deleting tmp directories ... " if Kernel.system("rm -rf repositories/ db/ backup_information.yml") - puts "[DONE]".green + puts "done".green else - puts "[FAILED]".red + puts "failed".red end # delete backups - print "Deleting old backups... " + print "Deleting old backups ... " if Gitlab.config.backup.keep_time > 0 file_list = Dir.glob("*_gitlab_backup.tar").map { |f| f.split(/_/).first.to_i } file_list.sort.each do |timestamp| @@ -46,15 +48,17 @@ namespace :gitlab do %x{rm #{timestamp}_gitlab_backup.tar} end end - puts "[DONE]".green + puts "done".green else - puts "[SKIPPING]".yellow + puts "skipping".yellow end end # Restore backup of GitLab system desc "GITLAB | Restore a previously created backup" task :restore => :environment do + warn_user_is_not_gitlab + Dir.chdir(Gitlab.config.backup.path) # check for existing backups in the backup dir @@ -63,22 +67,22 @@ namespace :gitlab do if file_list.count > 1 && ENV["BACKUP"].nil? puts "Found more than one backup, please specify which one you want to restore:" puts "rake gitlab:backup:restore BACKUP=timestamp_of_backup" - exit 1; + exit 1 end tar_file = ENV["BACKUP"].nil? ? File.join("#{file_list.first}_gitlab_backup.tar") : File.join(ENV["BACKUP"] + "_gitlab_backup.tar") unless File.exists?(tar_file) puts "The specified backup doesn't exist!" - exit 1; + exit 1 end - print "Unpacking backup... " + print "Unpacking backup ... " unless Kernel.system("tar -xf #{tar_file}") - puts "[FAILED]".red + puts "failed".red exit 1 else - puts "[DONE]".green + puts "done".green end settings = YAML.load_file("backup_information.yml") @@ -86,7 +90,7 @@ namespace :gitlab do # restoring mismatching backups can lead to unexpected problems if settings[:gitlab_version] != %x{git rev-parse HEAD}.gsub(/\n/,"") - puts "gitlab_version mismatch:".red + puts "GitLab version mismatch:".red puts " Your current HEAD differs from the HEAD in the backup!".red puts " Please switch to the following revision and try again:".red puts " revision: #{settings[:gitlab_version]}".red @@ -97,11 +101,11 @@ namespace :gitlab do Rake::Task["gitlab:backup:repo:restore"].invoke # cleanup: remove tmp files - print "Deleting tmp directories..." + print "Deleting tmp directories ... " if Kernel.system("rm -rf repositories/ db/ backup_information.yml") - puts "[DONE]".green + puts "done".green else - puts "[FAILED]".red + puts "failed".red end end @@ -114,26 +118,26 @@ namespace :gitlab do task :create => :environment do backup_path_repo = File.join(Gitlab.config.backup.path, "repositories") FileUtils.mkdir_p(backup_path_repo) until Dir.exists?(backup_path_repo) - puts "Dumping repositories:" + puts "Dumping repositories ..." project = Project.all.map { |n| [n.path, n.path_to_repo] } project << ["gitolite-admin.git", File.join(Gitlab.config.git_base_path, "gitolite-admin.git")] project.each do |project| - print "- Dumping repository #{project.first}... " + print "#{project.first.yellow} ... " if Kernel.system("cd #{project.second} > /dev/null 2>&1 && git bundle create #{backup_path_repo}/#{project.first}.bundle --all > /dev/null 2>&1") - puts "[DONE]".green + puts "done".green else - puts "[FAILED]".red + puts "failed".red end end end task :restore => :environment do backup_path_repo = File.join(Gitlab.config.backup.path, "repositories") - puts "Restoring repositories:" + puts "Restoring repositories ... " project = Project.all.map { |n| [n.path, n.path_to_repo] } - project << ["gitolite-admin.git", File.join(File.dirname(project.first.second), "gitolite-admin.git")] + project << ["gitolite-admin.git", File.join(Gitlab.config.git_base_path, "gitolite-admin.git")] project.each do |project| - print "- Restoring repository #{project.first}... " + print "#{project.first.yellow} ... " FileUtils.rm_rf(project.second) if File.dirname(project.second) # delete old stuff if Kernel.system("cd #{File.dirname(project.second)} > /dev/null 2>&1 && git clone --bare #{backup_path_repo}/#{project.first}.bundle #{project.first}.git > /dev/null 2>&1") permission_commands = [ @@ -141,9 +145,9 @@ namespace :gitlab do "sudo chown -R #{Gitlab.config.ssh_user}:#{Gitlab.config.ssh_user} #{Gitlab.config.git_base_path}" ] permission_commands.each { |command| Kernel.system(command) } - puts "[DONE]".green + puts "done".green else - puts "[FAILED]".red + puts "failed".red end end end @@ -156,9 +160,9 @@ namespace :gitlab do backup_path_db = File.join(Gitlab.config.backup.path, "db") FileUtils.mkdir_p(backup_path_db) unless Dir.exists?(backup_path_db) - puts "Dumping database tables:" + puts "Dumping database tables ... " ActiveRecord::Base.connection.tables.each do |tbl| - print "- Dumping table #{tbl}... " + print "#{tbl.yellow} ... " count = 1 File.open(File.join(backup_path_db, tbl + ".yml"), "w+") do |file| ActiveRecord::Base.connection.select_all("SELECT * FROM `#{tbl}`").each do |line| @@ -167,25 +171,25 @@ namespace :gitlab do file << output.to_yaml.gsub(/^---\n/,'') + "\n" count += 1 end - puts "[DONE]".green + puts "done".green end end end - task :restore=> :environment do + task :restore => :environment do backup_path_db = File.join(Gitlab.config.backup.path, "db") - puts "Restoring database tables:" + puts "Restoring database tables (loading fixtures) ... " Rake::Task["db:reset"].invoke Dir.glob(File.join(backup_path_db, "*.yml") ).each do |dir| fixture_file = File.basename(dir, ".*" ) - print "- Loading fixture #{fixture_file}..." + print "#{fixture_file.yellow} ... " if File.size(dir) > 0 ActiveRecord::Fixtures.create_fixtures(backup_path_db, fixture_file) - puts "[DONE]".green + puts "done".green else - puts "[SKIPPING]".yellow + puts "skipping".yellow end end end -- cgit v1.2.1 From 31e0fa6572848ee12c05e4e7471c1b3cee426f5f Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Sun, 23 Dec 2012 21:16:08 +0100 Subject: Update output of gitlab:enable_namespaces --- lib/tasks/gitlab/enable_namespaces.rake | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/tasks/gitlab/enable_namespaces.rake b/lib/tasks/gitlab/enable_namespaces.rake index 1be9ba6469d..81b86d56eb3 100644 --- a/lib/tasks/gitlab/enable_namespaces.rake +++ b/lib/tasks/gitlab/enable_namespaces.rake @@ -1,7 +1,9 @@ namespace :gitlab do desc "GITLAB | Enable usernames and namespaces for user projects" task enable_namespaces: :environment do - print "\nUsernames for users:".yellow + warn_user_is_not_gitlab + + print "Generate usernames for users without one: " User.find_each(batch_size: 500) do |user| next if user.namespace @@ -16,7 +18,8 @@ namespace :gitlab do end end - print "\n\nDirs for groups:".yellow + puts "" + print "Create directories for groups: " Group.find_each(batch_size: 500) do |group| if group.ensure_dir_exist @@ -25,43 +28,44 @@ namespace :gitlab do print 'F'.red end end + puts "" - print "\n\nMove projects from groups under groups dirs:".yellow git_path = Gitlab.config.gitolite.repos_path - + puts "" + puts "Move projects in groups into respective directories ... " Project.where('namespace_id IS NOT NULL').find_each(batch_size: 500) do |project| next unless project.group group = project.group - puts "\n" - print " * #{project.name}: " + print "#{project.name_with_namespace.yellow} ... " new_path = File.join(git_path, project.path_with_namespace + '.git') if File.exists?(new_path) - print "ok. already at #{new_path}".cyan + puts "already at #{new_path}".green next end old_path = File.join(git_path, project.path + '.git') unless File.exists?(old_path) - print "missing. not found at #{old_path}".red + puts "couldn't find it at #{old_path}".red next end begin Gitlab::ProjectMover.new(project, '', group.path).execute - print "ok. Moved to #{new_path}".green + puts "moved to #{new_path}".green rescue - print "Failed moving to #{new_path}".red + puts "failed moving to #{new_path}".red end end - print "\n\nRebuild gitolite:".yellow + puts "" + puts "Rebuild Gitolite ... " gitolite = Gitlab::Gitolite.new gitolite.update_repositories(Project.where('namespace_id IS NOT NULL')) - puts "\n" + puts "... #{"done".green}" end end -- cgit v1.2.1 From 2462949fd598258204a8b6b98c2c91b5eabde847 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Sun, 23 Dec 2012 21:16:26 +0100 Subject: Update output of gitlab:gitolite:update_* --- lib/tasks/gitlab/gitolite_rebuild.rake | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/tasks/gitlab/gitolite_rebuild.rake b/lib/tasks/gitlab/gitolite_rebuild.rake index fce10eb5b69..af2a2127ee2 100644 --- a/lib/tasks/gitlab/gitolite_rebuild.rake +++ b/lib/tasks/gitlab/gitolite_rebuild.rake @@ -1,24 +1,27 @@ namespace :gitlab do namespace :gitolite do - desc "GITLAB | Rebuild each project at gitolite config" + desc "GITLAB | Rebuild each project in Gitolite config" task :update_repos => :environment do - puts "Starting Projects" + warn_user_is_not_gitlab + + puts "Rebuilding projects ... " Project.find_each(:batch_size => 100) do |project| - puts "\n=== #{project.name}" + puts "#{project.name_with_namespace.yellow} ... " project.update_repository - puts + puts "... #{"done".green}" end - puts "Done with projects" end - desc "GITLAB | Rebuild each key at gitolite config" + desc "GITLAB | Rebuild each user key in Gitolite config" task :update_keys => :environment do - puts "Starting Key" + warn_user_is_not_gitlab + + puts "Rebuilding keys ... " Key.find_each(:batch_size => 100) do |key| + puts "#{key.identifier.yellow} ... " Gitlab::Gitolite.new.set_key(key.identifier, key.key, key.projects) - print '.' + puts "... #{"done".green}" end - puts "Done with keys" end end end -- cgit v1.2.1 From d9ca1bce7a52709aa9d1aa60940cab69861e09c0 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Mon, 24 Dec 2012 15:47:02 +0100 Subject: Fix paths in gitlab:check --- lib/tasks/gitlab/check.rake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index 540299c592e..f8448d19666 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -317,7 +317,7 @@ namespace :gitlab do gitolite_ssh_user = Gitlab.config.gitolite.ssh_user print "Has no \"-e\" in ~#{gitolite_ssh_user}/.profile ... " - profile_file = File.expand_path("~#{Gitlab.config.gitolite.ssh_user}/.profile") + profile_file = File.join(gitolite_home, ".profile") unless File.read(profile_file) =~ /^-e PATH/ puts "yes".green @@ -474,7 +474,7 @@ namespace :gitlab do def check_dot_gitolite_exists print "Config directory exists? ... " - gitolite_config_path = File.expand_path("~#{Gitlab.config.gitolite.ssh_user}/.gitolite") + gitolite_config_path = File.join(gitolite_home, ".gitolite") if File.directory?(gitolite_config_path) puts "yes".green @@ -495,7 +495,7 @@ namespace :gitlab do def check_dot_gitolite_permissions print "Config directory access is drwxr-x---? ... " - gitolite_config_path = File.expand_path("~#{Gitlab.config.gitolite.ssh_user}/.gitolite") + gitolite_config_path = File.join(gitolite_home, ".gitolite") unless File.exists?(gitolite_config_path) puts "can't check because of previous errors".magenta return @@ -519,7 +519,7 @@ namespace :gitlab do gitolite_ssh_user = Gitlab.config.gitolite.ssh_user print "Config directory owned by #{gitolite_ssh_user}:#{gitolite_ssh_user} ... " - gitolite_config_path = File.expand_path("~#{gitolite_ssh_user}/.gitolite") + gitolite_config_path = File.join(gitolite_home, ".gitolite") unless File.exists?(gitolite_config_path) puts "can't check because of previous errors".magenta return -- cgit v1.2.1 From 0e15270b75df9e882bc41e22a6a120092a629a02 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Mon, 24 Dec 2012 16:41:46 +0100 Subject: Fix crash in gitlab:check while checking hooks --- lib/tasks/gitlab/check.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index f8448d19666..f052de77184 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -645,7 +645,6 @@ namespace :gitlab do hook_file = "post-receive" gitolite_hooks_path = File.join(Gitlab.config.gitolite.hooks_path, "common") gitolite_hook_file = File.join(gitolite_hooks_path, hook_file) - gitolite_hook_content = File.read(gitolite_hook_file) gitolite_ssh_user = Gitlab.config.gitolite.ssh_user unless File.exists?(gitolite_hook_file) @@ -653,6 +652,7 @@ namespace :gitlab do return end + gitolite_hook_content = File.read(gitolite_hook_file) gitlab_hook_file = Rails.root.join.join("lib", "hooks", hook_file) gitlab_hook_content = File.read(gitlab_hook_file) -- cgit v1.2.1 From 8ef7b9b6d10bde1f513d678703fc209653087137 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Mon, 24 Dec 2012 15:52:49 +0100 Subject: Make SQLite check in gitlab:check more robust --- lib/tasks/gitlab/check.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index f052de77184..5f1ed080fa5 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -57,7 +57,7 @@ namespace :gitlab do database_config_file = Rails.root.join("config", "database.yml") - unless File.read(database_config_file) =~ /sqlite/ + unless File.read(database_config_file) =~ /adapter:\s+sqlite/ puts "no".green else puts "yes".red -- cgit v1.2.1 From a87fccc0834aa816289669a0fc7744338e469745 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 24 Dec 2012 20:01:49 +0200 Subject: Update projects in gitolite after namespace moved. Added rake task to cleanup garbage from gitolite --- lib/tasks/gitlab/gitolite_rebuild.rake | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'lib') diff --git a/lib/tasks/gitlab/gitolite_rebuild.rake b/lib/tasks/gitlab/gitolite_rebuild.rake index af2a2127ee2..8fa466fbfd7 100644 --- a/lib/tasks/gitlab/gitolite_rebuild.rake +++ b/lib/tasks/gitlab/gitolite_rebuild.rake @@ -23,5 +23,38 @@ namespace :gitlab do puts "... #{"done".green}" end end + + desc "GITLAB | Cleanup gitolite config" + task :cleanup => :environment do + warn_user_is_not_gitlab + + real_repos = Project.all.map(&:path_with_namespace) + real_repos << "gitolite-admin" + real_repos << "@all" + + remove_flag = ENV['REMOVE'] + + puts "Looking for repositories to remove... " + Gitlab::GitoliteConfig.new.apply do |config| + all_repos = [] + garbage_repos = [] + + all_repos = config.conf.repos.keys + garbage_repos = all_repos - real_repos + + garbage_repos.each do |repo_name| + if remove_flag + config.conf.rm_repo(repo_name) + print "to remove...".red + end + + puts repo_name.red + end + end + + unless remove_flag + puts "To cleanup repositories run this command with REMOVE=true".yellow + end + end end end -- cgit v1.2.1 From c8ba5c2d58b882fd7cd5342a42158bb5f810fd60 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 25 Dec 2012 06:14:05 +0300 Subject: Fix routing issues when navigating over tree, commits etc --- lib/extracts_path.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/extracts_path.rb b/lib/extracts_path.rb index b60dfd036e1..220e3d2271f 100644 --- a/lib/extracts_path.rb +++ b/lib/extracts_path.rb @@ -33,6 +33,9 @@ module ExtractsPath # extract_ref("v2.0.0/README.md") # # => ['v2.0.0', 'README.md'] # + # extract_ref('/gitlab/vagrant/tree/master/app/models/project.rb') + # # => ['master', 'app/models/project.rb'] + # # extract_ref('issues/1234/app/models/project.rb') # # => ['issues/1234', 'app/models/project.rb'] # @@ -47,6 +50,13 @@ module ExtractsPath return pair unless @project + # Remove project, actions and all other staff from path + input.gsub!("/#{@project.path_with_namespace}", "") + input.gsub!(/^\/(tree|commits|blame|blob)\//, "") # remove actions + input.gsub!(/\?.*$/, "") # remove stamps suffix + input.gsub!(/.atom$/, "") # remove rss feed + input.gsub!(/\/edit$/, "") # remove edit route part + if input.match(/^([[:alnum:]]{40})(.+)/) # If the ref appears to be a SHA, we're done, just split the string pair = $~.captures @@ -98,7 +108,7 @@ module ExtractsPath request.format = :atom end - @ref, @path = extract_ref(params[:id]) + @ref, @path = extract_ref(request.fullpath) @id = File.join(@ref, @path) -- cgit v1.2.1 From c5eba169cdcf0d66cd7c6b34dace639a08949dd9 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 25 Dec 2012 07:14:05 +0300 Subject: Cleanup service tasks --- lib/tasks/gitlab/cleanup.rake | 128 +++++++++++++++++++++++++++++++++ lib/tasks/gitlab/gitolite_rebuild.rake | 33 --------- 2 files changed, 128 insertions(+), 33 deletions(-) create mode 100644 lib/tasks/gitlab/cleanup.rake (limited to 'lib') diff --git a/lib/tasks/gitlab/cleanup.rake b/lib/tasks/gitlab/cleanup.rake new file mode 100644 index 00000000000..2a0ffe0f4bd --- /dev/null +++ b/lib/tasks/gitlab/cleanup.rake @@ -0,0 +1,128 @@ +namespace :gitlab do + namespace :cleanup do + desc "GITLAB | Cleanup | Clean gitolite config" + task :config => :environment do + warn_user_is_not_gitlab + + real_repos = Project.all.map(&:path_with_namespace) + real_repos << "gitolite-admin" + real_repos << "@all" + + remove_flag = ENV['REMOVE'] + + puts "Looking for repositories to remove... " + Gitlab::GitoliteConfig.new.apply do |config| + all_repos = [] + garbage_repos = [] + + all_repos = config.conf.repos.keys + garbage_repos = all_repos - real_repos + + garbage_repos.each do |repo_name| + if remove_flag + config.conf.rm_repo(repo_name) + print "to remove...".red + end + + puts repo_name.red + end + end + + unless remove_flag + puts "To cleanup repositories run this command with REMOVE=true".yellow + end + end + + desc "GITLAB | Cleanup | Clean namespaces" + task :dirs => :environment do + warn_user_is_not_gitlab + remove_flag = ENV['REMOVE'] + + + namespaces = Namespace.pluck(:path) + git_base_path = Gitlab.config.gitolite.repos_path + all_dirs = Dir.glob(git_base_path + '/*') + + puts git_base_path.yellow + puts "Looking for directories to remove... " + + all_dirs.reject! do |dir| + # skip if git repo + dir =~ /.git$/ + end + + all_dirs.reject! do |dir| + dir_name = File.basename dir + + # skip if namespace present + namespaces.include?(dir_name) + end + + all_dirs.each do |dir_path| + + if remove_flag + if FileUtils.rm_rf dir_path + puts "Removed...#{dir_path}".red + else + puts "Cannot remove #{dir_path}".red + end + else + puts "Can be removed: #{dir_path}".red + end + end + + unless remove_flag + puts "To cleanup this directories run this command with REMOVE=true".yellow + end + end + + desc "GITLAB | Cleanup | Clean respositories" + task :repos => :environment do + warn_user_is_not_gitlab + remove_flag = ENV['REMOVE'] + + git_base_path = Gitlab.config.gitolite.repos_path + all_dirs = Dir.glob(git_base_path + '/*') + + global_projects = Project.where(namespace_id: nil).pluck(:path) + + puts git_base_path.yellow + puts "Looking for global repos to remove... " + + # skip non git repo + all_dirs.select! do |dir| + dir =~ /.git$/ + end + + # skip existing repos + all_dirs.reject! do |dir| + repo_name = File.basename dir + path = repo_name.gsub(/\.git$/, "") + global_projects.include?(path) + end + + # skip gitolite admin + all_dirs.reject! do |dir| + repo_name = File.basename dir + repo_name == 'gitolite-admin.git' + end + + + all_dirs.each do |dir_path| + if remove_flag + if FileUtils.rm_rf dir_path + puts "Removed...#{dir_path}".red + else + puts "Cannot remove #{dir_path}".red + end + else + puts "Can be removed: #{dir_path}".red + end + end + + unless remove_flag + puts "To cleanup this directories run this command with REMOVE=true".yellow + end + end + end +end diff --git a/lib/tasks/gitlab/gitolite_rebuild.rake b/lib/tasks/gitlab/gitolite_rebuild.rake index 8fa466fbfd7..af2a2127ee2 100644 --- a/lib/tasks/gitlab/gitolite_rebuild.rake +++ b/lib/tasks/gitlab/gitolite_rebuild.rake @@ -23,38 +23,5 @@ namespace :gitlab do puts "... #{"done".green}" end end - - desc "GITLAB | Cleanup gitolite config" - task :cleanup => :environment do - warn_user_is_not_gitlab - - real_repos = Project.all.map(&:path_with_namespace) - real_repos << "gitolite-admin" - real_repos << "@all" - - remove_flag = ENV['REMOVE'] - - puts "Looking for repositories to remove... " - Gitlab::GitoliteConfig.new.apply do |config| - all_repos = [] - garbage_repos = [] - - all_repos = config.conf.repos.keys - garbage_repos = all_repos - real_repos - - garbage_repos.each do |repo_name| - if remove_flag - config.conf.rm_repo(repo_name) - print "to remove...".red - end - - puts repo_name.red - end - end - - unless remove_flag - puts "To cleanup repositories run this command with REMOVE=true".yellow - end - end end end -- cgit v1.2.1 From d41aac629b0a951262542570d002d33d30203725 Mon Sep 17 00:00:00 2001 From: Sriharsha Vardhan Date: Tue, 25 Dec 2012 12:13:50 +0530 Subject: Fix replace return with next in rake rask --- lib/tasks/gitlab/enable_automerge.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/tasks/gitlab/enable_automerge.rake b/lib/tasks/gitlab/enable_automerge.rake index d412f8b3837..e92da81021f 100644 --- a/lib/tasks/gitlab/enable_automerge.rake +++ b/lib/tasks/gitlab/enable_automerge.rake @@ -11,7 +11,7 @@ namespace :gitlab do print "Creating satellites for ..." unless Project.count > 0 puts "skipping, because you have no projects".magenta - return + next end puts "" -- cgit v1.2.1 From 64db738f9de3839090eef6a862581a0e72f6540d Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 25 Dec 2012 15:53:50 +0200 Subject: Trying to fix resque issue --- lib/tasks/resque.rake | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/tasks/resque.rake b/lib/tasks/resque.rake index 0825324a424..36e461da660 100644 --- a/lib/tasks/resque.rake +++ b/lib/tasks/resque.rake @@ -1,9 +1,7 @@ require 'resque/tasks' task "resque:setup" => :environment do - Resque.after_fork do - Resque.redis.client.reconnect - end + Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection } end desc "Alias for resque:work (To run workers on Heroku)" -- cgit v1.2.1 From 5cd823847b37c66d521545180c81d9a92ca0ab57 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 26 Dec 2012 11:18:38 +0200 Subject: Use gitlab resque fork. Added rake task to stop all workers --- lib/tasks/resque.rake | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/tasks/resque.rake b/lib/tasks/resque.rake index 36e461da660..0c3b93c5bed 100644 --- a/lib/tasks/resque.rake +++ b/lib/tasks/resque.rake @@ -1,7 +1,22 @@ require 'resque/tasks' -task "resque:setup" => :environment do - Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection } +namespace :resque do + task setup: :environment do + Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection } + end + + desc "Resque | kill all workers (using -QUIT), god will take care of them" + task :stop_workers => :environment do + pids = Array.new + + Resque.workers.each do |worker| + pids << worker.to_s.split(/:/).second + end + + if pids.size > 0 + system("kill -QUIT #{pids.join(' ')}") + end + end end desc "Alias for resque:work (To run workers on Heroku)" -- cgit v1.2.1 From 17ea019f4e43b4fb394544f9d86ab3016f54d28e Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Wed, 26 Dec 2012 02:50:41 +0400 Subject: Add Project name validation --- lib/gitlab/regex.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib') diff --git a/lib/gitlab/regex.rb b/lib/gitlab/regex.rb index a3f38b1c360..e0fb47da17b 100644 --- a/lib/gitlab/regex.rb +++ b/lib/gitlab/regex.rb @@ -6,6 +6,10 @@ module Gitlab default_regex end + def project_name_regex + default_regex + end + def path_regex default_regex end -- cgit v1.2.1 From 4cbb29cfadb243733185cdfaefe34e15dee35260 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 27 Dec 2012 06:14:05 +0300 Subject: Fix not_in_project scope. Added counters in admin -> users. Improved seeds --- lib/support/truncate_repositories.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 lib/support/truncate_repositories.sh (limited to 'lib') diff --git a/lib/support/truncate_repositories.sh b/lib/support/truncate_repositories.sh new file mode 100755 index 00000000000..3b14e2ee362 --- /dev/null +++ b/lib/support/truncate_repositories.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +echo "Danger!!! Data Loss" +while true; do + read -p "Do you wish to all directories except gitolite-admin.git from /home/git/repositories/ (y/n) ?: " yn + case $yn in + [Yy]* ) sh -c "find /home/git/repositories/. -maxdepth 1 -not -name 'gitolite-admin.git' -not -name '.' | xargs sudo rm -rf"; break;; + [Nn]* ) exit;; + * ) echo "Please answer yes or no.";; + esac +done -- cgit v1.2.1 From 1f3bdd453e8dfb81b97166ede481685d85ea04c6 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 28 Dec 2012 09:29:57 +0200 Subject: Allow spaces in project name --- lib/gitlab/regex.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/gitlab/regex.rb b/lib/gitlab/regex.rb index e0fb47da17b..483042205ea 100644 --- a/lib/gitlab/regex.rb +++ b/lib/gitlab/regex.rb @@ -7,7 +7,7 @@ module Gitlab end def project_name_regex - default_regex + /\A[a-zA-Z][a-zA-Z0-9_\-\. ]*\z/ end def path_regex -- cgit v1.2.1 From d03964d6ec4351be76ec978fc0481f24c3b623ec Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 28 Dec 2012 06:14:05 +0300 Subject: Fixed and improved enable_naamespace migration task --- lib/tasks/gitlab/enable_namespaces.rake | 85 +++++++++++++++++++++++++-------- 1 file changed, 65 insertions(+), 20 deletions(-) (limited to 'lib') diff --git a/lib/tasks/gitlab/enable_namespaces.rake b/lib/tasks/gitlab/enable_namespaces.rake index 81b86d56eb3..aa76a2f7d83 100644 --- a/lib/tasks/gitlab/enable_namespaces.rake +++ b/lib/tasks/gitlab/enable_namespaces.rake @@ -3,36 +3,85 @@ namespace :gitlab do task enable_namespaces: :environment do warn_user_is_not_gitlab - print "Generate usernames for users without one: " + migrate_user_namespaces + migrate_groups + migrate_projects + puts "Rebuild Gitolite ... " + gitolite = Gitlab::Gitolite.new + gitolite.update_repositories(Project.where('namespace_id IS NOT NULL')) + puts "... #{"done".green}" + end + + def migrate_user_namespaces + puts "\nGenerate usernames for users without one: ".blue User.find_each(batch_size: 500) do |user| - next if user.namespace + if user.namespace + print '-'.cyan + next + end - User.transaction do - username = user.email.match(/^[^@]*/)[0] - if user.update_attributes!(username: username) + username = if user.username.present? + # if user already has username filled + user.username + else + build_username(user) + end + + begin + User.transaction do + user.update_attributes!(username: username) print '.'.green - else - print 'F'.red end + rescue + print 'F'.red end end + puts "\nDone" + end + + def build_username(user) + username = nil + + # generate username + username = user.email.match(/^[^@]*/)[0] + username.gsub!("+", ".") + + # return username if no mathes + return username unless User.find_by_username(username) + + # look for same username + (1..10).each do |i| + suffixed_username = "#{username}#{i}" + + return suffixed_username unless User.find_by_username(suffixed_username) + end + end - puts "" - print "Create directories for groups: " + def migrate_groups + puts "\nCreate directories for groups: ".blue Group.find_each(batch_size: 500) do |group| - if group.ensure_dir_exist - print '.'.green - else + begin + if group.dir_exists? + print '-'.cyan + else + if group.ensure_dir_exist + print '.'.green + else + print 'F'.red + end + end + rescue print 'F'.red end end - puts "" + puts "\nDone" + end + def migrate_projects git_path = Gitlab.config.gitolite.repos_path - puts "" - puts "Move projects in groups into respective directories ... " + puts "\nMove projects in groups into respective directories ... ".blue Project.where('namespace_id IS NOT NULL').find_each(batch_size: 500) do |project| next unless project.group @@ -62,10 +111,6 @@ namespace :gitlab do end end - puts "" - puts "Rebuild Gitolite ... " - gitolite = Gitlab::Gitolite.new - gitolite.update_repositories(Project.where('namespace_id IS NOT NULL')) - puts "... #{"done".green}" + puts "\nDone" end end -- cgit v1.2.1 From 21e55ca318bb829399c85b10e678b596d6fd414e Mon Sep 17 00:00:00 2001 From: Chris Frohoff Date: Fri, 28 Dec 2012 18:11:28 +0000 Subject: added RAILS_RELATIVE_URL_ROOT support --- lib/gitlab/backend/grack_auth.rb | 4 ---- 1 file changed, 4 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/backend/grack_auth.rb b/lib/gitlab/backend/grack_auth.rb index 7c31117f01d..cfad532a06c 100644 --- a/lib/gitlab/backend/grack_auth.rb +++ b/lib/gitlab/backend/grack_auth.rb @@ -17,10 +17,6 @@ module Grack # Pass Gitolite update hook ENV['GL_BYPASS_UPDATE_HOOK'] = "true" - # Need this patch due to the rails mount - @env['PATH_INFO'] = @request.path - @env['SCRIPT_NAME'] = "" - # Find project by PATH_INFO from env if m = /^\/([\w\.\/-]+)\.git/.match(@request.path_info).to_a self.project = Project.find_with_namespace(m.last) -- cgit v1.2.1 From 96d49bf04ce77c975fe500f4d961e4a1ffed4c26 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sun, 30 Dec 2012 14:43:00 +0200 Subject: Use sdoc to generate application code documentation --- lib/tasks/gitlab/generate_docs.rake | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 lib/tasks/gitlab/generate_docs.rake (limited to 'lib') diff --git a/lib/tasks/gitlab/generate_docs.rake b/lib/tasks/gitlab/generate_docs.rake new file mode 100644 index 00000000000..58795fac4af --- /dev/null +++ b/lib/tasks/gitlab/generate_docs.rake @@ -0,0 +1,7 @@ +namespace :gitlab do + desc "GITLAB | Generate sdocs for project" + task generate_docs: :environment do + system("bundle exec sdoc -o doc/code app lib") + end +end + -- cgit v1.2.1 From 83924495993753e6c503ce539c6533b54af6f86a Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 31 Dec 2012 12:00:46 +0200 Subject: Fix backup/restore of repos --- lib/tasks/gitlab/backup.rake | 54 ++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 20 deletions(-) (limited to 'lib') diff --git a/lib/tasks/gitlab/backup.rake b/lib/tasks/gitlab/backup.rake index 3595ba222a2..82c8dd8ca11 100644 --- a/lib/tasks/gitlab/backup.rake +++ b/lib/tasks/gitlab/backup.rake @@ -119,35 +119,49 @@ namespace :gitlab do backup_path_repo = File.join(Gitlab.config.backup.path, "repositories") FileUtils.mkdir_p(backup_path_repo) until Dir.exists?(backup_path_repo) puts "Dumping repositories ..." - project = Project.all.map { |n| [n.path, n.path_to_repo] } - project << ["gitolite-admin.git", File.join(Gitlab.config.git_base_path, "gitolite-admin.git")] - project.each do |project| - print "#{project.first.yellow} ... " - if Kernel.system("cd #{project.second} > /dev/null 2>&1 && git bundle create #{backup_path_repo}/#{project.first}.bundle --all > /dev/null 2>&1") - puts "done".green + + Project.find_each(:batch_size => 1000) do |project| + print "#{project.path_with_namespace} ... " + + if project.empty_repo? + puts "[SKIPPED]".cyan + next + end + + # Create namespace dir if missing + FileUtils.mkdir_p(File.join(backup_path_repo, project.namespace.path)) if project.namespace + + # Build a destination path for backup + path_to_bundle = File.join(backup_path_repo, project.path_with_namespace + ".bundle") + + if Kernel.system("cd #{project.path_to_repo} > /dev/null 2>&1 && git bundle create #{path_to_bundle} --all > /dev/null 2>&1") + puts "[DONE]".green else - puts "failed".red + puts "[FAILED]".red end end end task :restore => :environment do backup_path_repo = File.join(Gitlab.config.backup.path, "repositories") + repos_path = Gitlab.config.gitolite.repos_path + puts "Restoring repositories ... " - project = Project.all.map { |n| [n.path, n.path_to_repo] } - project << ["gitolite-admin.git", File.join(Gitlab.config.git_base_path, "gitolite-admin.git")] - project.each do |project| - print "#{project.first.yellow} ... " - FileUtils.rm_rf(project.second) if File.dirname(project.second) # delete old stuff - if Kernel.system("cd #{File.dirname(project.second)} > /dev/null 2>&1 && git clone --bare #{backup_path_repo}/#{project.first}.bundle #{project.first}.git > /dev/null 2>&1") - permission_commands = [ - "sudo chmod -R g+rwX #{Gitlab.config.git_base_path}", - "sudo chown -R #{Gitlab.config.ssh_user}:#{Gitlab.config.ssh_user} #{Gitlab.config.git_base_path}" - ] - permission_commands.each { |command| Kernel.system(command) } - puts "done".green + + Project.find_each(:batch_size => 1000) do |project| + print "#{project.path_with_namespace} ... " + + if project.namespace + project.namespace.ensure_dir_exist + end + + # Build a backup path + path_to_bundle = File.join(backup_path_repo, project.path_with_namespace + ".bundle") + + if Kernel.system("git clone --bare #{path_to_bundle} #{project.path_to_repo} > /dev/null 2>&1") + puts "[DONE]".green else - puts "failed".red + puts "[FAILED]".red end end end -- cgit v1.2.1 From 30d6370719263da531d2405fb561d34e1340f49e Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 31 Dec 2012 17:46:40 +0200 Subject: Add subdir support for rewrite-hooks script --- lib/support/rewrite-hooks.sh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/support/rewrite-hooks.sh b/lib/support/rewrite-hooks.sh index 6688785a179..b8fd36b9a1e 100755 --- a/lib/support/rewrite-hooks.sh +++ b/lib/support/rewrite-hooks.sh @@ -11,9 +11,22 @@ do continue fi - project_hook="$src/$dir/hooks/post-receive" - gitolite_hook="/home/git/.gitolite/hooks/common/post-receive" + if [[ "$dir" =~ ^.*.git$ ]] + then + project_hook="$src/$dir/hooks/post-receive" + gitolite_hook="/home/git/.gitolite/hooks/common/post-receive" + + ln -s -f $gitolite_hook $project_hook + else + for subdir in `ls "$src/$dir/"` + do + if [ -d "$src/$dir/$subdir" ] && [[ "$subdir" =~ ^.*.git$ ]]; then + project_hook="$src/$dir/$subdir/hooks/post-receive" + gitolite_hook="/home/git/.gitolite/hooks/common/post-receive" - ln -s -f $gitolite_hook $project_hook + ln -s -f $gitolite_hook $project_hook + fi + done + fi fi done -- cgit v1.2.1 From e5ff5c28694daee117f22ba3a8c21f38a5f14966 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 31 Dec 2012 18:22:44 +0200 Subject: Use project with namespace in email subject --- lib/gitlab/graph/json_builder.rb | 4 ++-- lib/tasks/gitlab/backup.rake | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/graph/json_builder.rb b/lib/gitlab/graph/json_builder.rb index 443704044c7..4a48b3b5675 100644 --- a/lib/gitlab/graph/json_builder.rb +++ b/lib/gitlab/graph/json_builder.rb @@ -17,14 +17,14 @@ module Gitlab @commits = collect_commits @days = index_commits end - + def to_json(*args) { days: @days.compact.map { |d| [d.day, d.strftime("%b")] }, commits: @commits.map(&:to_graph_hash) }.to_json(*args) end - + protected # Get commits from repository diff --git a/lib/tasks/gitlab/backup.rake b/lib/tasks/gitlab/backup.rake index 82c8dd8ca11..677ecf21bdc 100644 --- a/lib/tasks/gitlab/backup.rake +++ b/lib/tasks/gitlab/backup.rake @@ -118,10 +118,10 @@ namespace :gitlab do task :create => :environment do backup_path_repo = File.join(Gitlab.config.backup.path, "repositories") FileUtils.mkdir_p(backup_path_repo) until Dir.exists?(backup_path_repo) - puts "Dumping repositories ..." + puts "Dumping repositories ...".blue Project.find_each(:batch_size => 1000) do |project| - print "#{project.path_with_namespace} ... " + print " * #{project.path_with_namespace} ... " if project.empty_repo? puts "[SKIPPED]".cyan @@ -174,9 +174,9 @@ namespace :gitlab do backup_path_db = File.join(Gitlab.config.backup.path, "db") FileUtils.mkdir_p(backup_path_db) unless Dir.exists?(backup_path_db) - puts "Dumping database tables ... " + puts "Dumping database tables ... ".blue ActiveRecord::Base.connection.tables.each do |tbl| - print "#{tbl.yellow} ... " + print " * #{tbl.yellow} ... " count = 1 File.open(File.join(backup_path_db, tbl + ".yml"), "w+") do |file| ActiveRecord::Base.connection.select_all("SELECT * FROM `#{tbl}`").each do |line| -- cgit v1.2.1 From d431e4339269041784986da40a0e0879baaf96a9 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 2 Jan 2013 19:32:34 +0200 Subject: Fix few bugs and tests after refactoring ownership logic --- lib/api/projects.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/api/projects.rb b/lib/api/projects.rb index fb01524da39..c71fd64838b 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -9,7 +9,7 @@ module Gitlab # Example Request: # GET /projects get do - @projects = paginate current_user.projects + @projects = paginate current_user.authorized_projects present @projects, with: Entities::Project end -- cgit v1.2.1 From 67896ea9a258eee8bb8ecca849d59f48e16ac77a Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 2 Jan 2013 20:25:25 +0200 Subject: Fixed missing current user for issue observer --- lib/api/issues.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 3be558816b5..4d832fbe593 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -78,6 +78,7 @@ module Gitlab attrs = attributes_for_keys [:title, :description, :assignee_id, :milestone_id, :closed] attrs[:label_list] = params[:labels] if params[:labels].present? + IssueObserver.current_user = current_user if @issue.update_attributes attrs present @issue, with: Entities::Issue else -- cgit v1.2.1 From 1b25a8f4374363d546d4a58f47c6fe00c3b3af07 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 2 Jan 2013 22:39:02 +0200 Subject: Improve Extract path --- lib/extracts_path.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/extracts_path.rb b/lib/extracts_path.rb index 220e3d2271f..0b7a0d47caf 100644 --- a/lib/extracts_path.rb +++ b/lib/extracts_path.rb @@ -51,7 +51,7 @@ module ExtractsPath return pair unless @project # Remove project, actions and all other staff from path - input.gsub!("/#{@project.path_with_namespace}", "") + input.gsub!(/^\/#{Regexp.escape(@project.path_with_namespace)}/, "") input.gsub!(/^\/(tree|commits|blame|blob)\//, "") # remove actions input.gsub!(/\?.*$/, "") # remove stamps suffix input.gsub!(/.atom$/, "") # remove rss feed @@ -108,7 +108,9 @@ module ExtractsPath request.format = :atom end - @ref, @path = extract_ref(request.fullpath) + path = request.fullpath.dup + + @ref, @path = extract_ref(path) @id = File.join(@ref, @path) -- cgit v1.2.1 From cac7723451e575ce39a6930990178450a2a972f0 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 2 Jan 2013 23:35:11 +0200 Subject: Get rid of roles --- lib/git_host.rb | 11 ++++++++ lib/issue_commonality.rb | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/static_model.rb | 47 ++++++++++++++++++++++++++++++++ lib/votes.rb | 39 ++++++++++++++++++++++++++ 4 files changed, 168 insertions(+) create mode 100644 lib/git_host.rb create mode 100644 lib/issue_commonality.rb create mode 100644 lib/static_model.rb create mode 100644 lib/votes.rb (limited to 'lib') diff --git a/lib/git_host.rb b/lib/git_host.rb new file mode 100644 index 00000000000..2410e0fec42 --- /dev/null +++ b/lib/git_host.rb @@ -0,0 +1,11 @@ +# == GitHost role +# +# Provide a shortcut to Gitlab::Gitolite instance +# +# Used by Project, UsersProject +# +module GitHost + def git_host + Gitlab::Gitolite.new + end +end diff --git a/lib/issue_commonality.rb b/lib/issue_commonality.rb new file mode 100644 index 00000000000..b755936c9c1 --- /dev/null +++ b/lib/issue_commonality.rb @@ -0,0 +1,71 @@ +# == 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 diff --git a/lib/static_model.rb b/lib/static_model.rb new file mode 100644 index 00000000000..5b64be1f041 --- /dev/null +++ b/lib/static_model.rb @@ -0,0 +1,47 @@ +# Provides an ActiveRecord-like interface to a model whose data is not persisted to a database. +module StaticModel + extend ActiveSupport::Concern + + module ClassMethods + # Used by ActiveRecord's polymorphic association to set object_id + def primary_key + 'id' + end + + # Used by ActiveRecord's polymorphic association to set object_type + def base_class + self + end + end + + # Used by AR for fetching attributes + # + # Pass it along if we respond to it. + def [](key) + send(key) if respond_to?(key) + end + + def to_param + id + end + + def new_record? + false + end + + def persisted? + false + end + + def destroyed? + false + end + + def ==(other) + if other.is_a? StaticModel + id == other.id + else + super + end + end +end diff --git a/lib/votes.rb b/lib/votes.rb new file mode 100644 index 00000000000..dfd751b1b11 --- /dev/null +++ b/lib/votes.rb @@ -0,0 +1,39 @@ +# == 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 -- cgit v1.2.1 From da03a5c7e25601c2bce8375dbbe1cffc58db7bbf Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 3 Jan 2013 09:06:07 +0200 Subject: more refactoring using models/concerns --- lib/git_host.rb | 11 -------- lib/gitolited.rb | 11 ++++++++ lib/issue_commonality.rb | 71 ------------------------------------------------ lib/votes.rb | 39 -------------------------- 4 files changed, 11 insertions(+), 121 deletions(-) delete mode 100644 lib/git_host.rb create mode 100644 lib/gitolited.rb delete mode 100644 lib/issue_commonality.rb delete mode 100644 lib/votes.rb (limited to 'lib') diff --git a/lib/git_host.rb b/lib/git_host.rb deleted file mode 100644 index 2410e0fec42..00000000000 --- a/lib/git_host.rb +++ /dev/null @@ -1,11 +0,0 @@ -# == GitHost role -# -# Provide a shortcut to Gitlab::Gitolite instance -# -# Used by Project, UsersProject -# -module GitHost - def git_host - Gitlab::Gitolite.new - end -end diff --git a/lib/gitolited.rb b/lib/gitolited.rb new file mode 100644 index 00000000000..68b9b625525 --- /dev/null +++ b/lib/gitolited.rb @@ -0,0 +1,11 @@ +# == 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 diff --git a/lib/issue_commonality.rb b/lib/issue_commonality.rb deleted file mode 100644 index b755936c9c1..00000000000 --- a/lib/issue_commonality.rb +++ /dev/null @@ -1,71 +0,0 @@ -# == 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 diff --git a/lib/votes.rb b/lib/votes.rb deleted file mode 100644 index dfd751b1b11..00000000000 --- a/lib/votes.rb +++ /dev/null @@ -1,39 +0,0 @@ -# == 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 -- cgit v1.2.1 From 6b9177ca0209b78398edb409f11bb7b4f5db7ca3 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Fri, 7 Dec 2012 01:51:49 +0100 Subject: replaced system() calls with FileUtils.* method This also makes that 'mv: cannot stat `/ho..' is not shown in the test :) consistent spacing require fileutils Revert "require fileutils" This reverts commit 54313d3bbaa60cfc5b405be50cc00b7f6b0cb715. new hash notation FileUtils.mv in begin/rescue block --- lib/gitlab/project_mover.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/project_mover.rb b/lib/gitlab/project_mover.rb index def6e90001b..207e585f572 100644 --- a/lib/gitlab/project_mover.rb +++ b/lib/gitlab/project_mover.rb @@ -16,7 +16,7 @@ module Gitlab def execute # Create new dir if missing new_dir_path = File.join(Gitlab.config.gitolite.repos_path, new_dir) - system("mkdir -m 770 #{new_dir_path}") unless File.exists?(new_dir_path) + FileUtils.mkdir( new_dir_path, mode: 0770 ) unless File.exists?(new_dir_path) old_path = File.join(Gitlab.config.gitolite.repos_path, old_dir, "#{project.path}.git") new_path = File.join(new_dir_path, "#{project.path}.git") @@ -25,17 +25,18 @@ module Gitlab raise ProjectMoveError.new("Destination #{new_path} already exists") end - if system("mv #{old_path} #{new_path}") + begin + FileUtils.mv( old_path, new_path ) log_info "Project #{project.name} was moved from #{old_path} to #{new_path}" true - else + rescue Exception => e message = "Project #{project.name} cannot be moved from #{old_path} to #{new_path}" - log_info "Error! #{message}" + log_info "Error! #{message} (#{e.message})" raise ProjectMoveError.new(message) end end - protected + protected def log_info message Gitlab::AppLogger.info message -- cgit v1.2.1 From 39ba934c0a65f571214998e056e925b61f389360 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 3 Jan 2013 21:09:18 +0200 Subject: REpostiry, Team models --- lib/extracts_path.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/extracts_path.rb b/lib/extracts_path.rb index 0b7a0d47caf..5c96eac02e7 100644 --- a/lib/extracts_path.rb +++ b/lib/extracts_path.rb @@ -68,7 +68,7 @@ module ExtractsPath id = input id += '/' unless id.ends_with?('/') - valid_refs = @project.ref_names + valid_refs = @project.repository.ref_names valid_refs.select! { |v| id.start_with?("#{v}/") } if valid_refs.length != 1 @@ -114,9 +114,9 @@ module ExtractsPath @id = File.join(@ref, @path) - @commit = CommitDecorator.decorate(@project.commit(@ref)) + @commit = CommitDecorator.decorate(@project.repository.commit(@ref)) - @tree = Tree.new(@commit.tree, @project, @ref, @path) + @tree = Tree.new(@commit.tree, @ref, @path) @tree = TreeDecorator.new(@tree) raise InvalidPathError if @tree.invalid? -- cgit v1.2.1 From dccd8b6eaa8b2e98b0245262a8e39df8fb8ae634 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 4 Jan 2013 08:43:25 +0200 Subject: Continue refactoring. Use repostory and team --- lib/gitlab/backend/gitolite_config.rb | 8 ++++---- lib/gitlab/markdown.rb | 2 +- lib/gitlab/satellite/merge_action.rb | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/backend/gitolite_config.rb b/lib/gitlab/backend/gitolite_config.rb index a2bc4ca8d74..10e527eac73 100644 --- a/lib/gitlab/backend/gitolite_config.rb +++ b/lib/gitlab/backend/gitolite_config.rb @@ -82,7 +82,7 @@ module Gitlab end def destroy_project(project) - FileUtils.rm_rf(project.path_to_repo) + FileUtils.rm_rf(project.repository.path_to_repo) conf.rm_repo(project.path_with_namespace) end @@ -138,9 +138,9 @@ module Gitlab ::Gitolite::Config::Repo.new(repo_name) end - name_readers = project.repository_readers - name_writers = project.repository_writers - name_masters = project.repository_masters + name_readers = project.team.repository_readers + name_writers = project.team.repository_writers + name_masters = project.team.repository_masters pr_br = project.protected_branches.map(&:name).join("$ ") diff --git a/lib/gitlab/markdown.rb b/lib/gitlab/markdown.rb index 859184b6c3a..59249a229eb 100644 --- a/lib/gitlab/markdown.rb +++ b/lib/gitlab/markdown.rb @@ -170,7 +170,7 @@ module Gitlab end def reference_commit(identifier) - if @project.valid_repo? && commit = @project.commit(identifier) + if @project.valid_repo? && commit = @project.repository.commit(identifier) link_to(identifier, project_commit_path(@project, commit), html_options.merge(title: CommitDecorator.new(commit).link_title, class: "gfm gfm-commit #{html_options[:class]}")) end end diff --git a/lib/gitlab/satellite/merge_action.rb b/lib/gitlab/satellite/merge_action.rb index 832db6621c4..556a1e2d52f 100644 --- a/lib/gitlab/satellite/merge_action.rb +++ b/lib/gitlab/satellite/merge_action.rb @@ -31,7 +31,7 @@ module Gitlab merge_repo.git.push({raise: true, timeout: true}, :origin, merge_request.target_branch) # remove source branch - if merge_request.should_remove_source_branch && !project.root_ref?(merge_request.source_branch) + if merge_request.should_remove_source_branch && !project.repository.root_ref?(merge_request.source_branch) # will raise CommandFailed when push fails merge_repo.git.push({raise: true, timeout: true}, :origin, ":#{merge_request.source_branch}") end -- cgit v1.2.1 From 90cba379a436a942d5d71bfb0bb5a9a321fcbd2b Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Fri, 28 Dec 2012 16:36:42 +0100 Subject: Updated graph tooltips and labels --- lib/gitlab/graph/commit.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/graph/commit.rb b/lib/gitlab/graph/commit.rb index 3d82c34432f..a6bf23a2381 100644 --- a/lib/gitlab/graph/commit.rb +++ b/lib/gitlab/graph/commit.rb @@ -22,14 +22,16 @@ module Gitlab h[:parents] = self.parents.collect do |p| [p.id,0,0] end - h[:author] = author.name + h[:author] = { + name: author.name, + email: author.email + } h[:time] = time h[:space] = space h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil? h[:id] = sha h[:date] = date h[:message] = message - h[:login] = author.email h end -- cgit v1.2.1 From fd4bcd9f09305c057e91a4f791c74d00da9ac143 Mon Sep 17 00:00:00 2001 From: Wouter D'Haeseleer Date: Fri, 4 Jan 2013 15:05:00 +0100 Subject: Fixing request.fullpath URL encoding Let's assume your path is = "project/tree/master/This%20Is%20valid" In this case gitlab renders a 404. To fix this we should decode the path so that it looks like "project/tree/master/This Is valid" --- lib/extracts_path.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/extracts_path.rb b/lib/extracts_path.rb index 0b7a0d47caf..d1e569ce3e5 100644 --- a/lib/extracts_path.rb +++ b/lib/extracts_path.rb @@ -108,7 +108,7 @@ module ExtractsPath request.format = :atom end - path = request.fullpath.dup + path = CGI::unescape(request.fullpath.dup) @ref, @path = extract_ref(path) -- cgit v1.2.1 From 29623d77e48e3fd103990b9582f754fb5792f24e Mon Sep 17 00:00:00 2001 From: gliptak Date: Fri, 4 Jan 2013 10:14:55 -0500 Subject: Renaming check function from 1056 to 1059 --- lib/tasks/gitlab/check.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index 72111f87567..fff1be5577b 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -256,7 +256,7 @@ namespace :gitlab do start_checking "Environment" check_gitlab_in_git_group - check_issue_1056_shell_profile_error + check_issue_1059_shell_profile_error check_gitlab_git_config check_python2_exists check_python2_version @@ -313,7 +313,7 @@ namespace :gitlab do end # see https://github.com/gitlabhq/gitlabhq/issues/1059 - def check_issue_1056_shell_profile_error + def check_issue_1059_shell_profile_error gitolite_ssh_user = Gitlab.config.gitolite.ssh_user print "Has no \"-e\" in ~#{gitolite_ssh_user}/.profile ... " -- cgit v1.2.1 From afbdbb0c959affbdb8725eafb8169025a8aede1e Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 4 Jan 2013 18:50:31 +0200 Subject: Rspec fixes --- lib/api/notes.rb | 4 ++-- lib/api/projects.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/api/notes.rb b/lib/api/notes.rb index 4875ac4c03e..4613db54578 100644 --- a/lib/api/notes.rb +++ b/lib/api/notes.rb @@ -13,7 +13,7 @@ module Gitlab # Example Request: # GET /projects/:id/notes get ":id/notes" do - @notes = user_project.common_notes + @notes = user_project.notes.common present paginate(@notes), with: Entities::Note end @@ -25,7 +25,7 @@ module Gitlab # Example Request: # GET /projects/:id/notes/:note_id get ":id/notes/:note_id" do - @note = user_project.common_notes.find(params[:note_id]) + @note = user_project.notes.common.find(params[:note_id]) present @note, with: Entities::Note end diff --git a/lib/api/projects.rb b/lib/api/projects.rb index c71fd64838b..55c81f3158a 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -257,7 +257,7 @@ module Gitlab per_page = params[:per_page] || 20 ref = params[:ref_name] || user_project.try(:default_branch) || 'master' - commits = user_project.commits(ref, nil, per_page, page * per_page) + commits = user_project.repository.commits(ref, nil, per_page, page * per_page) present CommitDecorator.decorate(commits), with: Entities::RepoCommit end @@ -375,10 +375,10 @@ module Gitlab ref = params[:sha] - commit = user_project.commit ref + commit = user_project.repository.commit ref not_found! "Commit" unless commit - tree = Tree.new commit.tree, user_project, ref, params[:filepath] + tree = Tree.new commit.tree, ref, params[:filepath] not_found! "File" unless tree.try(:tree) content_type tree.mime_type -- cgit v1.2.1 From e16cebac3eaadc0df93576358f60ae4a498ce15f Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sat, 5 Jan 2013 00:35:38 +0200 Subject: Fixed styles, ProjectHook specs etc --- lib/static_model.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/static_model.rb b/lib/static_model.rb index 5b64be1f041..185921d8fbe 100644 --- a/lib/static_model.rb +++ b/lib/static_model.rb @@ -38,7 +38,7 @@ module StaticModel end def ==(other) - if other.is_a? StaticModel + if other.is_a? ::StaticModel id == other.id else super -- cgit v1.2.1 From eded4bfa95320974a0a2f52da2ce0f46974734bb Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sat, 5 Jan 2013 23:09:26 +0200 Subject: Raise exception and show message to user if repo missing satellite --- lib/gitlab/satellite/satellite.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/satellite/satellite.rb b/lib/gitlab/satellite/satellite.rb index 784b146b98a..a0abf1918ca 100644 --- a/lib/gitlab/satellite/satellite.rb +++ b/lib/gitlab/satellite/satellite.rb @@ -1,4 +1,6 @@ module Gitlab + class SatelliteNotExistError < StandardError; end + module Satellite class Satellite PARKING_BRANCH = "__parking_branch" @@ -9,8 +11,12 @@ module Gitlab @project = project end + def raise_no_satellite + raise SatelliteNotExistError.new("Satellite doesn't exist") + end + def clear_and_update! - raise "Satellite doesn't exist" unless exists? + raise_no_satellite unless exists? delete_heads! clear_working_dir! @@ -35,7 +41,7 @@ module Gitlab # * Changes the current directory to the satellite's working dir # * Yields def lock - raise "Satellite doesn't exist" unless exists? + raise_no_satellite unless exists? File.open(lock_file, "w+") do |f| f.flock(File::LOCK_EX) @@ -55,7 +61,7 @@ module Gitlab end def repo - raise "Satellite doesn't exist" unless exists? + raise_no_satellite unless exists? @repo ||= Grit::Repo.new(path) end -- cgit v1.2.1 From 2c8a46e0fe0232e811e4bfbb0fa8d607298fdf10 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sat, 5 Jan 2013 23:29:48 +0200 Subject: Fix backup/restore path_to_repo --- lib/tasks/gitlab/backup.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/tasks/gitlab/backup.rake b/lib/tasks/gitlab/backup.rake index 677ecf21bdc..ae2b1bb793f 100644 --- a/lib/tasks/gitlab/backup.rake +++ b/lib/tasks/gitlab/backup.rake @@ -134,7 +134,7 @@ namespace :gitlab do # Build a destination path for backup path_to_bundle = File.join(backup_path_repo, project.path_with_namespace + ".bundle") - if Kernel.system("cd #{project.path_to_repo} > /dev/null 2>&1 && git bundle create #{path_to_bundle} --all > /dev/null 2>&1") + if Kernel.system("cd #{project.repository.path_to_repo} > /dev/null 2>&1 && git bundle create #{path_to_bundle} --all > /dev/null 2>&1") puts "[DONE]".green else puts "[FAILED]".red @@ -158,7 +158,7 @@ namespace :gitlab do # Build a backup path path_to_bundle = File.join(backup_path_repo, project.path_with_namespace + ".bundle") - if Kernel.system("git clone --bare #{path_to_bundle} #{project.path_to_repo} > /dev/null 2>&1") + if Kernel.system("git clone --bare #{path_to_bundle} #{project.repository.path_to_repo} > /dev/null 2>&1") puts "[DONE]".green else puts "[FAILED]".red -- cgit v1.2.1 From fb470e8e2aff80a16b56f9c5422c04e74dcb213c Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 7 Jan 2013 17:36:24 +0200 Subject: Validate username uniq in scope of namespace --- lib/tasks/travis.rake | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/tasks/travis.rake b/lib/tasks/travis.rake index e04bfbaf1c0..6b434830803 100644 --- a/lib/tasks/travis.rake +++ b/lib/tasks/travis.rake @@ -1,7 +1,5 @@ -task :travis do - ["rake spinach", "rake spec"].each do |cmd| - puts "Starting to run #{cmd}..." - system("export DISPLAY=:99.0 && bundle exec #{cmd}") - raise "#{cmd} failed!" unless $?.exitstatus == 0 - end -end +desc "Travis run tests" +task :travis => [ + :spinach, + :spec +] -- cgit v1.2.1 From 3e89244e08ed79564c0c483cb1f810936d661996 Mon Sep 17 00:00:00 2001 From: Mitch Tishmack Date: Mon, 7 Jan 2013 11:07:11 -0600 Subject: Update info.rake to be able to run successfully on SuSE. --- lib/tasks/gitlab/info.rake | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib') diff --git a/lib/tasks/gitlab/info.rake b/lib/tasks/gitlab/info.rake index 3fbedda7721..fcd590134d6 100644 --- a/lib/tasks/gitlab/info.rake +++ b/lib/tasks/gitlab/info.rake @@ -12,6 +12,9 @@ namespace :gitlab do debian_version = File.read('/etc/debian_version') "Debian #{debian_version}" end + os_name ||= if File.readable?('/etc/SuSE-release') + File.read('/etc/SuSE-release') + end os_name.squish! # check if there is an RVM environment -- cgit v1.2.1 From 11e28aff7db8498dc08165717b476a7b0a34533f Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Mon, 7 Jan 2013 19:04:20 +0100 Subject: Fix accessing the project repository path in check task Fixes #2496 --- lib/tasks/gitlab/check.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index fff1be5577b..72330440dbf 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -759,7 +759,7 @@ namespace :gitlab do print "#{project.name_with_namespace.yellow} ... " correct_options = options.map do |name, value| - run("git --git-dir=\"#{project.path_to_repo}\" config --get #{name}").try(:chomp) == value + run("git --git-dir=\"#{project.repository.path_to_repo}\" config --get #{name}").try(:chomp) == value end if correct_options.all? @@ -798,7 +798,7 @@ namespace :gitlab do Project.find_each(batch_size: 100) do |project| print "#{project.name_with_namespace.yellow} ... " - project_hook_file = File.join(project.path_to_repo, "hooks", hook_file) + project_hook_file = File.join(project.repository.path_to_repo, "hooks", hook_file) unless File.exists?(project_hook_file) puts "missing".red -- cgit v1.2.1 From b7314a1687cf67bc8b74f652e44d9b0cb92d4826 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Mon, 7 Jan 2013 19:19:50 +0100 Subject: Fix bug in OS detection in check task --- lib/tasks/gitlab/info.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/tasks/gitlab/info.rake b/lib/tasks/gitlab/info.rake index fcd590134d6..fd3e83e8338 100644 --- a/lib/tasks/gitlab/info.rake +++ b/lib/tasks/gitlab/info.rake @@ -15,7 +15,7 @@ namespace :gitlab do os_name ||= if File.readable?('/etc/SuSE-release') File.read('/etc/SuSE-release') end - os_name.squish! + os_name.try(:squish!) # check if there is an RVM environment rvm_version = run_and_match("rvm --version", /[\d\.]+/).try(:to_s) -- cgit v1.2.1 From b5f116f08bfd02f87b819411f89d93c711411c90 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Mon, 7 Jan 2013 19:39:15 +0100 Subject: Add a check whether repos_path is a symlink --- lib/tasks/gitlab/check.rake | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'lib') diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index 72330440dbf..494d756b794 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -398,6 +398,7 @@ namespace :gitlab do check_dot_gitolite_user_and_group check_dot_gitolite_permissions check_repo_base_exists + check_repo_base_is_not_symlink check_repo_base_user_and_group check_repo_base_permissions check_can_clone_gitolite_admin @@ -692,6 +693,26 @@ namespace :gitlab do end end + def check_repo_base_is_not_symlink + print "Repo base directory is a symlink? ... " + + repo_base_path = Gitlab.config.gitolite.repos_path + unless File.exists?(repo_base_path) + puts "can't check because of previous errors".magenta + return + end + + unless File.symlink?(repo_base_path) + puts "no".green + else + puts "yes".red + try_fixing_it( + "Make sure it's set to the real directory in config/gitlab.yml" + ) + fix_and_rerun + end + end + def check_repo_base_permissions print "Repo base access is drwsrws---? ... " -- cgit v1.2.1 From ea8cd13f79f52e500ddb174f18ae0d6bd83631e7 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Mon, 7 Jan 2013 19:47:53 +0100 Subject: Fix check for outdated config file --- lib/tasks/gitlab/check.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index 494d756b794..3d091441a16 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -98,7 +98,7 @@ namespace :gitlab do end # omniauth or ldap could have been deleted from the file - unless Gitlab.config.pre_40_config + unless Gitlab.config['git_host'] puts "no".green else puts "yes".red -- cgit v1.2.1 From 71c8801eefd64d4b2e2f37205b1a5415e3c5bf93 Mon Sep 17 00:00:00 2001 From: Riyad Preukschas Date: Mon, 7 Jan 2013 21:18:41 +0100 Subject: Fix checking for the recommended Gitolite version Fixes #2475 --- lib/tasks/gitlab/check.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index 3d091441a16..252b508609a 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -544,7 +544,7 @@ namespace :gitlab do def check_gitolite_is_up_to_date print "Using recommended version ... " - if gitolite_version.try(:start_with?, "v3.04") + if gitolite_version.try(:start_with?, "v3.2") puts "yes".green else puts "no".red -- cgit v1.2.1 From aa97ff7fde07a682db59bbcfbac21cf35d8acc08 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 9 Jan 2013 09:34:26 +0200 Subject: Fixed tree logs for branches with slash. Fixed remember of path when switch branch --- lib/extracts_path.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/extracts_path.rb b/lib/extracts_path.rb index 5c96eac02e7..14201ae63ce 100644 --- a/lib/extracts_path.rb +++ b/lib/extracts_path.rb @@ -52,7 +52,7 @@ module ExtractsPath # Remove project, actions and all other staff from path input.gsub!(/^\/#{Regexp.escape(@project.path_with_namespace)}/, "") - input.gsub!(/^\/(tree|commits|blame|blob)\//, "") # remove actions + input.gsub!(/^\/(tree|commits|blame|blob|refs)\//, "") # remove actions input.gsub!(/\?.*$/, "") # remove stamps suffix input.gsub!(/.atom$/, "") # remove rss feed input.gsub!(/\/edit$/, "") # remove edit route part -- cgit v1.2.1 From c7bb3a1f726be189ccce51bdd631b26eb4f64db1 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 9 Jan 2013 08:14:05 +0300 Subject: sidekiq --- lib/tasks/resque.rake | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/tasks/resque.rake b/lib/tasks/resque.rake index 0c3b93c5bed..e469aef3f94 100644 --- a/lib/tasks/resque.rake +++ b/lib/tasks/resque.rake @@ -2,20 +2,20 @@ require 'resque/tasks' namespace :resque do task setup: :environment do - Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection } + #Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection } end desc "Resque | kill all workers (using -QUIT), god will take care of them" task :stop_workers => :environment do - pids = Array.new + #pids = Array.new - Resque.workers.each do |worker| - pids << worker.to_s.split(/:/).second - end + #Resque.workers.each do |worker| + #pids << worker.to_s.split(/:/).second + #end - if pids.size > 0 - system("kill -QUIT #{pids.join(' ')}") - end + #if pids.size > 0 + #system("kill -QUIT #{pids.join(' ')}") + #end end end -- cgit v1.2.1 From 71bd9568669d18bc04c551a603a04af2ea99328c Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 9 Jan 2013 08:44:05 +0300 Subject: email via sidekiq. start and stop rake tasks --- lib/tasks/resque.rake | 23 ----------------------- lib/tasks/sidekiq.rake | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 23 deletions(-) delete mode 100644 lib/tasks/resque.rake create mode 100644 lib/tasks/sidekiq.rake (limited to 'lib') diff --git a/lib/tasks/resque.rake b/lib/tasks/resque.rake deleted file mode 100644 index e469aef3f94..00000000000 --- a/lib/tasks/resque.rake +++ /dev/null @@ -1,23 +0,0 @@ -require 'resque/tasks' - -namespace :resque do - task setup: :environment do - #Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection } - end - - desc "Resque | kill all workers (using -QUIT), god will take care of them" - task :stop_workers => :environment do - #pids = Array.new - - #Resque.workers.each do |worker| - #pids << worker.to_s.split(/:/).second - #end - - #if pids.size > 0 - #system("kill -QUIT #{pids.join(' ')}") - #end - end -end - -desc "Alias for resque:work (To run workers on Heroku)" -task "jobs:work" => "resque:work" diff --git a/lib/tasks/sidekiq.rake b/lib/tasks/sidekiq.rake new file mode 100644 index 00000000000..6bbcb3da4bc --- /dev/null +++ b/lib/tasks/sidekiq.rake @@ -0,0 +1,23 @@ +namespace :sidekiq do + desc "GITLAB | Stop sidekiq" + task :stop do + run "bundle exec sidekiqctl stop #{pidfile}" + end + + desc "GITLAB | Start sidekiq" + task :start do + run "nohup bundle exec sidekiq -q post_receive,mailer,system_hook,common,default -e #{rails_env} -P #{pidfile} >> #{root_path}/log/sidekiq.log 2>&1 &" + end + + def root_path + @root_path ||= File.join(File.expand_path(File.dirname(__FILE__)), "../..") + end + + def pidfile + "#{root_path}/tmp/pids/sidekiq.pid" + end + + def rails_env + ENV['RAILS_ENV'] || "production" + end +end -- cgit v1.2.1 From 9773ccc4519c4c35f969248c4e0f13689b631760 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 9 Jan 2013 09:14:05 +0300 Subject: sidekiq with green tests --- lib/hooks/post-receive | 1 + lib/tasks/gitlab/check.rake | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/hooks/post-receive b/lib/hooks/post-receive index ebd9e1a028a..6944d3e3f72 100755 --- a/lib/hooks/post-receive +++ b/lib/hooks/post-receive @@ -1,5 +1,6 @@ #!/usr/bin/env bash +# Version 4.1 # This file was placed here by GitLab. It makes sure that your pushed commits # will be processed properly. diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index 252b508609a..db181cb9a96 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -871,7 +871,7 @@ namespace :gitlab do namespace :resque do - desc "GITLAB | Check the configuration of Resque" + desc "GITLAB | Check the configuration of Sidekiq" task check: :environment do warn_user_is_not_gitlab start_checking "Resque" @@ -888,7 +888,7 @@ namespace :gitlab do def check_resque_running print "Running? ... " - if run_and_match("ps aux | grep -i resque", /resque-[\d\.]+:.+$/) + if run_and_match("ps aux | grep -i sidekiq", /sidekiq-[\d\.]+:.+$/) puts "yes".green else puts "no".red @@ -899,7 +899,7 @@ namespace :gitlab do ) for_more_information( see_installation_guide_section("Install Init Script"), - "see log/resque.log for possible errors" + "see log/sidekiq.log for possible errors" ) fix_and_rerun end -- cgit v1.2.1 From 6869a5640347bb391aea657c763716f27dea380e Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 9 Jan 2013 20:31:05 +0200 Subject: Fix sidekiq chech and added script/check --- lib/tasks/gitlab/check.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index db181cb9a96..5d850a17fe3 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -888,7 +888,7 @@ namespace :gitlab do def check_resque_running print "Running? ... " - if run_and_match("ps aux | grep -i sidekiq", /sidekiq-[\d\.]+:.+$/) + if run_and_match("ps aux | grep -i sidekiq", /sidekiq \d\.\d\.\d.+$/) puts "yes".green else puts "no".red -- cgit v1.2.1