Class: MultiRepo::Helpers::RenameLabels

Inherits:
Object
  • Object
show all
Defined in:
lib/multi_repo/helpers/rename_labels.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo_name, rename_hash, dry_run: false) ⇒ RenameLabels

Returns a new instance of RenameLabels.



5
6
7
8
9
# File 'lib/multi_repo/helpers/rename_labels.rb', line 5

def initialize(repo_name, rename_hash, dry_run: false, **)
  @repo_name   = repo_name
  @rename_hash = rename_hash
  @github      = MultiRepo::Service::Github.new(dry_run: dry_run)
end

Instance Attribute Details

#githubObject (readonly)

Returns the value of attribute github.



3
4
5
# File 'lib/multi_repo/helpers/rename_labels.rb', line 3

def github
  @github
end

#rename_hashObject (readonly)

Returns the value of attribute rename_hash.



3
4
5
# File 'lib/multi_repo/helpers/rename_labels.rb', line 3

def rename_hash
  @rename_hash
end

#repo_nameObject (readonly)

Returns the value of attribute repo_name.



3
4
5
# File 'lib/multi_repo/helpers/rename_labels.rb', line 3

def repo_name
  @repo_name
end

Instance Method Details

#runObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/multi_repo/helpers/rename_labels.rb', line 11

def run
  rename_hash.each do |old_name, new_name|
    github_label = existing_labels.detect { |l| l.name == old_name }

    if github_label
      puts "Renaming label #{old_name.inspect} to #{new_name.inspect}"
      github.update_label(repo_name, old_name, name: new_name)
    end
  end
end