escobar 0.1.16 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 565dac00f0f4e159e17b700aa337db80c05957d0
4
- data.tar.gz: d41e2099578502c68ee80ee4b6b3fbcc3f677ba7
3
+ metadata.gz: 215c4992c7b3c59638fa16b2c086228df83e32b2
4
+ data.tar.gz: a91f0086d93d2aac3b398b976ee879207d5b0609
5
5
  SHA512:
6
- metadata.gz: ff14c4e3c5aec1c607bb314037886339692d4cc8f7f0c775083f347b6dc639e34a56343cbb55621e3d6d9a865536b92c1ee6bcdb8b1a1712181f0158449d27eb
7
- data.tar.gz: a420c04e6df43198808782f6a06cb03d8ea30231f2ccb6a089c1b5d6e908f651545fb3a2f7c6e11397210242fa155753e4de7c195f53929b4b552b7cffdfb1ec
6
+ metadata.gz: ab9b5f92213cbac6e4deb86a3ad290781d12fdb8c1e43b0e79d29c5a0ae5729bdb5fc3fb838f4619c8aaab419fe94e6264164addd95fd94ae8c5ed705f26797e
7
+ data.tar.gz: 618b14a920e91853aaff09c29a92b28d01cd76e26126faf37ba57df84de6d6f28b87e09ca0354743579d2c1436260cb3dd8d3f0fdfbf05a780638e5d693efc8f
@@ -5,6 +5,8 @@ require "escobar/version"
5
5
 
6
6
  # Top-level module for Escobar code
7
7
  module Escobar
8
+ UUID_REGEX = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
9
+
8
10
  def self.netrc
9
11
  @netrc ||= begin
10
12
  if env_netrc
@@ -42,6 +44,9 @@ module Escobar
42
44
  def self.github_api_token
43
45
  netrc["api.github.com"]["password"]
44
46
  end
47
+ module Heroku
48
+ BuildRequestSuccess = Escobar::UUID_REGEX
49
+ end
45
50
  end
46
51
 
47
52
  require_relative "./escobar/client"
@@ -11,6 +11,13 @@ module Escobar
11
11
  @heroku = Escobar::Heroku::Client.new(heroku_token)
12
12
  end
13
13
 
14
+ # mask password
15
+ def inspect
16
+ inspected = super
17
+ inspected = inspected.gsub! @github_token, "*******" if @github_token
18
+ inspected
19
+ end
20
+
14
21
  def [](key)
15
22
  pipelines.find { |pipeline| pipeline.name == key }
16
23
  end
@@ -8,6 +8,13 @@ module Escobar
8
8
  @name_with_owner = name_with_owner
9
9
  end
10
10
 
11
+ # mask password
12
+ def inspect
13
+ inspected = super
14
+ inspected = inspected.gsub! @token, "*******" if @token
15
+ inspected
16
+ end
17
+
11
18
  def whoami
12
19
  client.get("/user")
13
20
  end
@@ -37,12 +37,9 @@ module Escobar
37
37
  }
38
38
  end
39
39
 
40
- def repository
41
- @repository ||= get("/pipelines/#{id}/repository")
42
- end
43
-
44
40
  def github_repository
45
- repository["repository"] && repository["repository"]["name"]
41
+ remote_repository["repository"] &&
42
+ remote_repository["repository"]["name"]
46
43
  end
47
44
 
48
45
  def couplings
@@ -55,8 +52,52 @@ module Escobar
55
52
  end
56
53
  end
57
54
 
