Last active
November 12, 2022 23:24
-
-
Save chillu/45f9e9b777016f6257a64026aa84e0b3 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-siteconfig', | |
'silverstripe/silverstripe-admin', | |
'silverstripe/silverstripe-asset-admin', | |
'silverstripe/silverstripe-cms', | |
'silverstripe/silverstripe-installer', | |
'silverstripe/silverstripe-reports', | |
'silverstripe/silverstripe-subsites', | |
'silverstripe/silverstripe-upgrader', | |
'silverstripe/silverstripe-versioned', | |
] | |
default_labels = { | |
"affects/v3" => "d4c5f9", | |
"affects/v4" => "5319e7", | |
"change/major" => "e99695", | |
"change/minor" => "f9d0c4", | |
"change/patch" => "fef2c0", | |
"effort/easy" => "c2e0c6", | |
"effort/hard" => "f9d0c4", | |
"effort/medium" => "fef2c0", | |
# "Epic =>" "3E4B9E", | |
"feedback-required/author" => "DDDDDD", | |
"feedback-required/core-team" => "DDDDDD", | |
"impact/critical" => "e11d21", | |
"impact/high" => "eb6420", | |
"impact/low" => "fef2c0", | |
"impact/medium" => "f7c6c7", | |
"rfc/accepted" => "DDDDDD", | |
"rfc/draft" => "DDDDDD", | |
"type/bug" => "d93f0b", | |
"type/docs" => "02d7e1", | |
"type/enhancement" => "0e8a16", | |
"type/frontend" => "c5def5", | |
"type/userhelp" => "c5def5", | |
"type/UX" => "006b75", | |
} | |
rename_labels = { | |
"bug" => "type/bug", | |
"critical" => "impact/critical", | |
"enhancement" => "type/enhancement", | |
} | |
remove_labels = [ | |
'wontfix', | |
'question', | |
'invalid', | |
'help wanted', | |
'duplicate', | |
'in progress' | |
] | |
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 | |
Apparently the Gemfile should indicate a source above dependancies now:
source 'https://rubygems.org'
gem "octokit", "~> 4.0"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A new label to remove has popped up:
good first issue
(cc @chillu)