Skip to content

Commit

Permalink
Merge pull request #18 from DeployGate/feature/v0.0.4
Browse files Browse the repository at this point in the history
v0.0.4
  • Loading branch information
henteko committed Nov 5, 2015
2 parents ebe4695 + 5838146 commit 4d2224b
Show file tree
Hide file tree
Showing 19 changed files with 378 additions and 58 deletions.
2 changes: 2 additions & 0 deletions deploygate.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ POST_INSTALL_MESSAGE
spec.add_dependency 'github_issue_request', '~> 0.0.2'
spec.add_dependency 'highline', '~> 1.7.8'
spec.add_dependency 'uuid', '~> 2.3.8'
spec.add_dependency 'gem_update_checker', '~> 0.2.0'
spec.add_dependency 'activesupport', '~> 4.2.4'

# ios build
spec.add_dependency 'gym', '~> 1.0.0'
Expand Down
9 changes: 8 additions & 1 deletion lib/deploygate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
require "github_issue_request"
require "highline"
require "uuid"
require "gem_update_checker"
require "active_support/core_ext/time"

# ios build
require "gym"
Expand All @@ -23,20 +25,25 @@ module DeployGate
require "deploygate/api/v1/base"
require "deploygate/api/v1/session"
require "deploygate/api/v1/push"
require "deploygate/api/v1/user"
require "deploygate/command_builder"
require "deploygate/commands/init"
require "deploygate/commands/logout"
require "deploygate/commands/deploy"
require "deploygate/commands/deploy/push"
require "deploygate/commands/deploy/build"
require "deploygate/config"
require "deploygate/config/base"
require "deploygate/config/credential"
require "deploygate/config/cache_version"
require "deploygate/session"
require "deploygate/deploy"
require "deploygate/build"
require "deploygate/user"
require "deploygate/builds/ios"
require "deploygate/builds/ios/export"
require "deploygate/builds/ios/analyze"
require "deploygate/builds/ios/set_profile"
require "deploygate/message/error"
require "deploygate/message/success"
require "deploygate/message/warning"
require "deploygate/version"
43 changes: 43 additions & 0 deletions lib/deploygate/api/v1/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module DeployGate
module API
module V1
class User

ENDPOINT = '/users'

class << self
# @param [String] name
# @param [String] email
# @param [String] password
# @return [Hash]
def create(name, email, password)
res = Base.new().post(ENDPOINT, {:name => name, :email => email, :password => password})

user_create_results = {
:error => res['error'],
:message => res['because']
}

results = res['results']
unless results.nil?
user_create_results.merge!({
:name => results['user']['name'],
:token => results['api_token']
})
end

user_create_results
end

# @param [String] name
# @param [String] email
# @return [Boolean]
def registered?(name, email)
res = Base.new().get("#{ENDPOINT}/registered", {:name => name, :email => email})
res['results']['registered']
end
end
end
end
end
end
69 changes: 64 additions & 5 deletions lib/deploygate/command_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class CommandBuilder

def run
GithubIssueRequest::Url.config('deploygate', 'deploygate-cli')
check_update()

program :name, 'dg'
program :version, VERSION
Expand All @@ -17,7 +18,7 @@ def run
begin
Commands::Init.run
rescue => e
error_handling("Commands::Init Error: #{e.class}", create_error_issue_body(e), ['bug', 'Init'])
error_handling("Commands::Init Error: #{e.class}", create_error_issue_body(e))
raise e
end
end
Expand All @@ -35,7 +36,7 @@ def run
begin
Commands::Deploy.run(args, options)
rescue => e
error_handling("Commands::Deploy Error: #{e.class}", create_error_issue_body(e), ['bug', 'Deploy'])
error_handling("Commands::Deploy Error: #{e.class}", create_error_issue_body(e))
raise e
end
end
Expand All @@ -49,7 +50,7 @@ def run
begin
Commands::Logout.run
rescue => e
error_handling("Commands::Logout Error: #{e.class}", create_error_issue_body(e), ['bug', 'Logout'])
error_handling("Commands::Logout Error: #{e.class}", create_error_issue_body(e))
raise e
end
end
Expand All @@ -62,6 +63,10 @@ def run
# @return [String]
def create_error_issue_body(error)
return <<EOF
# Status
deploygate-cli ver #{DeployGate::VERSION}
# Error message
#{error.message}
Expand All @@ -75,11 +80,11 @@ def create_error_issue_body(error)
# @param [String] title
# @param [String] body
# @param [Array] labels
def error_handling(title, body, labels)
def error_handling(title, body, labels = [])
options = {
:title => title,
:body => body,
:labels => labels.push("v#{DeployGate::VERSION}")
:labels => labels
}
url = GithubIssueRequest::Url.new(options).to_s
puts ''
Expand All @@ -89,5 +94,59 @@ def error_handling(title, body, labels)
end
puts ''
end

# @return [void]
def check_update
current_version = DeployGate::VERSION

