Class: Migrator::Engine

Inherits:
Object
  • Object
show all
Includes:
MigrateFromDb, MigrateFromFile, MigrateToFile
Defined in:
lib/tractive/migrator/engine.rb,
lib/tractive/migrator/engine/migrate_from_db.rb,
lib/tractive/migrator/engine/migrate_to_file.rb,
lib/tractive/migrator/engine/migrate_from_file.rb

Defined Under Namespace

Modules: MigrateFromDb, MigrateFromFile, MigrateToFile

Instance Method Summary collapse

Methods included from MigrateFromFile

#migrate_from_file

Methods included from MigrateToFile

#migrate_to_file

Methods included from MigrateFromDb

#migrate_from_db

Constructor Details

#initialize(args) ⇒ Engine

Returns a new instance of Engine.



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
# File 'lib/tractive/migrator/engine.rb', line 17

def initialize(args)
  # def initialize(trac, github, users, labels, revmap, attachurl, singlepost, safetychecks, mockdeleted = false)
  @config = args

  db                = args[:db]
  github            = args[:cfg]["github"]
  safetychecks      = !(args[:opts][:fast])
  mockdeleted       = args[:opts][:mockdeleted]
  start_ticket      = args[:opts][:start]
  filter_closed     = args[:opts][:openedonly]
  input_file_name   = args[:opts][:importfromfile]

  @filter_applied   = args[:opts][:filter]
  @filter_options   = { column_name: args[:opts][:columnname], operator: args[:opts][:operator], column_value: args[:opts][:columnvalue], include_null: args[:opts][:includenull] }

  @trac  = Tractive::Trac.new(db)
  @repo  = github["repo"]
  @client = GithubApi::Client.new(access_token: github["token"])
  @graph_ql_client = GithubApi::GraphQlClient.new

  if input_file_name
    @from_file = input_file_name
    file = File.open(@from_file, "r")
    @input_file = JSON.parse(file.read)
    file.close
  end

  @ticket_to_issue   = {}
  @mockdeleted       = mockdeleted || @filter_applied

  $logger.debug("Get highest in #{@repo}")
  issues = @client.issues(@repo, { filter: "all",
                                   state: "all",
                                   sort: "created",
                                   direction: "desc" })

  @last_created_issue = issues.empty? ? 0 : issues[0]["number"].to_i

  $logger.info("created issue on GitHub is '#{@last_created_issue}' #{issues.count}")

  dry_run_output_file = args[:cfg][:dry_run_output_file] || "#{Dir.pwd}/dryrun_out.json"

  @dry_run          = args[:opts][:dryrun]
  @output_file      = File.new(dry_run_output_file, "w+")
  @delimiter        = "{"
  @revmap           = load_revmap_file(args[:opts][:revmapfile] || args[:cfg]["revmap_path"])
  @safetychecks     = safetychecks
  @start_ticket     = (start_ticket || (@last_created_issue + 1)).to_i
  @filter_closed    = filter_closed
  @delete_mocked_tickets = args[:cfg]["ticket"]["delete_mocked"] if args[:cfg]["ticket"]
end

Instance Method Details

#migrateObject



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/tractive/migrator/engine.rb', line 69

def migrate
  if @dry_run
    migrate_to_file
  elsif @from_file
    migrate_from_file
  else
    migrate_from_db
  end
rescue StandardError => e
  $logger.error e.message
  exit 1
end