58
- def github_archive_link(ref)
59
- github_client.archive_link(ref)
55
+ # rubocop:disable Metrics/AbcSize
56
+ # rubocop:disable Metrics/LineLength
57
+ def create_deployment(ref, environment, force = false, custom_payload = {})
58
+ app = environments[environment] && environments[environment].last
59
+ return({ error: "No '#{environment}' environment for #{name}." }) unless app
60
+
61
+ github_deployment = create_github_deployment("deploy", ref, environment, force, custom_payload)
62
+ return({ error: github_deployment["message"] }) unless github_deployment["sha"]
63
+
64
+ build = create_heroku_build(app.name, github_deployment["sha"])
65
+ case build["id"]
66
+ when "two_factor"
67
+ description = "A second factor is required. Use your configured authenticator app or yubikey."
68
+ create_github_deployment_status(github_deployment["url"], nil, "failure", description)
69
+ return({ error: build["message"] })
70
+ when Escobar::Heroku::BuildRequestSuccess
71
+ path = "/apps/#{app.name}/activity/builds/#{build['id']}"
72
+ target_url = "https://dashboard.heroku.com#{path}"
73
+
74
+ create_github_deployment_status(github_deployment["url"], target_url, "pending", "Build running..")
75
+ { app_id: app.name, build_id: build["id"], deployment_url: github_deployment["url"] }
76
+ else
77
+ return({ error: "Unable to create heroku build for #{name}" })
78
+ end
79
+ end
80
+ # rubocop:enable Metrics/AbcSize
81
+ # rubocop:enable Metrics/LineLength
82
+
83
+ def get(path)
84
+ response = kolkrabbi.get do |request|
85
+ request.url path
86
+ request.headers["Content-Type"] = "application/json"
87
+ request.headers["Authorization"] = "Bearer #{client.heroku.token}"
88
+ end
89
+
90
+ JSON.parse(response.body)
91
+ end
92
+
93
+ def kolkrabbi
94
+ @kolkrabbi ||= Faraday.new(url: "https://#{ENV['KOLKRABBI_HOSTNAME']}")
95
+ end
96
+
97
+ private
98
+
99
+ def remote_repository
100
+ @remote_repository ||= get("/pipelines/#{id}/repository")
60
101
  end
61
102
 
62
103
  def github_client
@@ -68,7 +109,7 @@ module Escobar
68
109
  { name: name, pipeline: self.to_hash, provider: "slash-heroku" }
69
110
  end
70
111
 
71
- def create_github_deployment(task, ref, environment, force = false, extras = {})
112
+ def create_github_deployment(task, ref, environment, force, extras = {})
72
113
  options = {
73
114
  ref: ref,
74
115
  task: task,
@@ -80,56 +121,25 @@ module Escobar
80
121
  github_client.create_deployment(options)
81
122
  end
82
123
 
83
- def create_github_deployment_status(deployment_url, name, build_id, state)
84
- path = "/apps/#{name}/activity/builds/#{build_id}"
124
+ def create_github_deployment_status(url, target_url, state, description)
85
125
  payload = {
86
126
  state: state,
87
- target_url: "https://dashboard.heroku.com#{path}",
88
- description: "Deploying from escobar-#{Escobar::VERSION}"
127
+ target_url: target_url,
128
+ description: description
89
129
  }
90
- github_client.create_deployment_status(deployment_url, payload)
130
+ github_client.create_deployment_status(url, payload)
91
131
  end
92
132
 
93
133
  def create_heroku_build(app_name, sha)
94
134
  body = {
95
135
  source_blob: {
96
- url: github_archive_link(sha),
136
+ url: github_client.archive_link(sha),
97
137
  version: sha[0..7],
98
138
  version_description: "#{github_repository}:#{sha}"
99
139
  }
100
140
  }
101
141
  client.heroku.post("/apps/#{app_name}/builds", body)
102
142
  end
103
-
104
- # rubocop:disable Metrics/AbcSize
105
- # rubocop:disable Metrics/LineLength
106
- def create_deployment(ref, environment, force)
107
- app = environments[environment] && environments[environment].last
108
- return({ error: "No '#{environment}' environment for #{name}." }) unless app
109
-
110
- github_deployment = create_github_deployment("deploy", ref, environment, force)
111
- return({ error: github_deployment["message"] }) unless github_deployment["sha"]
112
-
113
- build = create_heroku_build(app.name, github_deployment["sha"])
114
- return({ error: "Unable to create heroku build for #{name}" }) unless build["id"]
115
-
116
- create_github_deployment_status(github_deployment["url"], app.name, build["id"], "pending")
117
- { app_id: app.name, build_id: build["id"], deployment_url: github_deployment["url"] }
118
- end
119
-
120
- def get(path)
121
- response = kolkrabbi.get do |request|
122
- request.url path
123
- request.headers["Content-Type"] = "application/json"
124
- request.headers["Authorization"] = "Bearer #{client.heroku.token}"
125
- end
126
-
127
- JSON.parse(response.body)
128
- end
129
-
130
- def kolkrabbi
131
- @kolkrabbi ||= Faraday.new(url: "https://#{ENV['KOLKRABBI_HOSTNAME']}")
132
- end
133
143
  end
134
144
  end
135
145
  end
@@ -1,3 +1,3 @@
1
1
  module Escobar
2
- VERSION = "0.1.16".freeze
2
+ VERSION = "0.1.17".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: escobar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Donohoe