Skip to content

Commit e03a7d4

Browse files
committed
Merge pull request #38 from DeployGate/feature/v0.0.5
ver 0.0.5
2 parents 4d2224b + fb5158a commit e03a7d4

File tree

18 files changed

+323
-39
lines changed

18 files changed

+323
-39
lines changed

deploygate.gemspec

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ dg installed! To get started fast:
1818
1919
$ dg deploy
2020
21-
Or see the docs at:
22-
23-
https://deploygate.com/docs/cli
24-
2521
POST_INSTALL_MESSAGE
2622

2723
spec.add_dependency 'json', '~> 1.8.2'
@@ -40,6 +36,7 @@ POST_INSTALL_MESSAGE
4036
spec.add_dependency 'gym', '~> 1.0.0'
4137
spec.add_dependency 'spaceship', '~> 0.12.3'
4238
spec.add_dependency 'sigh', '~> 1.1.0'
39+
spec.add_dependency 'locale'
4340

4441
spec.add_development_dependency "bundler", "~> 1.3"
4542
spec.add_development_dependency "rake"

lib/deploygate.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
require "uuid"
1313
require "gem_update_checker"
1414
require "active_support/core_ext/time"
15+
require "locale"
1516

1617
# ios build
1718
require "gym"
@@ -27,8 +28,9 @@ module DeployGate
2728
require "deploygate/api/v1/push"
2829
require "deploygate/api/v1/user"
2930
require "deploygate/command_builder"
30-
require "deploygate/commands/init"
31+
require "deploygate/commands/login"
3132
require "deploygate/commands/logout"
33+
require "deploygate/commands/config"
3234
require "deploygate/commands/deploy"
3335
require "deploygate/commands/deploy/push"
3436
require "deploygate/commands/deploy/build"

lib/deploygate/api/v1/session.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,23 @@ class Session
66

77
class << self
88

9+
# @param [String] token
10+
# @return [Hash]
11+
def show(token)
12+
res = Base.new(token).get(ENDPOINT + '/user', {})
13+
return nil if res['error']
14+
15+
res['results']
16+
end
17+
918
# @param [String] name
1019
# @param [String] token
1120
# @return [Boolean]
1221
def check(name, token)
13-
res = Base.new(token).get(ENDPOINT + '/user', {})
14-
return false if res['error']
22+
results = show(token)
23+
return false if results.nil?
1524

16-
name == res['results']['name']
25+
name == results['name']
1726
end
1827

1928
# @param [String] email

lib/deploygate/api/v1/user.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ class << self
99
# @param [String] name
1010
# @param [String] email
1111
# @param [String] password
12+
# @param [String] locale
1213
# @return [Hash]
13-
def create(name, email, password)
14-
res = Base.new().post(ENDPOINT, {:name => name, :email => email, :password => password})
14+
def create(name, email, password, locale = 'en')
15+
res = Base.new().post(ENDPOINT, {:name => name, :email => email, :password => password, :locale => locale})
1516

