Class: GerritSeed::Seeder

Inherits:
Object
  • Object
show all
Defined in:
lib/gerrit_seed/seeder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gerrit:, git:) ⇒ Seeder

Returns a new instance of Seeder.



5
6
7
8
# File 'lib/gerrit_seed/seeder.rb', line 5

def initialize(gerrit:, git:)
  @gerrit = gerrit
  @git = git
end

Instance Attribute Details

#gerritObject (readonly)

Returns the value of attribute gerrit.



3
4
5
# File 'lib/gerrit_seed/seeder.rb', line 3

def gerrit
  @gerrit
end

#gitObject (readonly)

Returns the value of attribute git.



3
4
5
# File 'lib/gerrit_seed/seeder.rb', line 3

def git
  @git
end

Instance Method Details

#apply(directive_list) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gerrit_seed/seeder.rb', line 10

def apply(directive_list)
  directives = directive_list.reduce({}) do |acc, item|
    item.keys.each do |key|
      acc[key.to_sym] ||= []
      acc[key.to_sym] << item[key].transform_keys(&:to_sym)
    end

    acc
  end


  directives[:user].each(&gerrit.method(:create_user))
  directives[:project].each(&gerrit.method(:create_project))

  repos = directives[:project].reduce({}) do |acc, name:, **|
    acc[name.to_s] = git.clone(name: name)
    acc
  end

  directives[:change].reduce([]) do |acc, change|
    repo = repos.fetch(change[:project].to_s)

    gerrit.create_change(change, git: repo, changes: acc, users: directives[:user])

    acc.push(change)
  end
end