# check cache
if DeployGate::Config::CacheVersion.exist?
data = DeployGate::Config::CacheVersion.read
if Time.parse(data['check_date']) > 1.day.ago
# cache available
latest_version = data['latest_version']
if Gem::Version.new(latest_version) > Gem::Version.new(current_version)
show_update_message(latest_version)
end
else
request_gem_update_checker
end
else
request_gem_update_checker
end
end

# @return [void]
def request_gem_update_checker
gem_name = DeployGate.name.downcase
current_version = DeployGate::VERSION

checker = GemUpdateChecker::Client.new(gem_name, current_version)
if checker.update_available
show_update_message(checker.latest_version)
end
cache_data = {
:latest_version => checker.latest_version,
:check_date => Time.now
}
DeployGate::Config::CacheVersion.write(cache_data)
end

# @param [String] latest_version
# @return [void]
def show_update_message(latest_version)
gem_name = DeployGate.name.downcase
current_version = DeployGate::VERSION
update_message =<<EOF
#################################################################
# #{gem_name} #{latest_version} is available. You are on #{current_version}.
# It is recommended to use the latest version.
# Update using 'gem update #{gem_name}'.
#################################################################
EOF
DeployGate::Message::Warning.print(update_message)
end
end
end
2 changes: 1 addition & 1 deletion lib/deploygate/commands/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class << self
# @param [Array] args
# @param [Commander::Command::Options] options
def run(args, options)
Init.login unless DeployGate::Session.new.login?
Init.start_login_or_create_account() unless DeployGate::Session.new.login?

# push or build(android/ios)
args.push(Dir.pwd) if args.empty?
Expand Down
15 changes: 15 additions & 0 deletions lib/deploygate/commands/deploy/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def run(args, options)
ios(workspaces, options)
elsif DeployGate::Build.android?(work_dir)
# TODO: support android build
print_no_target
else
print_no_target
end
end

Expand Down Expand Up @@ -55,6 +58,8 @@ def ios(workspaces, options)
ipa_path = DeployGate::Builds::Ios.build(analyze, target_scheme, codesigning_identity, method)
rescue => e
# TODO: build error handling
use_xcode_path = `xcode-select -p`
DeployGate::Message::Error.print("Current Xcode used to build: #{use_xcode_path} (via xcode-select)")
raise e
end

Expand Down Expand Up @@ -141,6 +146,16 @@ def create_provisioning(identifier, uuid)

DeployGate::Builds::Ios::Export.select_profile(provisioning_profiles)
end

def print_no_target
message = <<EOF
No deploy target found.
Please run on the root directory of iOS project or specify .apk/.ipa file to deploy.
EOF
DeployGate::Message::Warning.print(message)
end
end
end
end
Expand Down
79 changes: 73 additions & 6 deletions lib/deploygate/commands/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,33 @@ class << self

# @return [void]
def run
login unless Session.new().login?
start_login_or_create_account() unless Session.new().login?

finish
end

# @return [void]
def login
def start_login_or_create_account
puts 'Welcome to DeployGate!'
puts ''
print 'Email: '
email= STDIN.gets.chop
print 'Password: '
password = STDIN.noecho(&:gets).chop
email = ask("Email: ")

puts ''
puts 'Checking for your account...'
if DeployGate::User.registered?('', email)
puts ''
password = input_password('Password: ')
puts ''
login(email, password)
else
create_account(email)
end
end

# @param [String] email
# @param [String] password
# @return [void]
def login(email, password)
begin
Session.login(email, password)
rescue Session::LoginError => e
Expand All @@ -34,6 +46,61 @@ def login
Message::Success.print("Hello #{session.name}!")
end

# @param [String] email
# @return [void]
def create_account(email)
puts "Looks new to DeployGate. Let's set up your account, just choose your username and password."
puts ''

name = input_new_account_name()
puts ''

password = input_new_account_password()
puts ''

print 'Creating your account... '
if DeployGate::User.create(name, email, password).nil?
Message::Error.print('User create error')
Message::Error.print('Please try again')
raise 'User create error'
else
Message::Success.print('done! Your account has been set up successfully.')
login(email, password)
end
end

# @return [String]
def input_new_account_name
user_name = ask("Username: " )
print 'Checking for availability... '

if DeployGate::User.registered?(user_name, '')
Message::Error.print("Bad, #{user_name} is already used. Please try again.")
return input_new_account_name()
else
Message::Success.print("Good, #{user_name} is available.")
return user_name
end
end

# @return [String]
def input_new_account_password
password = input_password('Password: ')
secound_password = input_password('Type the same password: ')

if password == secound_password
return password
else
Message::Error.print("Password Please enter the same thing.")
return input_new_account_password()
end
end

# @return [String]
def input_password(message)
ask(message) { |q| q.echo = "*" }
end

# @return [void]
def finish
Message::Success.print('Enjoy development!')
Expand Down
35 changes: 0 additions & 35 deletions lib/deploygate/config.rb

This file was deleted.

Loading

0 comments on commit 4d2224b

Please sign in to comment.