-
-
Save vshjxyz/71ffc99f9c99a5ba32e9206e317e9659 to your computer and use it in GitHub Desktop.
Batch update labels in Github repos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem "octokit", "~> 4.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'octokit' | |
require 'json' | |
Octokit.auto_paginate = true | |
client = Octokit::Client.new(:access_token => "MY_TOKEN") | |
repos = [ | |
'silverstripe/silverstripe-versioned', | |
] | |
default_labels = { | |
"affects/v3" => "d4c5f9", | |
"affects/v4" => "5319e7", | |
} | |
rename_labels = { | |
"bug" => "type/bug", | |
} | |
remove_labels = [ | |
'wontfix', | |
'question', | |
] | |
repos.each do | repo | | |
puts '# Repo %s' % repo | |
repo_labels = client.labels(repo) | |
rename_labels.each do |from_name, to_name| | |
existing_label = repo_labels.select{|k,v| k.name == from_name}.first | |
if existing_label | |
puts 'Renaming label from %s to %s' % [from_name, to_name] | |
client.update_label(repo, from_name, {:name => to_name}) | |
end | |
end | |
# Fetch labels again because they might've been renamed | |
repo_labels = client.labels(repo) | |
default_labels.each do |name, color| | |
existing_label = repo_labels.select{|k,v| k.name == name}.first | |
if existing_label | |
puts 'Updating label %s' % (name) | |
client.update_label(repo, name, {:color => color}) | |
else | |
puts 'Adding label %s' % (name) | |
client.add_label(repo, name, color) | |
end | |
end | |
remove_labels.each do |name| | |
puts 'Removing label %s' % (name) | |
client.delete_label!(repo, name) | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment