ghi_label_maker 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +57 -0
- data/Rakefile +2 -0
- data/bin/label_maker +5 -0
- data/label_maker.gemspec +27 -0
- data/lib/label_maker.rb +16 -0
- data/lib/label_maker/repo.rb +115 -0
- data/lib/label_maker/user.rb +64 -0
- data/lib/label_maker/version.rb +3 -0
- data/spec/label_maker_spec.rb +7 -0
- data/spec/user_spec.rb +7 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6e24e9350768817c3eec677a426641aa8d128bbf
|
4
|
+
data.tar.gz: 1fba075586256b74b1197393175b06a9560c0203
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4c55aa0f61171c27616256b5183adfb228b1c30b94793f37dcb0120739146bf88d125a00ad1bfb0b3e1c5b8d6e3cc6b6721c32b6ccefbd8e6673f3845423e797
|
7
|
+
data.tar.gz: 859dcff6a88f4fbddf149fe6234f26e02d00c0074e113e206f479dd1eea8ca7707a310a3229a312bf0cc934dab90b7d18093277dc1bfd3e01481f79bb36cc3ca
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 shaeffga
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# GHI Label Maker
|
2
|
+
|
3
|
+
Utility for copying GitHub issue labels from a source repo to target repo(s). Use `*` to copy/update labels for all authorized repos in an organization.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install ghi_label_maker
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
Start with:
|
12
|
+
|
13
|
+
$ label_maker
|
14
|
+
|
15
|
+
The first time it runs, it'll prompt you for your GitHub username and password. For convenience the gem will save your GitHub credentials to your `.netrc` file.
|
16
|
+
|
17
|
+
Welcome to LabelMaker!
|
18
|
+
Please login with your GitHub account:
|
19
|
+
GitHub Username:
|
20
|
+
$ MyUsername
|
21
|
+
Password (hidden):
|
22
|
+
$
|
23
|
+
Successful GitHub login!
|
24
|
+
|
25
|
+
After you have logged in it'll prompt you for a source repository to copy labels from:
|
26
|
+
|
27
|
+
Source repo (ex. username/source-repo):
|
28
|
+
$ username/my-test-repo
|
29
|
+
|
30
|
+
After providing the source repository you will need to provide a target repository to copy labels to. When entering the repository name, you can enter any repository that your GitHub account has access to. This includes your public, private & organinzation repository. To copy labels to all repositories that you have access to, use the `*` symbol as shown below.
|
31
|
+
|
32
|
+
Target repo (ex. username/target-repo or organization/*):
|
33
|
+
$ username/*
|
34
|
+
|
35
|
+
|
36
|
+
Then you will be given the option to delete all labels in the target repository that aren't assigned to an issue:
|
37
|
+
|
38
|
+
Delete labels in target repo with 0 issues? (y/n)
|
39
|
+
$ y
|
40
|
+
|
41
|
+
Deleting labels from username/target-repo that are not associated with an issue!
|
42
|
+
Ignoring chore
|
43
|
+
Deleting flagged
|
44
|
+
|
45
|
+
Copying labels to username/target-repo!
|
46
|
+
Added - color: d4c5f9 with name: bug
|
47
|
+
Updated - color: c4c4c4 with name: enhancement
|
48
|
+
Already Exsists - color: 3f3f3f with name: feature
|
49
|
+
Labels from username/source-repo have been copied to username/target-repo
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
1. Fork it ( https://github.com/topgunhq/label-maker/fork )
|
54
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
55
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
56
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
57
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/label_maker
ADDED
data/label_maker.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'label_maker/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ghi_label_maker"
|
8
|
+
spec.version = LabelMaker::VERSION
|
9
|
+
spec.authors = ["Top Gun Performance Solutions"]
|
10
|
+
spec.email = ["dev.rubygems@topgunhq.com"]
|
11
|
+
spec.summary = %q{Copy github issue labels from one repo to another.}
|
12
|
+
spec.description = %q{Utility for copying github issue labels from a source repo to target repo(s). Use "*" to copy/update labels for all authorized repos in an organization.}
|
13
|
+
spec.homepage = "https://github.com/topgunhq/label-maker"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = 'label_maker'
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "octokit", "~> 3.0"
|
22
|
+
spec.add_dependency "netrc", "~> 0.7"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.3"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.1"
|
27
|
+
end
|
data/lib/label_maker.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "label_maker/version"
|
2
|
+
require "label_maker/repo"
|
3
|
+
require "label_maker/user"
|
4
|
+
require 'octokit'
|
5
|
+
|
6
|
+
module LabelMaker
|
7
|
+
class CLI
|
8
|
+
def self.start
|
9
|
+
puts "Welcome to LabelMaker!"
|
10
|
+
LabelMaker::User.new.authenticate
|
11
|
+
puts "Successful GitHub login!"
|
12
|
+
LabelMaker::Repo.new.repo_questions
|
13
|
+
return
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
|
2
|
+
module LabelMaker
|
3
|
+
class Repo
|
4
|
+
def initialize
|
5
|
+
@client = LabelMaker::User.new.github_client
|
6
|
+
end
|
7
|
+
|
8
|
+
def repo_questions
|
9
|
+
puts "Source repo (ex. username/source-repo):"
|
10
|
+
@source_repo = gets.chomp
|
11
|
+
|
12
|
+
puts "Target repo (ex. username/target-repo or organization/*):"
|
13
|
+
@target_repo = gets.chomp
|
14
|
+
|
15
|
+
puts "Delete labels in target repo with 0 issues? (y/n)"
|
16
|
+
@clear_labels = gets.chomp
|
17
|
+
|
18
|
+
@source_labels = @client.labels(@source_repo)
|
19
|
+
@source_labels = Hash[@source_labels.map {|l| [l.name, l.color]}]
|
20
|
+
|
21
|
+
@target_repo.include?("*") ? copy_to_all_repos() : add_source_labels()
|
22
|
+
end
|
23
|
+
|
24
|
+
def copy_to_all_repos
|
25
|
+
puts "This may take awhile!"
|
26
|
+
if @target_repo.start_with?(@client.login)
|
27
|
+
@client.repositories.each do |repo|
|
28
|
+
@repo_target = repo.full_name
|
29
|
+
|
30
|
+
if @clear_labels == "y"
|
31
|
+
clear_all_labels
|
32
|
+
else
|
33
|
+
add_labels_to_target
|
34
|
+
end
|
35
|
+
puts " Labels from #{@source_repo} have been copied to #{@repo_target}"
|
36
|
+
puts ""
|
37
|
+
end
|
38
|
+
else
|
39
|
+
org = @target_repo.chomp("/*")
|
40
|
+
|
41
|
+
@client.org_repos(org).each do |repo|
|
42
|
+
@repo_target = repo.full_name
|
43
|
+
|
44
|
+
if @clear_labels == "y"
|
45
|
+
clear_all_labels
|
46
|
+
else
|
47
|
+
add_labels_to_target
|
48
|
+
end
|
49
|
+
puts " Labels from #{@source_repo} have been copied to #{@repo_target}"
|
50
|
+
puts ""
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def add_source_labels
|
56
|
+
@repo_target = @target_repo
|
57
|
+
|
58
|
+
|
59
|
+
if @clear_labels == "y"
|
60
|
+
clear_all_labels
|
61
|
+
else
|
62
|
+
add_labels_to_target
|
63
|
+
end
|
64
|
+
puts " Labels from #{@source_repo} have been copied to #{@repo_target}"
|
65
|
+
puts ""
|
66
|
+
end
|
67
|
+
|
68
|
+
def clear_all_labels
|
69
|
+
t_labels_in_repo = @client.labels(@repo_target)
|
70
|
+
t_labels_in_repo = Hash[t_labels_in_repo.map {|l| [l.name, l.color]}]
|
71
|
+
target_issue_labels = []
|
72
|
+
puts "Deleting labels from #{@repo_target} that are not associated with an issue!"
|
73
|
+
issues_with_target_repo = @client.list_issues(@repo_target, options= {state: "all"})
|
74
|
+
issues_with_target_repo.each do |issue|
|
75
|
+
if issue.labels != []
|
76
|
+
issue.labels.each do |label|
|
77
|
+
target_issue_labels << label.name
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
target_issue_labels = target_issue_labels.uniq
|
82
|
+
t_labels_in_repo.each_key do |t_label|
|
83
|
+
if target_issue_labels.include?(t_label) != true
|
84
|
+
@client.delete_label!(@repo_target, t_label)
|
85
|
+
puts " Deleting #{t_label}"
|
86
|
+
else
|
87
|
+
puts " Ignoring #{t_label}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
puts ""
|
91
|
+
|
92
|
+
add_labels_to_target
|
93
|
+
end
|
94
|
+
|
95
|
+
def add_labels_to_target
|
96
|
+
@target_labels = @client.labels(@repo_target)
|
97
|
+
@target_labels = Hash[@target_labels.map {|l| [l.name, l.color]}]
|
98
|
+
puts "Copying #{@source_repo}"
|
99
|
+
|
100
|
+
@source_labels.each do |s_key, s_value|
|
101
|
+
if @target_labels.include?(s_key)
|
102
|
+
if @target_labels[s_key] == s_value
|
103
|
+
puts " Already Exsists - color: #{s_value} with name: #{s_key}"
|
104
|
+
else
|
105
|
+
puts " Updating - color: #{s_value} with name: #{s_key}"
|
106
|
+
@client.update_label(@repo_target, s_key, {color: "#{s_value}"})
|
107
|
+
end
|
108
|
+
else
|
109
|
+
puts " Adding - color: #{s_value} with name: #{s_key}"
|
110
|
+
@client.add_label(@repo_target, s_key, s_value)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'netrc'
|
2
|
+
require 'io/console'
|
3
|
+
|
4
|
+
module LabelMaker
|
5
|
+
class User
|
6
|
+
attr_reader :github_client
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
# Uses credentials in .netrc to authenticate
|
10
|
+
@github_client = Octokit::Client.new(netrc: true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def authenticate(logged_in = false)
|
14
|
+
if logged_in?
|
15
|
+
return true
|
16
|
+
else
|
17
|
+
puts "Authentication failed or you are a first time user!"
|
18
|
+
get_credentials
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_credentials
|
23
|
+
puts "Please login with your GitHub account:"
|
24
|
+
puts "GitHub Username:"
|
25
|
+
username = gets.chomp
|
26
|
+
puts "Password (hidden):"
|
27
|
+
password = STDIN.noecho(&:gets).chomp
|
28
|
+
|
29
|
+
client = Octokit::Client.new(login: username, password: password)
|
30
|
+
puts client.inspect
|
31
|
+
|
32
|
+
puts 'Do you use Two Factor Auth? (y/n)'
|
33
|
+
agree = gets.chomp
|
34
|
+
if agree == 'y'
|
35
|
+
puts 'Enter your 2FA token:'
|
36
|
+
two_factor = gets.chomp
|
37
|
+
oauth = oauth_authorization(client, headers: {"X-GitHub-OTP" => two_factor})
|
38
|
+
else
|
39
|
+
oauth = oauth_authorization(client)
|
40
|
+
end
|
41
|
+
|
42
|
+
save_to_netrc(username, oauth.token)
|
43
|
+
authenticate(true)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def oauth_authorization(client, headers = {})
|
49
|
+
client.create_authorization(scopes: ['user','repo'], note: "LabelMaker gem 0.0.1- #{Time.now.strftime("%Y-%m-%d")}!", headers: headers)
|
50
|
+
end
|
51
|
+
|
52
|
+
def save_to_netrc(user, token)
|
53
|
+
netrc = Netrc.read
|
54
|
+
netrc.new_item_prefix = "# This entry was added by the LabelMaker gem\n"
|
55
|
+
netrc['api.github.com'] = user, token
|
56
|
+
netrc.save
|
57
|
+
end
|
58
|
+
|
59
|
+
def logged_in?
|
60
|
+
netrc = Netrc.read
|
61
|
+
netrc['api.github.com'] && Octokit::Client.new(netrc: true).login
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/spec/user_spec.rb
ADDED
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ghi_label_maker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Top Gun Performance Solutions
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: octokit
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: netrc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.7'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.1'
|
83
|
+
description: Utility for copying github issue labels from a source repo to target
|
84
|
+
repo(s). Use "*" to copy/update labels for all authorized repos in an organization.
|
85
|
+
email:
|
86
|
+
- dev.rubygems@topgunhq.com
|
87
|
+
executables:
|
88
|
+
- label_maker
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/label_maker
|
98
|
+
- label_maker.gemspec
|
99
|
+
- lib/label_maker.rb
|
100
|
+
- lib/label_maker/repo.rb
|
101
|
+
- lib/label_maker/user.rb
|
102
|
+
- lib/label_maker/version.rb
|
103
|
+
- spec/label_maker_spec.rb
|
104
|
+
- spec/user_spec.rb
|
105
|
+
homepage: https://github.com/topgunhq/label-maker
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.2.2
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Copy github issue labels from one repo to another.
|
129
|
+
test_files:
|
130
|
+
- spec/label_maker_spec.rb
|
131
|
+
- spec/user_spec.rb
|