Module: BitbucketMigration

Defined in:
lib/bitbucket_migration.rb,
lib/bitbucket_migration/api.rb,
lib/bitbucket_migration/version.rb,
lib/bitbucket_migration/csv_import.rb,
lib/bitbucket_migration/git_workdir.rb,
lib/bitbucket_migration/configuration.rb,
lib/bitbucket_migration/git_interface.rb,
lib/bitbucket_migration/git_repository.rb

Defined Under Namespace

Classes: Api, CSVImport, Configuration, GitInterface, GitRepository, WorkDir

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.run!(argv) ⇒ Object

Main method implementing command line interface



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/bitbucket_migration.rb', line 13

def self.run!(argv)
  options = {}
  opt_parser =OptionParser.new do |opts|
    opts.banner = "Usage: bitbucket_migration [options]"

    options[:config] = nil
    opts.on("-c", "--config FILE", String, "Configuration file with bitbucket credentials") do |conf|
      options[:config] = conf
    end

    options[:list] = nil
    opts.on("-l", "--list FILE", String, "List file in CSV format with repository migration information") do |list|
      options[:list] = list
    end

    opts.on("-h", "--help", "Show help") do |h|
      options[:help] = h
      puts opt_parser
      exit
    end

    opts.on("-v", "--version", "Show version") do |vers|
      options[:version] = vers
      puts BitbucketMigration::VERSION
      exit
    end
  end

  begin
    opt_parser.parse!(argv)

    required = [:config, :list]
    missing = required.select { |param| options[param].nil? }
    if not missing.empty?
      puts "Missing options: #{required.join(', ')}"
      puts opt_parser
      exit
    end

    begin
      config    =BitbucketMigration::Configuration.new(options[:config])
      list      =BitbucketMigration::CSVImport.new(options[:list])
      bitbucket =BitbucketMigration::Api.new(config.username, config.password, config.team)

      list.repositories.each do |src_repo|
        # Print current migration
        puts "Migrating repository #{src_repo.name}"
        workdir       =BitbucketMigration::WorkDir.new
        target_repo   =bitbucket.create_repository(src_repo.name, src_repo.language)
        if (bitbucket.repository_exists?(src_repo.name))
          gitinterface  =BitbucketMigration::GitInterface.new(src_repo, target_repo)
          gitinterface.init_src_repo(workdir.path)
          gitinterface.init_target_repo
          gitinterface.fetch_src_repo_all
          gitinterface.push_target_repo_all
        end
        workdir.clean!
      end
    rescue
      puts $!.to_s
      exit
    end
  rescue OptionParser::InvalidOption, OptionParser::MissingArgument
    puts $!.to_s
    puts opt_parser
    exit
  end
end