deploygate 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzM2OGRjMTVmYWJmODU1YTc0MDI3MzZjNTIwMDMyOThhNjNmMGQ1OQ==
4
+ ZWQyZmNkNWY5MDkxMjc2YmUxOTM4MTMwZTY4MmFlMTZiNzc4MTQxNg==
5
5
  data.tar.gz: !binary |-
6
- ZWZmMTNjMzA0YmY0YmI0NjEwZjgzOWEyZjk4YmExYmZjNTg3ZjE1Mg==
6
+ MWU0NWVmZDViMTYxZWJjNjg1NTc3YTc1MWExNTM4YWMyYTE5NDgxNA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NzY5MDBhZjU4NDliNzM4NDg0Yjg4NDE0NWZhYjFiYTE0ZjIyMWZmODZjNzY2
10
- NGU2MThmNjVmNDhmMDMwMmM0NTFhY2Y4Y2RjOGI0ZjYxMTQ3MTRkODI5MmZm
11
- ZGNhNzczMmNmMjE1NTM5YzMzY2ZlY2JkZjliMmZiNDFhZGM3ZjA=
9
+ MDkxMmZiYzVkYWQ0NjhhNjM3YzNmNTAzMjExODY0NmJhZDFiNDhiNTZiZWM1
10
+ ZDZjZTZkOGRhZTgzOGUyZDMxMGQ4YTBmZDM1MTJlMTg2OGQ5OTJkNmEyMmVh
11
+ NTM5Yjg4ODU1ZDJlMzA0MWU4YThkZmYyZmY3MDA4MDFjZTJjNzA=
12
12
  data.tar.gz: !binary |-
13
- NzVkMWE5ZTdkNWI4NzQ1NTM5MDg2MjlkZmM1MGFlNTMzMzBkYjBkZjZlMzNi
14
- Yzg5NmQxOTM4MGM1ZjQ2MzA3Nzc5Nzg3YWJhNGE2M2E2MWRjNzAzM2ZiNjIy
15
- NmRjMTVlZjZhMzIyZjc5ZDI1ZWY5YzFlMWQ4YjFjODEzY2JkZTg=
13
+ MWVjOGRhNWFiNTE1ODcyNzk2MzlhMGI1OGFhYzRjNDkzMDE4MzdmODg5NjFk
14
+ NTk5Y2NiZDAzMjEyNDRhYjJlZGYxNDBjMDNhOTAyZDE4MGZkNTE2ZDIwNmJj
15
+ NzJhOTIyODZjMWVlZTEzMzdlYjI3MDQ2ZGY4NzU4MGQ3NDdhZmE=
@@ -5,6 +5,7 @@ en:
5
5
  description: 'Control DeployGate from your terminal.'
6
6
  login:
7
7
  description: 'Log in to DeployGate'
8
+ terminal: 'Login in terminal'
8
9
  error: 'Commands::Login Error: %{e}'
9
10
  deploy:
10
11
  description: 'Build and upload a new build'
@@ -30,6 +31,7 @@ en:
30
31
  token: 'DeployGate API token'
31
32
  error: 'Commands::Config Error: %{e}'
32
33
  error_handling:
34
+ message: 'Error: %{message}'
33
35
  agree: 'Do you want to report this issue on GitHub? (y/n) '
34
36
  please_open: 'Please open GitHub issue: %{url}'
35
37
  show_update_message: |
data/deploygate.gemspec CHANGED
@@ -31,6 +31,7 @@ POST_INSTALL_MESSAGE
31
31
  spec.add_dependency 'gem_update_checker', '~> 0.2.0'
32
32
  spec.add_dependency 'activesupport', '~> 4.2.4'
33
33
  spec.add_dependency 'i18n'
34
+ spec.add_dependency 'launchy'
34
35
 
35
36
  # ios build
36
37
  spec.add_dependency 'gym', '~> 1.0.0'
data/lib/deploygate.rb CHANGED
@@ -16,6 +16,8 @@ require "tempfile"
16
16
  require "open3"
17
17
  require "open-uri"
18
18
  require "rexml/document"
19
+ require "launchy"
20
+ require "webrick"
19
21
 
20
22
  require "i18n"
21
23
  I18n.load_path = Dir[File.join(File.dirname(__FILE__), '../config/locales/*.yml')]
@@ -49,6 +51,7 @@ require "deploygate/session"
49
51
  require "deploygate/deploy"
50
52
  require "deploygate/project"
51
53
  require "deploygate/user"
54
+ require "deploygate/browser_login"
52
55
  require "deploygate/xcode/member_center"
53
56
  require "deploygate/xcode/member_centers/app"
54
57
  require "deploygate/xcode/member_centers/provisioning_profile"
