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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4435125428be5a367f719c8c7d36afe2dd741c3
4
- data.tar.gz: 90f9f62ae359c3b383243bff9f0fa5febf72c6e5
3
+ metadata.gz: 5915f80cf95a4eb33edc8b258c17245bca019ea9
4
+ data.tar.gz: 68d1871de7bc24f9081275e54d88de2c711a55ef
5
5
  SHA512:
6
- metadata.gz: fc00edd3722a9ae71213f88b15e41ec309844747c507344b34d95126e4a7b1f23ab1575a47386ba729cc6e7953f406665184f1679576fc900ab1ef6e0795b58e
7
- data.tar.gz: 521cf31faaed248310ded7e6e88326b0fde025a640c721e61b7fc2efde665f099c3c6cae1e192bb8573f6e55566b13033c2ca74de79ff9848c17fa9a0c42f2ec
6
+ metadata.gz: ceba64a581e8dec4bc5082d89fab54dba608a63e6aa067515711776cd6d6ecdcbc81ac7fadc4ea0e32f8e97fa8415b17ca19aa59ebe098c7759d0e5f36e20561
7
+ data.tar.gz: 107cbdcf44b532e013bd5e9088cb9c00027e00862def5f1e22bd6540a9babb71227b5411a7106e5ee42cac6f528e9aeaaa93ac226323d6e561e85f248a39e258
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'travis_migrate_to_apps'
4
4
 
5
- TravisMigrateToApps.new(*ARGV)
5
+ TravisMigrateToApps.new(*ARGV).run
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,3 +1,3 @@
1
1
  module TravisMigrateToApps
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  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
- abort "#{USAGE}\nNo #{key} given" unless send(key)
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, repo['github_id'], installation['github_id'])
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
- res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
110
- http.request(req)
111
- end
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
- puts MSGS[key] % args
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.2
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