travis_migrate_to_apps 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/travis_migrate_to_apps +1 -1
- data/lib/colors.rb +15 -0
- data/lib/travis_migrate_to_apps/version.rb +1 -1
- data/lib/travis_migrate_to_apps.rb +21 -9
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5915f80cf95a4eb33edc8b258c17245bca019ea9
|
4
|
+
data.tar.gz: 68d1871de7bc24f9081275e54d88de2c711a55ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ceba64a581e8dec4bc5082d89fab54dba608a63e6aa067515711776cd6d6ecdcbc81ac7fadc4ea0e32f8e97fa8415b17ca19aa59ebe098c7759d0e5f36e20561
|
7
|
+
data.tar.gz: 107cbdcf44b532e013bd5e9088cb9c00027e00862def5f1e22bd6540a9babb71227b5411a7106e5ee42cac6f528e9aeaaa93ac226323d6e561e85f248a39e258
|
data/bin/travis_migrate_to_apps
CHANGED
data/lib/colors.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Colors
|
2
|
+
COLORS = {
|
3
|
+
red: "\e[31m",
|
4
|
+
green: "\e[32m",
|
5
|
+
yellow: "\e[33m",
|
6
|
+
blue: "\e[34m",
|
7
|
+
gray: "\e[37m",
|
8
|
+
reset: "\e[0m"
|
9
|
+
}
|
10
|
+
|
11
|
+
def colored(color, str)
|
12
|
+
return str if color == :none
|
13
|
+
[COLORS[color], str, COLORS[:reset]].join
|
14
|
+
end
|
15
|
+
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'net/https'
|
2
2
|
require 'json'
|
3
|
+
require 'colors'
|
3
4
|
|
4
5
|
class TravisMigrateToApps < Struct.new(:owner_name, :travis_access_token, :github_access_token)
|
6
|
+
include Colors
|
7
|
+
|
5
8
|
USAGE = 'Usage: travis_migrate_to_apps [owner_name] [travis_access_token] [github_access_token]'
|
6
9
|
|
7
10
|
MSGS = {
|
@@ -43,15 +46,15 @@ class TravisMigrateToApps < Struct.new(:owner_name, :travis_access_token, :githu
|
|
43
46
|
def initialize(*)
|
44
47
|
super
|
45
48
|
to_h.keys.each do |key|
|
46
|
-
|
49
|
+
missing_arg(key) unless send(key)
|
47
50
|
end
|
48
51
|
end
|
49
52
|
|
50
53
|
def run
|
51
|
-
msg :start, owner_name
|
54
|
+
msg :start, owner_name, color: :yellow
|
52
55
|
validate
|
53
56
|
migrate_repos
|
54
|
-
msg :done
|
57
|
+
msg :done, color: :green
|
55
58
|
end
|
56
59
|
|
57
60
|
private
|
@@ -75,7 +78,7 @@ class TravisMigrateToApps < Struct.new(:owner_name, :travis_access_token, :githu
|
|
75
78
|
end
|
76
79
|
|
77
80
|
def migrate_repo(repo)
|
78
|
-
uri = uri(:github, :installation_repos,
|
81
|
+
uri = uri(:github, :installation_repos, installation['github_id'], repo['github_id'])
|
79
82
|
request(:put, uri, headers(:github))
|
80
83
|
msg :migrated_repo, repo['name']
|
81
84
|
end
|
@@ -106,19 +109,28 @@ class TravisMigrateToApps < Struct.new(:owner_name, :travis_access_token, :githu
|
|
106
109
|
|
107
110
|
def request(method, uri, headers)
|
108
111
|
req = Net::HTTP.const_get(method.to_s.capitalize).new(uri)
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
+
headers.each { |key, value| req[key] = value }
|
113
|
+
http = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true)
|
114
|
+
res = http.request(req)
|
112
115
|
error :request_failed, uri, res.code, res.body unless res.is_a?(Net::HTTPSuccess)
|
113
116
|
JSON.parse(res.body) if method == :get
|
114
117
|
end
|
115
118
|
|
116
119
|
def error(key, *args)
|
117
|
-
abort MSGS[key] % args
|
120
|
+
abort colored(:red, MSGS[key] % args)
|
118
121
|
end
|
119
122
|
|
120
123
|
def msg(key, *args)
|
121
|
-
|
124
|
+
opts = args.last.is_a?(Hash) ? args.pop : {}
|
125
|
+
msg = MSGS[key] % args
|
126
|
+
msg = colored(opts[:color], msg) if opts[:color]
|
127
|
+
puts msg
|
128
|
+
end
|
129
|
+
|
130
|
+
def missing_arg(key)
|
131
|
+
puts colored(:red, "No #{key} given")
|
132
|
+
puts USAGE
|
133
|
+
abort
|
122
134
|
end
|
123
135
|
|
124
136
|
def only(hash, *keys)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: travis_migrate_to_apps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis CI
|
@@ -22,6 +22,7 @@ files:
|
|
22
22
|
- Gemfile.lock
|
23
23
|
- LICENSE.md
|
24
24
|
- bin/travis_migrate_to_apps
|
25
|
+
- lib/colors.rb
|
25
26
|
- lib/travis_migrate_to_apps.rb
|
26
27
|
- lib/travis_migrate_to_apps/version.rb
|
27
28
|
homepage: https://github.com/travis-ci/travis_migrate_to_apps
|