From 34b335f3a90894b3fa1a6f9ee6bab77819277ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=BCller?= Date: Tue, 29 Nov 2022 14:50:58 +0100 Subject: [PATCH] Switch to API v4 for retrieving the branch info --- Gemfile.lock | 10 +++++----- lib/deploy_now_api.rb | 25 ++++++++++++------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 7669b35..3ff9d76 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - deploy-to-ionos (1.1.4) + deploy-to-ionos (1.1.5) colorize (= 0.8.1) ld-eventsource (= 2.2.0) net-ssh (= 6.1.0) @@ -12,8 +12,8 @@ PATH GEM remote: https://rubygems.org/ specs: - addressable (2.8.0) - public_suffix (>= 2.0.2, < 5.0) + addressable (2.8.1) + public_suffix (>= 2.0.2, < 6.0) colorize (0.8.1) concurrent-ruby (1.1.10) diff-lcs (1.4.4) @@ -24,7 +24,7 @@ GEM ffi-compiler (1.0.1) ffi (>= 1.0.0) rake - http (5.0.4) + http (5.1.0) addressable (~> 2.8) http-cookie (~> 1.0) http-form_data (~> 2.2) @@ -45,7 +45,7 @@ GEM net-ssh (6.1.0) netrc (0.11.0) passgen (1.2.0) - public_suffix (4.0.7) + public_suffix (5.0.0) rake (13.0.6) rest-client (2.1.0) http-accept (>= 1.7.0, < 2.0) diff --git a/lib/deploy_now_api.rb b/lib/deploy_now_api.rb index 5bdde45..4611902 100644 --- a/lib/deploy_now_api.rb +++ b/lib/deploy_now_api.rb @@ -44,20 +44,19 @@ def update_deployment_status end def get_branch_info - response = @client["/v3/accounts/me/projects/#{@project_id}"].get - project = JSON.parse(response.body) - is_production_branch = project['productionBranch']['id'] == @branch_id - branch = JSON.parse(@client["/v3/accounts/me/projects/#{@project_id}/branches/#{@branch_id}"].get.body) + deployments = JSON.parse(@client["/v4/accounts/me/projects/#{@project_id}/branches/#{@branch_id}/deployments"].get.body) + abort "v1 of this action doesn't support multi deployments".colorize(:red) if deployments['total'] > 1 + deployment = JSON.parse(@client["/v4/accounts/me/projects/#{@project_id}/branches/#{@branch_id}/deployments/#{deployments['values'].first['id']}"].get.body) { - app_url: is_production_branch ? "https://#{project['domain']}" : branch['webSpace']['webSpace']['siteUrl'], - last_deployment_date: branch['lastDeploymentDate'], - database: branch.include?('database') ? { id: branch['database']['database']['id'], - host: branch['database']['database']['host'], - name: branch['database']['database']['name'] } : nil, - storage_quota: branch['webSpace']['webSpace']['quota']['storageQuota'].to_i, - ssh_host: branch['webSpace']['webSpace']['sshHost'], - php_version: branch['webSpace']['webSpace']['phpVersion'], - web_space_id: branch['webSpace']['webSpace']['id'] + app_url: "https://#{deployment['domain']['name']}", + last_deployment_date: deployment['state']['lastDeployedDate'], + database: deployment.include?('database') ? { id: deployment['database']['database']['id'], + host: deployment['database']['database']['host'], + name: deployment['database']['database']['name'] } : nil, + storage_quota: deployment['webspace']['webspace']['quota']['storageQuota'].to_i, + ssh_host: deployment['webspace']['webspace']['sshHost'], + php_version: deployment['webspace']['webspace']['phpVersion'], + web_space_id: deployment['webspace']['webspace']['id'] }.compact end