Skip to content

Instantly share code, notes, and snippets.

@vshjxyz
Forked from chillu/Gemfile
Last active October 25, 2017 13:35
Show Gist options
  • Save vshjxyz/71ffc99f9c99a5ba32e9206e317e9659 to your computer and use it in GitHub Desktop.
Save vshjxyz/71ffc99f9c99a5ba32e9206e317e9659 to your computer and use it in GitHub Desktop.
Batch update labels in Github repos
gem "octokit", "~> 4.0"
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