From 6878bc904e5454a904470ea472ae83309cb1e77b Mon Sep 17 00:00:00 2001 From: jiikko Date: Tue, 21 Dec 2021 15:20:29 +0900 Subject: [PATCH 1/6] =?UTF-8?q?=E6=96=B0=E8=A6=8F=E7=99=BB=E9=8C=B2?= =?UTF-8?q?=E5=8B=95=E7=B7=9A=E3=82=92=E5=89=8A=E9=99=A4=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/locales/en.yml | 2 ++ lib/deploygate.rb | 1 + lib/deploygate/command_builder.rb | 9 +++++++ lib/deploygate/commands.rb | 5 ++++ lib/deploygate/commands/add_devices.rb | 2 +- lib/deploygate/commands/deploy.rb | 2 +- lib/deploygate/commands/deploy/push.rb | 2 +- lib/deploygate/commands/login.rb | 34 +++----------------------- 8 files changed, 24 insertions(+), 33 deletions(-) create mode 100644 lib/deploygate/commands.rb diff --git a/config/locales/en.yml b/config/locales/en.yml index a91e9f8..61c8338 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2,6 +2,8 @@ en: errors: check_update_failure: 'Checking update failed' + account_not_found_error: 'Your account was not found. Please create it from https://deploygate.com.' + command_builder: name: 'dg' description: 'Control DeployGate from your terminal.' diff --git a/lib/deploygate.rb b/lib/deploygate.rb index 433b765..99bef46 100644 --- a/lib/deploygate.rb +++ b/lib/deploygate.rb @@ -44,6 +44,7 @@ module DeployGate require "deploygate/api/v1/users/app" require "deploygate/api/v1/users/apps/cli_websockets" require "deploygate/command_builder" +require "deploygate/commands" require "deploygate/commands/login" require "deploygate/commands/logout" require "deploygate/commands/config" diff --git a/lib/deploygate/command_builder.rb b/lib/deploygate/command_builder.rb index 6a16e27..6b8a87d 100644 --- a/lib/deploygate/command_builder.rb +++ b/lib/deploygate/command_builder.rb @@ -53,6 +53,9 @@ def run options.default :terminal => false begin Commands::Login.run(args, options) + rescue Commands::AccountNotFoundError => e + puts HighLine.color(I18n.t('errors.account_not_found_error'), HighLine::RED) + exit 1 rescue => e error_handling(LOGIN, e) exit 1 @@ -74,6 +77,9 @@ def run options.default :message => '', :user => nil, :open => false, 'disable_notify' => false, :command => nil begin Commands::Deploy.run(args, options) + rescue Commands::AccountNotFoundError => e + puts HighLine.color(I18n.t('errors.account_not_found_error'), HighLine::RED) + exit 1 rescue => e error_handling(DEPLOY, e) exit 1 @@ -95,6 +101,9 @@ def run options.default :user => nil, :server => false, :command => 'add_devices' begin Commands::AddDevices.run(args, options) + rescue Commands::AccountNotFoundError => e + puts HighLine.color(I18n.t('errors.account_not_found_error'), HighLine::RED) + exit 1 rescue => e error_handling(ADD_DEVICES, e) exit 1 diff --git a/lib/deploygate/commands.rb b/lib/deploygate/commands.rb new file mode 100644 index 0000000..adfb665 --- /dev/null +++ b/lib/deploygate/commands.rb @@ -0,0 +1,5 @@ +module DeployGate + module Commands + class AccountNotFoundError < StandardError; end + end +end diff --git a/lib/deploygate/commands/add_devices.rb b/lib/deploygate/commands/add_devices.rb index 83c419f..f81019c 100644 --- a/lib/deploygate/commands/add_devices.rb +++ b/lib/deploygate/commands/add_devices.rb @@ -11,7 +11,7 @@ def run(args, options) session = DeployGate::Session.new unless session.login? - Login.start_login_or_create_account() + Login.start_login() session = DeployGate::Session.new() end diff --git a/lib/deploygate/commands/deploy.rb b/lib/deploygate/commands/deploy.rb index 356949b..8f80685 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) - Login.start_login_or_create_account() unless DeployGate::Session.new.login? + Login.start_login() unless DeployGate::Session.new.login? # push or build(android/ios) args.push(Dir.pwd) if args.empty? diff --git a/lib/deploygate/commands/deploy/push.rb b/lib/deploygate/commands/deploy/push.rb index 39569c5..fd6dbcc 100644 --- a/lib/deploygate/commands/deploy/push.rb +++ b/lib/deploygate/commands/deploy/push.rb @@ -13,7 +13,7 @@ class << self def upload(args, options) session = DeployGate::Session.new() unless session.login? - Login.start_login_or_create_account() + Login.start_login() session = DeployGate::Session.new() end diff --git a/lib/deploygate/commands/login.rb b/lib/deploygate/commands/login.rb index feea3b0..52547d0 100644 --- a/lib/deploygate/commands/login.rb +++ b/lib/deploygate/commands/login.rb @@ -8,7 +8,7 @@ def run(args, options) welcome() if options.terminal - start_login_or_create_account() + start_login() else DeployGate::BrowserLogin.new().start() end @@ -20,7 +20,8 @@ def welcome end # @return [void] - def start_login_or_create_account + # @raise [AccountNotFoundError] emailに一致するUserが存在しないとき + def start_login puts '' email = ask(I18n.t('commands.login.start_login_or_create_account.email')) @@ -32,7 +33,7 @@ def start_login_or_create_account puts '' start(email, password) else - create_account(email) + raise AccountNotFoundError, 'No users matching email were found' end end @@ -56,33 +57,6 @@ def login_success puts HighLine.color(I18n.t('commands.login.start.success', name: session.name), HighLine::GREEN) end - # @param [String] email - # @return [void] - def create_account(email) - puts I18n.t('commands.login.create_account.prompt') - puts '' - - name = input_new_account_name() - puts '' - - password = input_new_account_password() - puts '' - - unless check_terms - puts HighLine.color(I18n.t('commands.login.check_terms.error'), HighLine::RED) - exit 1 - end - - print I18n.t('commands.login.create_account.creating') - if DeployGate::User.create(name, email, password).nil? - puts HighLine.color(I18n.t('commands.login.create_account.error'), HighLine::RED) - raise 'User create error' - else - puts HighLine.color(I18n.t('commands.login.create_account.success'), HighLine::GREEN) - start(email, password) - end - end - # @return [String] def input_new_account_name user_name = ask(I18n.t('commands.login.input_new_account_name.input_user_name')) From 82db1dfa71ed7868690128c5149f29c53b0279be Mon Sep 17 00:00:00 2001 From: jiikko Date: Wed, 22 Dec 2021 19:28:36 +0900 Subject: [PATCH 2/6] =?UTF-8?q?=E6=96=B0=E6=A9=9F=E7=99=BB=E9=8C=B2?= =?UTF-8?q?=E9=8A=85=E7=B7=9A=E7=B3=BB=E3=81=AE=E3=83=AA=E3=82=BD=E3=83=BC?= =?UTF-8?q?=E3=82=B9=E3=82=92=E5=89=8A=E9=99=A4=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/locales/en.yml | 22 ------------------ lib/deploygate/api/v1/user.rb | 24 ------------------- lib/deploygate/commands/login.rb | 36 ----------------------------- lib/deploygate/user.rb | 11 --------- spec/deploygate/api/v1/user_spec.rb | 27 ---------------------- 5 files changed, 120 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 61c8338..6e0164e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -107,28 +107,6 @@ en: Could not log in to DeployGate. Please try again. success: 'Hello %{name}!' - create_account: - prompt: "Looks new to DeployGate. Let's set up your account, just choose your user name and password." - creating: 'Creating your account... ' - error: | - Could not create your account. - Please try again. - success: 'done! Your account has been set up successfully.' - input_new_account_name: - input_user_name: 'Username: ' - checking: 'Checking for availability... ' - already_used_user_name: 'Sorry, %{user_name} was already taken. Please try again.' - success: 'Good, %{user_name} is available.' - input_new_account_password: - input_password: 'Password: ' - input_same_password: 'Type the same password: ' - error: "Passwords didn't match. Please type again." - check_terms: - terms_url: 'Terms of Service: https://deploygate.com/terms' - privacy_url: 'Privacy Policy: https://deploygate.com/terms/privacy' - note: "DeployGate properly manages your account information under GDPR, Japan's Personal Information Protection Act and our Privacy Policy." - text: 'I agree to the Terms of Service and Privacy Policy (y/n) ' - error: 'You must agree to the Terms of Service and Privacy Policy.' logout: success: | Logout success! diff --git a/lib/deploygate/api/v1/user.rb b/lib/deploygate/api/v1/user.rb index 83ad661..75a3d4c 100644 --- a/lib/deploygate/api/v1/user.rb +++ b/lib/deploygate/api/v1/user.rb @@ -6,30 +6,6 @@ class User ENDPOINT = '/users' class << self - # @param [String] name - # @param [String] email - # @param [String] password - # @param [String] locale - # @return [Hash] - def create(name, email, password, locale = 'en') - res = Base.new().post(ENDPOINT, {:name => name, :email => email, :password => password, :locale => locale}) - - 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] diff --git a/lib/deploygate/commands/login.rb b/lib/deploygate/commands/login.rb index 52547d0..86355a1 100644 --- a/lib/deploygate/commands/login.rb +++ b/lib/deploygate/commands/login.rb @@ -57,42 +57,6 @@ def login_success puts HighLine.color(I18n.t('commands.login.start.success', name: session.name), HighLine::GREEN) end - # @return [String] - def input_new_account_name - user_name = ask(I18n.t('commands.login.input_new_account_name.input_user_name')) - print I18n.t('commands.login.input_new_account_name.checking') - - if DeployGate::User.registered?(user_name, '') - puts HighLine.color(I18n.t('commands.login.input_new_account_name.already_used_user_name', user_name: user_name), HighLine::RED) - return input_new_account_name() - else - puts HighLine.color(I18n.t('commands.login.input_new_account_name.success', user_name: user_name), HighLine::GREEN) - return user_name - end - end - - # @return [String] - def input_new_account_password - password = input_password(I18n.t('commands.login.input_new_account_password.input_password')) - secound_password = input_password(I18n.t('commands.login.input_new_account_password.input_same_password')) - - if password == secound_password - return password - else - puts HighLine.color(I18n.t('commands.login.input_new_account_password.error'), HighLine::RED) - return input_new_account_password() - end - end - - # @return [boolean] - def check_terms - puts I18n.t('commands.login.check_terms.terms_url') - puts I18n.t('commands.login.check_terms.privacy_url') - puts I18n.t('commands.login.check_terms.note') - puts '' - HighLine.agree(I18n.t('commands.login.check_terms.text')) {|q| q.default = "n"} - end - # @return [String] def input_password(message) ask(message) { |q| q.echo = "*" } diff --git a/lib/deploygate/user.rb b/lib/deploygate/user.rb index efa3f5e..51ea710 100644 --- a/lib/deploygate/user.rb +++ b/lib/deploygate/user.rb @@ -8,17 +8,6 @@ def initialize(name) @name = name end - # @param [String] name - # @param [String] email - # @param [String] password - # @return [DeployGate::User] - def self.create(name, email, password) - locale = Locale.current.language - results = DeployGate::API::V1::User.create(name, email, password, locale) - return if results[:error] - DeployGate::User.new(results[:name]) - end - # @param [String] name # @param [String] email # @return [Boolean] diff --git a/spec/deploygate/api/v1/user_spec.rb b/spec/deploygate/api/v1/user_spec.rb index f03ec46..7db9665 100644 --- a/spec/deploygate/api/v1/user_spec.rb +++ b/spec/deploygate/api/v1/user_spec.rb @@ -1,31 +1,4 @@ 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 - describe "#registered?" do it "registered" do name = 'test' From 2cee0701026bbc865462fa6c95824979fb343c3d Mon Sep 17 00:00:00 2001 From: jiikko Date: Wed, 22 Dec 2021 19:50:55 +0900 Subject: [PATCH 3/6] =?UTF-8?q?remove=20=E6=96=87=E6=9C=AB.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/locales/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 6e0164e..93395f3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2,7 +2,7 @@ en: errors: check_update_failure: 'Checking update failed' - account_not_found_error: 'Your account was not found. Please create it from https://deploygate.com.' + account_not_found_error: 'Your account was not found. Please create it from https://deploygate.com' command_builder: name: 'dg' From 1200021b97eb1bd8b2660d881f18e5dd63f6e5f0 Mon Sep 17 00:00:00 2001 From: jiikko Date: Thu, 23 Dec 2021 10:46:28 +0900 Subject: [PATCH 4/6] Rename i18n namespace --- config/locales/en.yml | 2 +- lib/deploygate/commands/login.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 93395f3..28d7064 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -97,7 +97,7 @@ en: $ dg login print_login_user: 'User name: %{name}' login: - start_login_or_create_account: + start_login: welcome: 'Welcome to DeployGate!' email: 'Email: ' check_account: 'Checking for your account...' diff --git a/lib/deploygate/commands/login.rb b/lib/deploygate/commands/login.rb index 86355a1..1f88502 100644 --- a/lib/deploygate/commands/login.rb +++ b/lib/deploygate/commands/login.rb @@ -15,7 +15,7 @@ def run(args, options) end def welcome - puts I18n.t('commands.login.start_login_or_create_account.welcome') + puts I18n.t('commands.login.start_login.welcome') print_deploygate_aa() end @@ -23,13 +23,13 @@ def welcome # @raise [AccountNotFoundError] emailに一致するUserが存在しないとき def start_login puts '' - email = ask(I18n.t('commands.login.start_login_or_create_account.email')) + email = ask(I18n.t('commands.login.start_login.email')) puts '' - puts I18n.t('commands.login.start_login_or_create_account.check_account') + puts I18n.t('commands.login.start_login.check_account') if DeployGate::User.registered?('', email) puts '' - password = input_password(I18n.t('commands.login.start_login_or_create_account.input_password')) + password = input_password(I18n.t('commands.login.start_login.input_password')) puts '' start(email, password) else From fd8b753e4cd02cc07dbf0d7c00bf647d947cc711 Mon Sep 17 00:00:00 2001 From: jiikko Date: Thu, 23 Dec 2021 10:57:53 +0900 Subject: [PATCH 5/6] =?UTF-8?q?DeployGate::RavenIgnoreException=E3=82=92?= =?UTF-8?q?=E7=B6=99=E6=89=BF=E3=81=97=E3=81=9F=E3=82=A8=E3=83=A9=E3=83=BC?= =?UTF-8?q?=E3=82=AF=E3=83=A9=E3=82=B9=E3=82=92=E3=82=B9=E3=83=AD=E3=83=BC?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/deploygate.rb | 1 - lib/deploygate/command_builder.rb | 9 --------- lib/deploygate/commands.rb | 5 ----- lib/deploygate/commands/login.rb | 4 +++- 4 files changed, 3 insertions(+), 16 deletions(-) delete mode 100644 lib/deploygate/commands.rb diff --git a/lib/deploygate.rb b/lib/deploygate.rb index 99bef46..433b765 100644 --- a/lib/deploygate.rb +++ b/lib/deploygate.rb @@ -44,7 +44,6 @@ module DeployGate require "deploygate/api/v1/users/app" require "deploygate/api/v1/users/apps/cli_websockets" require "deploygate/command_builder" -require "deploygate/commands" require "deploygate/commands/login" require "deploygate/commands/logout" require "deploygate/commands/config" diff --git a/lib/deploygate/command_builder.rb b/lib/deploygate/command_builder.rb index 6b8a87d..6a16e27 100644 --- a/lib/deploygate/command_builder.rb +++ b/lib/deploygate/command_builder.rb @@ -53,9 +53,6 @@ def run options.default :terminal => false begin Commands::Login.run(args, options) - rescue Commands::AccountNotFoundError => e - puts HighLine.color(I18n.t('errors.account_not_found_error'), HighLine::RED) - exit 1 rescue => e error_handling(LOGIN, e) exit 1 @@ -77,9 +74,6 @@ def run options.default :message => '', :user => nil, :open => false, 'disable_notify' => false, :command => nil begin Commands::Deploy.run(args, options) - rescue Commands::AccountNotFoundError => e - puts HighLine.color(I18n.t('errors.account_not_found_error'), HighLine::RED) - exit 1 rescue => e error_handling(DEPLOY, e) exit 1 @@ -101,9 +95,6 @@ def run options.default :user => nil, :server => false, :command => 'add_devices' begin Commands::AddDevices.run(args, options) - rescue Commands::AccountNotFoundError => e - puts HighLine.color(I18n.t('errors.account_not_found_error'), HighLine::RED) - exit 1 rescue => e error_handling(ADD_DEVICES, e) exit 1 diff --git a/lib/deploygate/commands.rb b/lib/deploygate/commands.rb deleted file mode 100644 index adfb665..0000000 --- a/lib/deploygate/commands.rb +++ /dev/null @@ -1,5 +0,0 @@ -module DeployGate - module Commands - class AccountNotFoundError < StandardError; end - end -end diff --git a/lib/deploygate/commands/login.rb b/lib/deploygate/commands/login.rb index 1f88502..a8771ba 100644 --- a/lib/deploygate/commands/login.rb +++ b/lib/deploygate/commands/login.rb @@ -1,6 +1,8 @@ module DeployGate module Commands class Login + class AccountNotFoundError < DeployGate::RavenIgnoreException; end + class << self # @return [void] @@ -33,7 +35,7 @@ def start_login puts '' start(email, password) else - raise AccountNotFoundError, 'No users matching email were found' + raise AccountNotFoundError, HighLine.color(I18n.t('errors.account_not_found_error')) end end From 489aaf618109cc32887294589363d9d1f4964a8e Mon Sep 17 00:00:00 2001 From: jiikko Date: Thu, 23 Dec 2021 23:53:53 +0900 Subject: [PATCH 6/6] Remove empty line --- config/locales/en.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 28d7064..3f2bcac 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3,7 +3,6 @@ en: errors: check_update_failure: 'Checking update failed' account_not_found_error: 'Your account was not found. Please create it from https://deploygate.com' - command_builder: name: 'dg' description: 'Control DeployGate from your terminal.'