1617
user_create_results = {
1718
:error => res['error'],

lib/deploygate/builds/ios/analyze.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def initialize(workspaces)
2828
@scheme = project.options[:scheme]
2929
end
3030

31+
# Support Xcode7 more
3132
# @return [String]
3233
def target_bundle_identifier
3334
product_name = target_product_name

lib/deploygate/builds/ios/export.rb

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ def installed_certificate?(profile_path)
5050
certificate_str = cert.read
5151
certificate = OpenSSL::X509::Certificate.new certificate_str
5252
id = OpenSSL::Digest::SHA1.new(certificate.to_der).to_s.upcase!
53-
installed_identies.include?(id)
53+
installed_distribution_certificate_ids.include?(id)
5454
end
5555
certs.include?(true)
5656
end
5757

5858
# @return [Array]
59-
def installed_identies
60-
available = `security find-identity -v -p codesigning`
59+
def installed_distribution_certificate_ids
60+
certificates = installed_certificates()
6161
ids = []
62-
available.split("\n").each do |current|
63-
next if current.include? "REVOKED"
62+
certificates.each do |current|
63+
next unless current.match(/iPhone Distribution:/)
6464
begin
6565
(ids << current.match(/.*\) (.*) \".*/)[1])
6666
rescue
@@ -71,6 +71,43 @@ def installed_identies
7171
ids
7272
end
7373

74+
# @return [Array]
75+
def installed_distribution_conflicting_certificates
76+
certificates = installed_certificates()
77+
names = []
78+
certificates.each do |current|
79+
begin
80+
names << current.match(/(iPhone Distribution:.*)/)[1]
81+
rescue
82+
end
83+
end
84+
85+
conflicting_names = names.select{|e| names.index(e) != names.rindex(e)}.uniq
86+
conflicting_certificates = []
87+
certificates.each do |current|
88+
begin
89+
name = current.match(/(iPhone Distribution:.*)/)[1]
90+
next unless conflicting_names.include?(name)
91+
conflicting_certificates << current
92+
rescue
93+
end
94+
end
95+
96+
conflicting_certificates
97+
end
98+
99+
# @return [Array]
100+
def installed_certificates
101+
available = `security find-identity -v -p codesigning`
102+
certificates = []
103+
available.split("\n").each do |current|
104+
next if current.include? "REVOKED"
105+
certificates << current
106+
end
107+
108+
certificates
109+
end
110+
74111
# @param [Array] profile_paths
75112
# @return [String]
76113
def select_profile(profile_paths)

lib/deploygate/command_builder.rb

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ def run
1111
program :version, VERSION
1212
program :description, 'You can control to DeployGate in your terminal.'
1313

14-
command :init do |c|
15-
c.syntax = 'dg init'
16-
c.description = 'project initial command'
14+
command :login do |c|
15+
c.syntax = 'dg login'
16+
c.description = 'DeployGate login command'
1717
c.action do |args, options|
1818
begin
19-
Commands::Init.run
19+
Commands::Login.run
2020
rescue => e
21-
error_handling("Commands::Init Error: #{e.class}", create_error_issue_body(e))
21+
error_handling("Commands::Login Error: #{e.class}", create_error_issue_body(e))
2222
raise e
2323
end
2424
end
@@ -56,6 +56,22 @@ def run
5656
end
5757
end
5858

59+
command :config do |c|
60+
c.syntax = 'dg config'
61+
c.description = 'dg user login config'
62+
c.option '--json', 'output json format'
63+
c.option '--name STRING', String, 'your DeployGate user name'
64+
c.option '--token STRING', String, 'your DeployGate api token'
65+
c.action do |args, options|
66+
begin
67+
Commands::Config.run(args, options)
68+
rescue => e
69+
error_handling("Commands::Config Error: #{e.class}", create_error_issue_body(e))
70+
raise e
71+
end
72+
end
73+
end
74+
5975
run!
6076
end
6177

lib/deploygate/commands/config.rb

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
module DeployGate
2+
module Commands
3+
class Config
4+
class << self
5+
6+
# @param [Array] args
7+
# @param [Commander::Command::Options] options
8+
def run(args, options)
9+
json_format = options.json
10+
name = options.name
11+
token = options.token
12+
13+
if name.nil? || token.nil?
14+
login_user = DeployGate::Session.new().show_login_user
15+
if login_user.nil?
16+
print_not_login(json_format)
17+
else
18+
print_login_user(login_user, json_format)
19+
end
20+
else
21+
login(name, token, json_format)
22+
end
23+
end
24+
25+
# @param [String] name
26+
# @param [String] token
27+
# @param [Boolean] json_format
28+
# @return [void]
29+
def login(name, token, json_format)
30+
if API::V1::Session.check(name, token)
31+
DeployGate::Session.save(name, token)
32+
login_user = DeployGate::Session.new().show_login_user
33+
print_login_success(login_user, json_format)
34+
else
35+
print_login_failed(json_format)
36+
end
37+
end
38+
39+
# @param [Hash] login_user
40+
# @param [Boolean] json_format
41+
# @return [void]
42+
def print_login_success(login_user, json_format)
43+
message = 'Login success'
44+
data = {:message => message, :error => false}
45+
46+
unless json_format
47+
DeployGate::Message::Success.print(message)
48+
puts ''
49+
end
50+
51+
print_login_user(login_user, json_format, data)
52+
end
53+
54+
# @param [Boolean] json_format
55+
# @param [Hash] data
56+
# @return [void]
57+
def print_login_failed(json_format, data = {})
58+
message = 'Login failed'
59+
data[:error] = true
60+
data[:message] = message
61+
62+
if json_format
63+
print_json(data)
64+
else
65+
DeployGate::Message::Error.print(message)
66+
puts <<EOF
67+
68+
Please check your name and api token.
69+
EOF
70+
end
71+
end
72+
73+
# @param [Boolean] json_format
74+
# @param [Hash] data
75+
# @return [void]
76+
def print_not_login(json_format, data = {})
77+
message = 'Not user login'
78+
data[:error] = true
79+
data[:message] = message
80+
81+
if json_format
82+
print_json(data)
83+
else
84+
DeployGate::Message::Warning.print(message)
85+
puts <<EOF
86+
87+
Please login to dg command.
88+
$ dg login
89+
EOF
90+
end
91+
end
92+
93+
# @param [Hash] login_user
94+
# @param [Boolean] json_format
95+
# @param [Hash] data
96+
# @return [void]
97+
def print_login_user(login_user, json_format, data = {})
98+
data[:error] = data[:error].nil? ? false : data[:error]
99+
data[:name] = login_user['name']
100+
101+
if json_format
102+
print_json(data)
103+
else
104+
puts <<EOF
105+
User name: #{data[:name]}
106+
EOF
107+
end
108+
end
109+
110+
# @param [Hash] data
111+
# @return [void]
112+
def print_json(data)
113+
puts data.to_json
114+
end
115+
end
116+
end
117+
end
118+
end

lib/deploygate/commands/deploy.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class << self
66
# @param [Array] args
77
# @param [Commander::Command::Options] options
88
def run(args, options)
9-
Init.start_login_or_create_account() unless DeployGate::Session.new.login?
9+
Login.start_login_or_create_account() unless DeployGate::Session.new.login?
1010

1111
# push or build(android/ios)
1212
args.push(Dir.pwd) if args.empty?

lib/deploygate/commands/deploy/build.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def run(args, options)
1212
work_dir = args.first
1313

1414
if DeployGate::Build.ios?(work_dir)
15+
check_local_certificates()
1516
root_path = DeployGate::Builds::Ios.project_root_path(work_dir)
1617
workspaces = DeployGate::Builds::Ios.find_workspaces(root_path)
1718
ios(workspaces, options)
@@ -156,6 +157,38 @@ def print_no_target
156157
EOF
157158
DeployGate::Message::Warning.print(message)
158159
end
160+
161+
def check_local_certificates
162+
if DeployGate::Builds::Ios::Export.installed_distribution_certificate_ids.count == 0
163+
# not local install certificate
164+
DeployGate::Message::Error.print("Error: Not local install distribution certificate")
165+
puts <<EOF
166+
167+
Not local install iPhone Distribution certificates.
168+
Please install certificate.
169+
170+
Docs: https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/AppDistributionGuide/MaintainingCertificates/MaintainingCertificates.html
171+
172+
EOF
173+
exit
174+
end
175+
176+
conflicting_certificates = DeployGate::Builds::Ios::Export.installed_distribution_conflicting_certificates
177+
if conflicting_certificates.count > 0
178+
DeployGate::Message::Error.print("Error: Conflicting local install certificates")
179+
puts <<EOF
180+
181+
Conflicting local install certificates.
182+
Please uninstall certificates.
183+
EOF
184+
conflicting_certificates.each do |certificate|
185+
puts certificate
186+
end
187+
puts ""
188+
189+
exit
190+
end
191+
end
159192
end
160193
end
161194
end

0 commit comments

Comments
 (0)