Skip to content

Commit

Permalink
Switch to API v4 for retrieving the branch info
Browse files Browse the repository at this point in the history
  • Loading branch information
coder-hugo committed Nov 29, 2022
1 parent 1ff1be5 commit 34b335f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
25 changes: 12 additions & 13 deletions lib/deploy_now_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 34b335f

Please sign in to comment.