From 7037c9f13bc2b164f34cb498f169d9b20bff2d13 Mon Sep 17 00:00:00 2001 From: henteko Date: Mon, 2 Nov 2015 15:27:34 +0900 Subject: [PATCH 01/16] version up --- lib/deploygate/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/deploygate/version.rb b/lib/deploygate/version.rb index 8421afa..099102a 100644 --- a/lib/deploygate/version.rb +++ b/lib/deploygate/version.rb @@ -1,3 +1,3 @@ module DeployGate - VERSION = "0.0.3" + VERSION = "0.0.4" end From 8457babbb9fb222450781d6fc374d676df2d4e7a Mon Sep 17 00:00:00 2001 From: henteko Date: Mon, 2 Nov 2015 16:23:35 +0900 Subject: [PATCH 02/16] add check gem latest version --- deploygate.gemspec | 1 + lib/deploygate.rb | 2 ++ lib/deploygate/command_builder.rb | 20 ++++++++++++++++++++ lib/deploygate/message/warning.rb | 12 ++++++++++++ 4 files changed, 35 insertions(+) create mode 100644 lib/deploygate/message/warning.rb diff --git a/deploygate.gemspec b/deploygate.gemspec index bf0f7dd..92b9f37 100644 --- a/deploygate.gemspec +++ b/deploygate.gemspec @@ -33,6 +33,7 @@ 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' # ios build spec.add_dependency 'gym', '~> 1.0.0' diff --git a/lib/deploygate.rb b/lib/deploygate.rb index 5e3ae48..2161dce 100644 --- a/lib/deploygate.rb +++ b/lib/deploygate.rb @@ -10,6 +10,7 @@ require "github_issue_request" require "highline" require "uuid" +require "gem_update_checker" # ios build require "gym" @@ -39,4 +40,5 @@ module DeployGate require "deploygate/builds/ios/set_profile" require "deploygate/message/error" require "deploygate/message/success" +require "deploygate/message/warning" require "deploygate/version" diff --git a/lib/deploygate/command_builder.rb b/lib/deploygate/command_builder.rb index 0ce1cd6..c05d2df 100644 --- a/lib/deploygate/command_builder.rb +++ b/lib/deploygate/command_builder.rb @@ -5,6 +5,7 @@ class CommandBuilder def run GithubIssueRequest::Url.config('deploygate', 'deploygate-cli') + check_update() program :name, 'dg' program :version, VERSION @@ -89,5 +90,24 @@ def error_handling(title, body, labels) end puts '' end + + # @return [void] + def check_update + gem_name = DeployGate.name.downcase + current_version = DeployGate::VERSION + checker = GemUpdateChecker::Client.new(gem_name, current_version) + + return unless checker.update_available + update_message =< Date: Mon, 2 Nov 2015 16:48:16 +0900 Subject: [PATCH 03/16] add config base and credential --- lib/deploygate.rb | 3 +- lib/deploygate/config.rb | 35 ------------------ lib/deploygate/config/base.rb | 36 +++++++++++++++++++ lib/deploygate/config/credential.rb | 12 +++++++ lib/deploygate/session.rb | 6 ++-- .../{config_spec.rb => config/base_spec.rb} | 12 ++++--- spec/deploygate/session_spec.rb | 2 +- spec/spec_helper.rb | 2 +- 8 files changed, 63 insertions(+), 45 deletions(-) delete mode 100644 lib/deploygate/config.rb create mode 100644 lib/deploygate/config/base.rb create mode 100644 lib/deploygate/config/credential.rb rename spec/deploygate/{config_spec.rb => config/base_spec.rb} (62%) diff --git a/lib/deploygate.rb b/lib/deploygate.rb index 2161dce..121f5d3 100644 --- a/lib/deploygate.rb +++ b/lib/deploygate.rb @@ -30,7 +30,8 @@ module DeployGate 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/session" require "deploygate/deploy" require "deploygate/build" diff --git a/lib/deploygate/config.rb b/lib/deploygate/config.rb deleted file mode 100644 index c20b58e..0000000 --- a/lib/deploygate/config.rb +++ /dev/null @@ -1,35 +0,0 @@ -module DeployGate - class Config - class << self - - # @return [String] - def file_path - File.join(ENV["HOME"], '.dg/credentials') - end - - # @param [Hash] config - # @return [void] - def write(config) - FileUtils.mkdir_p(File.dirname(file_path)) - - data = JSON.generate(config) - file = File.open(file_path, "w+") - file.print data - file.close - end - - # @return [Hash] - def read - file = File.open(file_path) - data = file.read - file.close - JSON.parse(data) - end - - # @return [Boolean] - def exist? - File.exist?(file_path) - end - end - end -end diff --git a/lib/deploygate/config/base.rb b/lib/deploygate/config/base.rb new file mode 100644 index 0000000..ced54d1 --- /dev/null +++ b/lib/deploygate/config/base.rb @@ -0,0 +1,36 @@ +module DeployGate + module Config + class Base + class << self + def file_path + # Please override this method + raise NotImplementedError.new("You must implement #{self.class}##{__method__}") + end + + # @param [Hash] config + # @return [void] + def write(config) + FileUtils.mkdir_p(File.dirname(file_path)) + + data = JSON.generate(config) + file = File.open(file_path, "w+") + file.print data + file.close + end + + # @return [Hash] + def read + file = File.open(file_path) + data = file.read + file.close + JSON.parse(data) + end + + # @return [Boolean] + def exist? + File.exist?(file_path) + end + end + end + end +end diff --git a/lib/deploygate/config/credential.rb b/lib/deploygate/config/credential.rb new file mode 100644 index 0000000..904366e --- /dev/null +++ b/lib/deploygate/config/credential.rb @@ -0,0 +1,12 @@ +module DeployGate + module Config + class Credential < Base + class << self + # @return [String] + def file_path + File.join(ENV["HOME"], '.dg/credentials') + end + end + end + end +end diff --git a/lib/deploygate/session.rb b/lib/deploygate/session.rb index 901974d..8d276ee 100644 --- a/lib/deploygate/session.rb +++ b/lib/deploygate/session.rb @@ -38,7 +38,7 @@ def self.save(name, token) :name => name, :token => token } - Config.write(settings) + Config::Credential.write(settings) end # @return [void] @@ -51,8 +51,8 @@ def self.delete # @return [void] def load_setting - return unless Config.exist? - settings = Config.read + return unless Config::Credential.exist? + settings = Config::Credential.read @name = settings['name'] @token = settings['token'] end diff --git a/spec/deploygate/config_spec.rb b/spec/deploygate/config/base_spec.rb similarity index 62% rename from spec/deploygate/config_spec.rb rename to spec/deploygate/config/base_spec.rb index f0ea8b0..801a7ef 100644 --- a/spec/deploygate/config_spec.rb +++ b/spec/deploygate/config/base_spec.rb @@ -1,4 +1,8 @@ -describe DeployGate::Config do +describe DeployGate::Config::Base do + before do + allow(DeployGate::Config::Base).to receive(:file_path).and_return(File.join(SPEC_FILE_PATH, 'test_files/.dg/base')) + end + describe "#write" do it "write data" do write_data = { @@ -6,9 +10,9 @@ :token => 'token' } allow(File).to receive(:open).and_return(StringIO.new("", "w+")) - DeployGate::Config.write(write_data) + DeployGate::Config::Base.write(write_data) - file = File.open(DeployGate::Config.file_path) + file = File.open(DeployGate::Config::Base.file_path) expect(file.string).to eq(write_data.to_json.to_s) end end @@ -20,7 +24,7 @@ :token => 'token' }.to_json.to_s allow(File).to receive(:open).and_return(StringIO.new(write_data)) - data = DeployGate::Config.read + data = DeployGate::Config::Base.read expect(data).to eq(JSON.parse(write_data)) end diff --git a/spec/deploygate/session_spec.rb b/spec/deploygate/session_spec.rb index 15394a6..0e7baa9 100644 --- a/spec/deploygate/session_spec.rb +++ b/spec/deploygate/session_spec.rb @@ -48,7 +48,7 @@ :token => 'token' } call_config_write_and_fix_config = false - allow(DeployGate::Config).to receive(:write) { |c| call_config_write_and_fix_config = c == config_data} + allow(DeployGate::Config::Credential).to receive(:write) { |c| call_config_write_and_fix_config = c == config_data} DeployGate::Session.save(config_data[:name], config_data[:token]) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2c31487..747bfee 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,7 +6,7 @@ RSpec.configure do |config| config.before :each do # config file mock - allow(DeployGate::Config).to receive(:file_path).and_return(File.join(SPEC_FILE_PATH, 'test_files/.dg/credentials')) + allow(DeployGate::Config::Credential).to receive(:file_path).and_return(File.join(SPEC_FILE_PATH, 'test_files/.dg/credentials')) # config dir mock allow(FileUtils).to receive(:mkdir_p) {} end From d5cdd6d305f8e56d28b2533c6ee1935bd8877d34 Mon Sep 17 00:00:00 2001 From: henteko Date: Mon, 2 Nov 2015 17:26:51 +0900 Subject: [PATCH 04/16] support cache check version --- deploygate.gemspec | 1 + lib/deploygate.rb | 2 ++ lib/deploygate/command_builder.rb | 39 ++++++++++++++++++++++++-- lib/deploygate/config/cache_version.rb | 12 ++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 lib/deploygate/config/cache_version.rb diff --git a/deploygate.gemspec b/deploygate.gemspec index 92b9f37..e93ef71 100644 --- a/deploygate.gemspec +++ b/deploygate.gemspec @@ -34,6 +34,7 @@ POST_INSTALL_MESSAGE 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' diff --git a/lib/deploygate.rb b/lib/deploygate.rb index 121f5d3..e6046e6 100644 --- a/lib/deploygate.rb +++ b/lib/deploygate.rb @@ -11,6 +11,7 @@ require "highline" require "uuid" require "gem_update_checker" +require "active_support/core_ext/time" # ios build require "gym" @@ -32,6 +33,7 @@ module DeployGate require "deploygate/commands/deploy/build" require "deploygate/config/base" require "deploygate/config/credential" +require "deploygate/config/cache_version" require "deploygate/session" require "deploygate/deploy" require "deploygate/build" diff --git a/lib/deploygate/command_builder.rb b/lib/deploygate/command_builder.rb index c05d2df..208337f 100644 --- a/lib/deploygate/command_builder.rb +++ b/lib/deploygate/command_builder.rb @@ -93,15 +93,50 @@ def error_handling(title, body, labels) # @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 - return unless checker.update_available + # @param [String] latest_version + # @return [void] + def show_update_message(latest_version) + gem_name = DeployGate.name.downcase + current_version = DeployGate::VERSION update_message =< Date: Mon, 2 Nov 2015 17:38:24 +0900 Subject: [PATCH 05/16] print xcode build path --- lib/deploygate/commands/deploy/build.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/deploygate/commands/deploy/build.rb b/lib/deploygate/commands/deploy/build.rb index 5f5ea81..3ccac50 100644 --- a/lib/deploygate/commands/deploy/build.rb +++ b/lib/deploygate/commands/deploy/build.rb @@ -24,6 +24,9 @@ def run(args, options) # @param [Hash] options # @return [void] def ios(workspaces, options) + use_xcode_path = `xcode-select -p` + DeployGate::Message::Success.print("Build Xcode path: #{use_xcode_path}") + analyze = DeployGate::Builds::Ios::Analyze.new(workspaces) target_scheme = analyze.scheme begin From 104e55b66332386058c7f0a0691045e360f5a311 Mon Sep 17 00:00:00 2001 From: henteko Date: Mon, 2 Nov 2015 17:54:43 +0900 Subject: [PATCH 06/16] print no target --- lib/deploygate/commands/deploy/build.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/deploygate/commands/deploy/build.rb b/lib/deploygate/commands/deploy/build.rb index 5f5ea81..bbb42c7 100644 --- a/lib/deploygate/commands/deploy/build.rb +++ b/lib/deploygate/commands/deploy/build.rb @@ -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 @@ -141,6 +144,16 @@ def create_provisioning(identifier, uuid) DeployGate::Builds::Ios::Export.select_profile(provisioning_profiles) end + + def print_no_target + message = < Date: Mon, 2 Nov 2015 18:13:42 +0900 Subject: [PATCH 07/16] xcode build error print xcode path --- lib/deploygate/commands/deploy/build.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/deploygate/commands/deploy/build.rb b/lib/deploygate/commands/deploy/build.rb index 3ccac50..05c1589 100644 --- a/lib/deploygate/commands/deploy/build.rb +++ b/lib/deploygate/commands/deploy/build.rb @@ -24,9 +24,6 @@ def run(args, options) # @param [Hash] options # @return [void] def ios(workspaces, options) - use_xcode_path = `xcode-select -p` - DeployGate::Message::Success.print("Build Xcode path: #{use_xcode_path}") - analyze = DeployGate::Builds::Ios::Analyze.new(workspaces) target_scheme = analyze.scheme begin @@ -58,6 +55,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("Build Xcode path: #{use_xcode_path}") raise e end From a317849307be642a7827fc6eb6a3da4edec4e4eb Mon Sep 17 00:00:00 2001 From: henteko Date: Mon, 2 Nov 2015 18:17:11 +0900 Subject: [PATCH 08/16] fix wording --- lib/deploygate/commands/deploy/build.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/deploygate/commands/deploy/build.rb b/lib/deploygate/commands/deploy/build.rb index bbb42c7..8926eb9 100644 --- a/lib/deploygate/commands/deploy/build.rb +++ b/lib/deploygate/commands/deploy/build.rb @@ -148,8 +148,8 @@ def create_provisioning(identifier, uuid) def print_no_target message = < Date: Mon, 2 Nov 2015 18:22:03 +0900 Subject: [PATCH 09/16] fix wording --- lib/deploygate/commands/deploy/build.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/deploygate/commands/deploy/build.rb b/lib/deploygate/commands/deploy/build.rb index 05c1589..baa7969 100644 --- a/lib/deploygate/commands/deploy/build.rb +++ b/lib/deploygate/commands/deploy/build.rb @@ -56,7 +56,7 @@ def ios(workspaces, options) rescue => e # TODO: build error handling use_xcode_path = `xcode-select -p` - DeployGate::Message::Error.print("Build Xcode path: #{use_xcode_path}") + DeployGate::Message::Error.print("Current Xcode used to build: #{use_xcode_path} (via xcode-select)") raise e end From 6b22fa1d84ca5cefe094fc0808d1c6c45c22e4f3 Mon Sep 17 00:00:00 2001 From: henteko Date: Mon, 2 Nov 2015 20:01:40 +0900 Subject: [PATCH 10/16] add api/user --- lib/deploygate.rb | 1 + lib/deploygate/api/v1/user.rb | 35 +++++++++++++++++++++++++++++ spec/deploygate/api/v1/user_spec.rb | 28 +++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 lib/deploygate/api/v1/user.rb create mode 100644 spec/deploygate/api/v1/user_spec.rb diff --git a/lib/deploygate.rb b/lib/deploygate.rb index e6046e6..527643a 100644 --- a/lib/deploygate.rb +++ b/lib/deploygate.rb @@ -25,6 +25,7 @@ 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" diff --git a/lib/deploygate/api/v1/user.rb b/lib/deploygate/api/v1/user.rb new file mode 100644 index 0000000..37759e1 --- /dev/null +++ b/lib/deploygate/api/v1/user.rb @@ -0,0 +1,35 @@ +module DeployGate + module API + module V1 + class User + + ENDPOINT = '/users' + + class << self + # @param [String] name + # @param [String] email + # @param [String] passowrd + # @return [Boolean] + 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 + end + end + end + end +end diff --git a/spec/deploygate/api/v1/user_spec.rb b/spec/deploygate/api/v1/user_spec.rb new file mode 100644 index 0000000..4e45be7 --- /dev/null +++ b/spec/deploygate/api/v1/user_spec.rb @@ -0,0 +1,28 @@ +describe DeployGate::API::V1::User do + describe "#create" do + it "success" do + name = 'test' + email = 'email' + password = 'password' + token = 'token' + response = { + :error => false, + :because => '', + :results => { + :user => {:name => name}, + :api_token => token + } + } + stub_request(:post, "#{API_ENDPOINT}/users"). + to_return(:body => response.to_json) + + results = DeployGate::API::V1::User.create(name, email, password) + expect(results).to eq({ + :error => response[:error], + :message => response[:because], + :name => name, + :token => token + }) + end + end +end From 5d6a69f5bf24d3386414e73d4fb84572f5205ec0 Mon Sep 17 00:00:00 2001 From: henteko Date: Wed, 4 Nov 2015 16:27:13 +0900 Subject: [PATCH 11/16] add already_registered? api --- lib/deploygate/api/v1/user.rb | 23 ++++++++++++++++-- spec/deploygate/api/v1/user_spec.rb | 36 +++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/lib/deploygate/api/v1/user.rb b/lib/deploygate/api/v1/user.rb index 37759e1..51061bf 100644 --- a/lib/deploygate/api/v1/user.rb +++ b/lib/deploygate/api/v1/user.rb @@ -8,8 +8,8 @@ class User class << self # @param [String] name # @param [String] email - # @param [String] passowrd - # @return [Boolean] + # @param [String] password + # @return [Hash] def create(name, email, password) res = Base.new().post(ENDPOINT, {:name => name, :email => email, :password => password}) @@ -28,6 +28,25 @@ def create(name, email, password) user_create_results end + + # @param [String] name_or_email + # @return [Hash] + def show(name_or_email) + res = Base.new().get("#{ENDPOINT}/#{name_or_email}", {}) + user_show_results = { + :error => res['error'], + :message => res['because'] + } + + results = res['results'] + unless results.nil? + user_show_results.merge!({ + :name => results['name'], + }) + end + + user_show_results + end end end end diff --git a/spec/deploygate/api/v1/user_spec.rb b/spec/deploygate/api/v1/user_spec.rb index 4e45be7..db4c216 100644 --- a/spec/deploygate/api/v1/user_spec.rb +++ b/spec/deploygate/api/v1/user_spec.rb @@ -25,4 +25,40 @@ }) end end + + describe "#already_registered?" do + it "registerd" do + name = 'test' + response = { + :error => false, + :because => '', + :results => {:name => name} + } + stub_request(:get, "#{API_ENDPOINT}/users/#{name}"). + to_return(:body => response.to_json) + + results = DeployGate::API::V1::User.show(name) + expect(results).to eq({ + :error => response[:error], + :message => response[:because], + :name => name, + }) + end + + it "not registerd" do + name = 'test' + response = { + :error => true, + :because => '' + } + stub_request(:get, "#{API_ENDPOINT}/users/#{name}"). + to_return(:body => response.to_json) + + results = DeployGate::API::V1::User.show(name) + expect(results).to eq({ + :error => response[:error], + :message => response[:because] + }) + end + end end From cf9e2b271f4d90279e066f94f77e8b7e89aae7ce Mon Sep 17 00:00:00 2001 From: henteko Date: Wed, 4 Nov 2015 17:14:13 +0900 Subject: [PATCH 12/16] support create account --- lib/deploygate.rb | 1 + lib/deploygate/commands/deploy.rb | 2 +- lib/deploygate/commands/init.rb | 84 +++++++++++++++++++++++++++++-- lib/deploygate/user.rb | 29 +++++++++++ 4 files changed, 110 insertions(+), 6 deletions(-) create mode 100644 lib/deploygate/user.rb diff --git a/lib/deploygate.rb b/lib/deploygate.rb index 527643a..f4b4a54 100644 --- a/lib/deploygate.rb +++ b/lib/deploygate.rb @@ -38,6 +38,7 @@ module DeployGate 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" diff --git a/lib/deploygate/commands/deploy.rb b/lib/deploygate/commands/deploy.rb index ba2f798..002d2f2 100644 --- a/lib/deploygate/commands/deploy.rb +++ b/lib/deploygate/commands/deploy.rb @@ -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? diff --git a/lib/deploygate/commands/init.rb b/lib/deploygate/commands/init.rb index 9e00c8d..bb74b28 100644 --- a/lib/deploygate/commands/init.rb +++ b/lib/deploygate/commands/init.rb @@ -5,21 +5,34 @@ 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 = STDIN.gets.chop + puts '' + puts 'Checking for your account...' + if DeployGate::User.find_user(email).nil? + create_account(email) + else + puts '' + password = input_password() + puts '' + login(email, password) + end + end + # @param [String] email + # @param [String] password + # @return [void] + def login(email, password) begin Session.login(email, password) rescue Session::LoginError => e @@ -34,6 +47,67 @@ 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 + print 'Username: ' + user_name = STDIN.gets.chop + print 'Checking for availability... ' + + if DeployGate::User.find_user(user_name).nil? + Message::Success.print("Good, #{user_name} is available.") + return user_name + else + Message::Error.print("Bad, #{user_name} is already used. Please try again.") + return input_new_account_name() + end + end + + # @return [String] + def input_new_account_password + print 'Password: ' + password = STDIN.noecho(&:gets).chop + puts '' + print 'Type the same password: ' + secound_password = STDIN.noecho(&:gets).chop + + if password == secound_password + return password + else + puts '' + Message::Error.print("Password Please enter the same thing.") + return input_new_account_password() + end + end + + # @return [String] + def input_password + print 'Password: ' + password = STDIN.noecho(&:gets).chop + end + # @return [void] def finish Message::Success.print('Enjoy development!') diff --git a/lib/deploygate/user.rb b/lib/deploygate/user.rb new file mode 100644 index 0000000..3958cb0 --- /dev/null +++ b/lib/deploygate/user.rb @@ -0,0 +1,29 @@ +module DeployGate + class User + attr_reader :name + + # @param [String] name + # @return [DeployGate::User] + def initialize(name) + @name = name + end + + # @param [String] name + # @param [String] email + # @param [String] password + # @return [DeployGate::User] + def self.create(name, email, password) + results = DeployGate::API::V1::User.create(name, email, password) + return if results[:error] + DeployGate::User.new(results[:name]) + end + + # @param [String] email_or_name + # @return [DeployGate::User] + def self.find_user(email_or_name) + results = DeployGate::API::V1::User.show(email_or_name) + return if results[:error] + DeployGate::User.new(results[:name]) + end + end +end From 37e90b8d6c98a549f1f6d3f9e91165da3e1726d8 Mon Sep 17 00:00:00 2001 From: henteko Date: Thu, 5 Nov 2015 13:43:09 +0900 Subject: [PATCH 13/16] change api check_already_registered --- lib/deploygate/api/v1/user.rb | 23 ++++++----------------- lib/deploygate/commands/init.rb | 14 +++++++------- lib/deploygate/user.rb | 11 +++++------ 3 files changed, 18 insertions(+), 30 deletions(-) diff --git a/lib/deploygate/api/v1/user.rb b/lib/deploygate/api/v1/user.rb index 51061bf..eb8c1e0 100644 --- a/lib/deploygate/api/v1/user.rb +++ b/lib/deploygate/api/v1/user.rb @@ -29,23 +29,12 @@ def create(name, email, password) user_create_results end - # @param [String] name_or_email - # @return [Hash] - def show(name_or_email) - res = Base.new().get("#{ENDPOINT}/#{name_or_email}", {}) - user_show_results = { - :error => res['error'], - :message => res['because'] - } - - results = res['results'] - unless results.nil? - user_show_results.merge!({ - :name => results['name'], - }) - end - - user_show_results + # @param [String] name + # @param [String] email + # @return [Boolean] + def already_registered?(name, email) + res = Base.new().get("#{ENDPOINT}/check_already_registered", {:name => name, :email => email}) + res['results']['already_registered'] end end end diff --git a/lib/deploygate/commands/init.rb b/lib/deploygate/commands/init.rb index bb74b28..46ac99d 100644 --- a/lib/deploygate/commands/init.rb +++ b/lib/deploygate/commands/init.rb @@ -19,13 +19,13 @@ def start_login_or_create_account puts '' puts 'Checking for your account...' - if DeployGate::User.find_user(email).nil? - create_account(email) - else + if DeployGate::User.already_registered?('', email) puts '' password = input_password() puts '' login(email, password) + else + create_account(email) end end @@ -76,12 +76,12 @@ def input_new_account_name user_name = STDIN.gets.chop print 'Checking for availability... ' - if DeployGate::User.find_user(user_name).nil? - Message::Success.print("Good, #{user_name} is available.") - return user_name - else + if DeployGate::User.already_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 diff --git a/lib/deploygate/user.rb b/lib/deploygate/user.rb index 3958cb0..0e9afd4 100644 --- a/lib/deploygate/user.rb +++ b/lib/deploygate/user.rb @@ -18,12 +18,11 @@ def self.create(name, email, password) DeployGate::User.new(results[:name]) end - # @param [String] email_or_name - # @return [DeployGate::User] - def self.find_user(email_or_name) - results = DeployGate::API::V1::User.show(email_or_name) - return if results[:error] - DeployGate::User.new(results[:name]) + # @param [String] name + # @param [String] email + # @return [Boolean] + def self.already_registered?(name, email) + DeployGate::API::V1::User.already_registered?(name, email) end end end From 3835a9bf5a317bf963d31989c8bf8188d0819203 Mon Sep 17 00:00:00 2001 From: henteko Date: Thu, 5 Nov 2015 13:56:25 +0900 Subject: [PATCH 14/16] password input * --- lib/deploygate/commands/init.rb | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/lib/deploygate/commands/init.rb b/lib/deploygate/commands/init.rb index 46ac99d..a948e2a 100644 --- a/lib/deploygate/commands/init.rb +++ b/lib/deploygate/commands/init.rb @@ -14,14 +14,13 @@ def run def start_login_or_create_account puts 'Welcome to DeployGate!' puts '' - print 'Email: ' - email = STDIN.gets.chop + email = ask("Email: ") puts '' puts 'Checking for your account...' if DeployGate::User.already_registered?('', email) puts '' - password = input_password() + password = input_password('Password: ') puts '' login(email, password) else @@ -72,8 +71,7 @@ def create_account(email) # @return [String] def input_new_account_name - print 'Username: ' - user_name = STDIN.gets.chop + user_name = ask("Username: " ) print 'Checking for availability... ' if DeployGate::User.already_registered?(user_name, '') @@ -87,25 +85,20 @@ def input_new_account_name # @return [String] def input_new_account_password - print 'Password: ' - password = STDIN.noecho(&:gets).chop - puts '' - print 'Type the same password: ' - secound_password = STDIN.noecho(&:gets).chop + password = input_password('Password: ') + secound_password = input_password('Type the same password: ') if password == secound_password return password else - puts '' Message::Error.print("Password Please enter the same thing.") return input_new_account_password() end end # @return [String] - def input_password - print 'Password: ' - password = STDIN.noecho(&:gets).chop + def input_password(message) + ask(message) { |q| q.echo = "*" } end # @return [void] From 74e821d8574613c27e0b1f77c635e0d7842d4c7f Mon Sep 17 00:00:00 2001 From: henteko Date: Thu, 5 Nov 2015 14:06:49 +0900 Subject: [PATCH 15/16] fix #27 --- lib/deploygate/command_builder.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/deploygate/command_builder.rb b/lib/deploygate/command_builder.rb index 208337f..6396a85 100644 --- a/lib/deploygate/command_builder.rb +++ b/lib/deploygate/command_builder.rb @@ -18,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 @@ -36,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 @@ -50,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 @@ -63,6 +63,10 @@ def run # @return [String] def create_error_issue_body(error) return < title, :body => body, - :labels => labels.push("v#{DeployGate::VERSION}") + :labels => labels } url = GithubIssueRequest::Url.new(options).to_s puts '' From 8aa1f38145cf289b3c07558278a6ec2927e8b24f Mon Sep 17 00:00:00 2001 From: henteko Date: Thu, 5 Nov 2015 14:34:48 +0900 Subject: [PATCH 16/16] fix user registered api --- lib/deploygate/api/v1/user.rb | 6 +++--- lib/deploygate/commands/init.rb | 4 ++-- lib/deploygate/user.rb | 4 ++-- spec/deploygate/api/v1/user_spec.rb | 32 ++++++++++++----------------- 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/lib/deploygate/api/v1/user.rb b/lib/deploygate/api/v1/user.rb index eb8c1e0..dd206bc 100644 --- a/lib/deploygate/api/v1/user.rb +++ b/lib/deploygate/api/v1/user.rb @@ -32,9 +32,9 @@ def create(name, email, password) # @param [String] name # @param [String] email # @return [Boolean] - def already_registered?(name, email) - res = Base.new().get("#{ENDPOINT}/check_already_registered", {:name => name, :email => email}) - res['results']['already_registered'] + def registered?(name, email) + res = Base.new().get("#{ENDPOINT}/registered", {:name => name, :email => email}) + res['results']['registered'] end end end diff --git a/lib/deploygate/commands/init.rb b/lib/deploygate/commands/init.rb index a948e2a..0ec69e1 100644 --- a/lib/deploygate/commands/init.rb +++ b/lib/deploygate/commands/init.rb @@ -18,7 +18,7 @@ def start_login_or_create_account puts '' puts 'Checking for your account...' - if DeployGate::User.already_registered?('', email) + if DeployGate::User.registered?('', email) puts '' password = input_password('Password: ') puts '' @@ -74,7 +74,7 @@ def input_new_account_name user_name = ask("Username: " ) print 'Checking for availability... ' - if DeployGate::User.already_registered?(user_name, '') + if DeployGate::User.registered?(user_name, '') Message::Error.print("Bad, #{user_name} is already used. Please try again.") return input_new_account_name() else diff --git a/lib/deploygate/user.rb b/lib/deploygate/user.rb index 0e9afd4..2cf31a0 100644 --- a/lib/deploygate/user.rb +++ b/lib/deploygate/user.rb @@ -21,8 +21,8 @@ def self.create(name, email, password) # @param [String] name # @param [String] email # @return [Boolean] - def self.already_registered?(name, email) - DeployGate::API::V1::User.already_registered?(name, email) + def self.registered?(name, email) + DeployGate::API::V1::User.registered?(name, email) end end end diff --git a/spec/deploygate/api/v1/user_spec.rb b/spec/deploygate/api/v1/user_spec.rb index db4c216..f03ec46 100644 --- a/spec/deploygate/api/v1/user_spec.rb +++ b/spec/deploygate/api/v1/user_spec.rb @@ -26,39 +26,33 @@ end end - describe "#already_registered?" do - it "registerd" do + describe "#registered?" do + it "registered" do name = 'test' response = { :error => false, :because => '', - :results => {:name => name} + :results => {:registered => true} } - stub_request(:get, "#{API_ENDPOINT}/users/#{name}"). + stub_request(:get, "#{API_ENDPOINT}/users/registered?email=&name=#{name}"). to_return(:body => response.to_json) - results = DeployGate::API::V1::User.show(name) - expect(results).to eq({ - :error => response[:error], - :message => response[:because], - :name => name, - }) + result = DeployGate::API::V1::User.registered?(name, '') + expect(result).to be_truthy end - it "not registerd" do + it "not registered" do name = 'test' response = { - :error => true, - :because => '' + :error => false, + :because => '', + :results => {:registered => false} } - stub_request(:get, "#{API_ENDPOINT}/users/#{name}"). + stub_request(:get, "#{API_ENDPOINT}/users/registered?email=&name=#{name}"). to_return(:body => response.to_json) - results = DeployGate::API::V1::User.show(name) - expect(results).to eq({ - :error => response[:error], - :message => response[:because] - }) + result = DeployGate::API::V1::User.registered?(name, '') + expect(result).to be_falsey end end end