@@ -0,0 +1,72 @@
1
+ module DeployGate
2
+ class BrowserLogin
3
+ DEFAULT_PORT = 64126
4
+ LOGIN_URL = "#{DeployGate::API::V1::Base::BASE_URL}/cli/login"
5
+ CREDENTIAL_URL = "#{DeployGate::API::V1::Base::BASE_URL}/cli/credential"
6
+ NOTIFY_URL = "#{DeployGate::API::V1::Base::BASE_URL}/cli/notify"
7
+
8
+ # @param [Fixnum] port
9
+ def initialize(port = nil)
10
+ @port = port || DEFAULT_PORT
11
+ @login_uri = URI(LOGIN_URL)
12
+ @login_uri.query = {port: @port, client: 'dg'}.to_query
13
+
14
+ @credential_uri = URI(CREDENTIAL_URL)
15
+ @notify_uri = URI(NOTIFY_URL)
16
+ end
17
+
18
+ def start
19
+ server = WEBrick::HTTPServer.new(
20
+ :Port => @port,
21
+ :BindAddress =>"localhost",
22
+ :Logger => WEBrick::Log.new(STDOUT, 0),
23
+ :AccessLog => []
24
+ )
25
+
26
+ begin
27
+ Signal.trap("INT") { server.shutdown }
28
+
29
+ server.mount_proc '/' do |req, res|
30
+ res.status = WEBrick::HTTPStatus::RC_NO_CONTENT
31
+
32
+ cancel = req.query['cancel']
33
+ notify_key = req.query['key']
34
+
35
+ unless cancel
36
+ credential = get_credential(notify_key)
37
+ DeployGate::Session.save(credential['name'], credential['token'])
38
+ notify_finish(notify_key)
39
+
40
+ DeployGate::Commands::Login.login_success()
41
+ end
42
+
43
+ server.stop
44
+ end
45
+
46
+ Launchy.open(@login_uri.to_s)
47
+ server.start
48
+ ensure
49
+ server.shutdown
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ # @param [String] notify_key
56
+ # @return [Hash]
57
+ def get_credential(notify_key)
58
+ res = HTTPClient.new(:agent_name => "dg/#{DeployGate::VERSION}").get(@credential_uri.to_s, {key: notify_key})
59
+ JSON.parse(res.body)
60
+ end
61
+
62
+ # @param [String] notify_key
63
+ def notify_finish(notify_key)
64
+ notify_post(notify_key, 'credential_saved')
65
+ notify_post(notify_key, 'finished')
66
+ end
67
+
68
+ def notify_post(notify_key, action)
69
+ HTTPClient.new(:agent_name => "dg/#{DeployGate::VERSION}").post(@notify_uri.to_s, {key: notify_key, command_action: action})
70
+ end
71
+ end
72
+ end
@@ -3,6 +3,12 @@ module DeployGate
3
3
  include Commander::Methods
4
4
  attr_reader :arguments
5
5
 
6
+ LOGIN = 'login'
7
+ LOGOUT = 'logout'
8
+ DEPLOY = 'deploy'
9
+ ADD_DEVICES = 'add-devices'
10
+ CONFIG = 'config'
11
+
6
12
  def run
