Skip to content
Snippets Groups Projects
Select Git revision
  • ag-test
  • rs-test
  • master default protected
  • test-me-pa
  • mksionek-master-patch-52381
  • new-branch-10
  • test-conflicts
  • test-suggestions
  • alejandro-test
  • patch-25
  • winh-test-image-doscussion
  • stg-lfs-image-test-2
  • stg-lfs-image-test
  • test42016
  • issue_42016
  • issue-32709
  • add-codeowners
  • ClemMakesApps-master-patch-62759
  • bvl-staging-test
  • bvl-merge-base-api
  • v9.2.0-rc6 protected
  • v9.2.0-rc5 protected
  • v9.2.0-rc4 protected
  • v9.2.0-rc3 protected
  • v9.1.4 protected
  • v9.2.0-rc2 protected
  • v9.2.0-rc1 protected
  • v9.1.3 protected
  • v8.17.6 protected
  • v9.0.7 protected
  • v9.1.2 protected
  • v9.1.1 protected
  • v9.2.0.pre protected
  • v9.1.0 protected
  • v9.1.0-rc7 protected
  • v9.1.0-rc6 protected
  • v9.0.6 protected
  • v9.1.0-rc5 protected
  • v9.1.0-rc4 protected
  • v9.1.0-rc3 protected
40 results

import.rake

Code owners
Assign users and groups as approvers for specific file changes. Learn more.
import.rake 2.36 KiB
namespace :gitlab do
  namespace :import do
    # How to use:
    #
    #  1. copy the bare repos under the repos_path (commonly /home/git/repositories)
    #  2. run: bundle exec rake gitlab:import:repos RAILS_ENV=production
    #
    # Notes:
    #  * The project owner will set to the first administator of the system
    #  * Existing projects will be skipped
    #
    desc "GITLAB | Import bare repositories from gitlab_shell -> repos_path into GitLab project instance"
    task repos: :environment do

      git_base_path = Gitlab.config.gitlab_shell.repos_path
      repos_to_import = Dir.glob(git_base_path + '/**/*.git')

      namespaces = Namespace.pluck(:path)

      repos_to_import.each do |repo_path|
        # strip repo base path
        repo_path[0..git_base_path.length] = ''

        path = repo_path.sub(/\.git$/, '')
        name = File.basename path
        group_name = File.dirname path
        group_name = nil if group_name == '.'

        # Skip if group or user
        next if namespaces.include?(name)

        puts "Processing #{repo_path}".yellow

        if path =~ /.wiki\Z/
          puts " * Skipping wiki repo"
          next
        end

        project = Project.find_with_namespace(path)

        if project
          puts " * #{project.name} (#{repo_path}) exists"
        else
          user = User.admins.first

          project_params = {
            name: name,
            path: name
          }

          # find group namespace
          if group_name
            group = Group.find_by_path(group_name)
            # create group namespace
            if !group
              group = Group.new(:name => group_name)
              group.path = group_name
              group.owner = user
              if group.save
                puts " * Created Group #{group.name} (#{group.id})".green
              else
                puts " * Failed trying to create group #{group.name}".red
              end
            end
            # set project group
            project_params[:namespace_id] = group.id
          end

          project = Projects::CreateService.new(user, project_params).execute
          if project.valid?
            puts " * Created #{project.name} (#{repo_path})".green
          else
            puts " * Failed trying to create #{project.name} (#{repo_path})".red
          end
        end
      end

      puts "Done!".green
    end
  end
end