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 +4 -4
- data/lib/escobar.rb +5 -0
- data/lib/escobar/client.rb +7 -0
- data/lib/escobar/github/client.rb +7 -0
- data/lib/escobar/heroku/pipeline.rb +54 -44
- data/lib/escobar/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 215c4992c7b3c59638fa16b2c086228df83e32b2
|
4
|
+
data.tar.gz: a91f0086d93d2aac3b398b976ee879207d5b0609
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab9b5f92213cbac6e4deb86a3ad290781d12fdb8c1e43b0e79d29c5a0ae5729bdb5fc3fb838f4619c8aaab419fe94e6264164addd95fd94ae8c5ed705f26797e
|
7
|
+
data.tar.gz: 618b14a920e91853aaff09c29a92b28d01cd76e26126faf37ba57df84de6d6f28b87e09ca0354743579d2c1436260cb3dd8d3f0fdfbf05a780638e5d693efc8f
|
data/lib/escobar.rb
CHANGED
@@ -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"
|
data/lib/escobar/client.rb
CHANGED
@@ -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
|
@@ -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
|
-
|
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
|
-
|
59
|
-
|
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
|
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(
|
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:
|
88
|
-
description:
|
127
|
+
target_url: target_url,
|
128
|
+
description: description
|
89
129
|
}
|
90
|
-
github_client.create_deployment_status(
|
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:
|
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
|
data/lib/escobar/version.rb
CHANGED