7
13
  Signal.trap(:INT){
8
14
  puts ''
@@ -16,20 +22,22 @@ module DeployGate
16
22
  program :version, VERSION
17
23
  program :description, I18n.t('command_builder.description')
18
24
 
19
- command :login do |c|
25
+ command LOGIN do |c|
20
26
  c.syntax = 'dg login'
21
27
  c.description = I18n.t('command_builder.login.description')
28
+ c.option '--terminal', I18n.t('command_builder.login.terminal')
22
29
  c.action do |args, options|
30
+ options.default :terminal => false
23
31
  begin
24
- Commands::Login.run
32
+ Commands::Login.run(args, options)
25
33
  rescue => e
26
- error_handling(I18n.t('command_builder.login.error', e: e.class), create_error_issue_body(e))
34
+ error_handling(LOGIN, e)
27
35
  raise e
28
36
  end
29
37
  end
30
38
  end
31
39
 
32
- command :deploy do |c|
40
+ command DEPLOY do |c|
33
41
  c.syntax = 'dg deploy /path/to/app'
34
42
  c.description = I18n.t('command_builder.deploy.description')
35
43
  c.option '--message STRING', String, I18n.t('command_builder.deploy.message')
@@ -42,14 +50,14 @@ module DeployGate
42
50
  begin
43
51
  Commands::Deploy.run(args, options)
44
52
  rescue => e
45
- error_handling(I18n.t('command_builder.deploy.error', e: e.class), create_error_issue_body(e))
53
+ error_handling(DEPLOY, e)
46
54
  raise e
47
55
  end
48
56
  end
49
57
  end
50
58
  alias_command :'push', :deploy
51
59
 
52
- command 'add-devices' do |c|
60
+ command ADD_DEVICES do |c|
53
61
  c.syntax = 'dg add-devices'
54
62
  c.description = I18n.t('command_builder.add_devices.description')
55
63
  c.option '--user STRING', String, I18n.t('command_builder.add_devices.user')
@@ -60,26 +68,26 @@ module DeployGate
60
68
  begin
61
69
  Commands::AddDevices.run(args, options)
62
70
  rescue => e
63
- error_handling(I18n.t('command_builder.add_devices.error', e: e.class), create_error_issue_body(e))
71
+ error_handling(ADD_DEVICES, e)
64
72
  raise e
65
73
  end
66
74
  end
67
75
  end
68
76
 
69
- command :logout do |c|
77
+ command LOGOUT do |c|
70
78
  c.syntax = 'dg logout'
71
79
  c.description = I18n.t('command_builder.logout.description')
72
80
  c.action do |args, options|
73
81
  begin
74
82
  Commands::Logout.run
75
83
  rescue => e
76
- error_handling(I18n.t('command_builder.logout.error', e: e.class), create_error_issue_body(e))
84
+ error_handling(LOGOUT, e)
77
85
  raise e
78
86
  end
79
87
  end
80
88
  end
81
89
 
82
- command :config do |c|
90
+ command CONFIG do |c|
83
91
  c.syntax = 'dg config'
84
92
  c.description = I18n.t('command_builder.config.description')
85
93
  c.option '--json', I18n.t('command_builder.config.json')
@@ -89,7 +97,7 @@ module DeployGate
89
97
  begin
90
98
  Commands::Config.run(args, options)
91
99
  rescue => e
92
- error_handling(I18n.t('command_builder.config.error', e: e.class), create_error_issue_body(e))
100
+ error_handling(CONFIG, e)
93
101
  raise e
94
102
  end
95
103
  end
@@ -116,18 +124,38 @@ deploygate-cli ver #{DeployGate::VERSION}
116
124
  EOF
117
125
  end
118
126
 
119
- # @param [String] title
120
- # @param [String] body
121
- # @param [Array] labels
122
- def error_handling(title, body, labels = [])
127
+ # @param [Symbol] command
128
+ # @param [Exception] error
129
+ # @return [String]
130
+ def create_issue_url(command, error)
131
+ title = case command
132
+ when LOGIN
133
+ I18n.t('command_builder.login.error', e: error.class)
134
+ when LOGOUT
135
+ I18n.t('command_builder.logout.error', e: error.class)
136
+ when DEPLOY
137
+ I18n.t('command_builder.deploy.error', e: error.class)
138
+ when ADD_DEVICES
139
+ I18n.t('command_builder.add_devices.error', e: error.class)
140
+ when CONFIG
141
+ I18n.t('command_builder.config.error', e: error.class)
142
+ end
143
+
123
144
  options = {
124
145
  :title => title,
125
- :body => body,
126
- :labels => labels
146
+ :body => create_error_issue_body(error),
127
147
  }
128
- url = GithubIssueRequest::Url.new(options).to_s
148
+ GithubIssueRequest::Url.new(options).to_s
149
+ end
150
+
151
+ # @param [Symbol] command
152
+ # @param [Exception] error
153
+ def error_handling(command, error)
154
+ STDERR.puts HighLine.color(I18n.t('command_builder.error_handling.message', message: error.message), HighLine::RED)
155
+
129
156
  puts ''
130
157
  if HighLine.agree(I18n.t('command_builder.error_handling.agree')) {|q| q.default = "n"}
158
+ url = create_issue_url(command, error)
131
159
  puts I18n.t('command_builder.error_handling.please_open', url: url)
132
160
  system('open', url) if Commands::Deploy::Push.openable?
133
161
  end
@@ -4,14 +4,23 @@ module DeployGate
4
4
  class << self
5
5
 
6
6
  # @return [void]
7
- def run
8
- start_login_or_create_account()
7
+ def run(args, options)
8
+ welcome()
9
+
10
+ if options.terminal
11
+ start_login_or_create_account()
12
+ else
13
+ DeployGate::BrowserLogin.new().start()
14
+ end
9
15
  end
10
16
 
11
- # @return [void]
12
- def start_login_or_create_account
17
+ def welcome
13
18
  puts I18n.t('commands.login.start_login_or_create_account.welcome')
14
19
  print_deploygate_aa()
20
+ end
21
+
22
+ # @return [void]
23
+ def start_login_or_create_account
15
24
  puts ''
16
25
  email = ask(I18n.t('commands.login.start_login_or_create_account.email'))
17
26
 
@@ -39,7 +48,10 @@ module DeployGate
39
48
  raise e
40
49
  end
41
50
 
42
- # login success
51
+ login_success()
52
+ end
53
+
54
+ def login_success
43
55
  session = Session.new
44
56
  puts HighLine.color(I18n.t('commands.login.start.success', name: session.name), HighLine::GREEN)
45
57
  end
@@ -1,3 +1,3 @@
1
1
  module DeployGate
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deploygate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - deploygate
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-21 00:00:00.000000000 Z
11
+ date: 2016-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - ! '>='
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: launchy
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ! '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: gym
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -318,6 +332,7 @@ files:
318
332
  - lib/deploygate/api/v1/session.rb
319
333
  - lib/deploygate/api/v1/user.rb
320
334
  - lib/deploygate/api/v1/users/app.rb
335
+ - lib/deploygate/browser_login.rb
321
336
  - lib/deploygate/command_builder.rb
322
337
  - lib/deploygate/commands/add_devices.rb
323
338
  - lib/deploygate/commands/config.rb