escobar 0.2.1 → 0.2.2.pre1

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: 4504457f5bf33b345fdb8250cff7d246a07c1102
4
- data.tar.gz: 8780426f0b46903792a101954476e1781c9128f9
3
+ metadata.gz: 4dcb8494c5d1b49c14b50e2abb945e09dd9897f1
4
+ data.tar.gz: 3f7324892b8260c505f8384a6b381ab25711a4e6
5
5
  SHA512:
6
- metadata.gz: afd9fbe836337dcdd8eaee118bb8e246a500ca1b65bd3a92acafd85b4a217383ec3426b9b744ea67bf9aaf70ec9b4cedb9b6c91c8be1987fc1883fdb67e432d8
7
- data.tar.gz: 953d97c4041b6669c3caa9fb485e2c93a83b7db63a37f0e6daef3bf0a72e2278874072fd3d704b06e15759e50ffadae59c79472d84b9ee012c212b8a1df1e2e2
6
+ metadata.gz: 439e7e9ada1b84086594df5e4f65c2aae7772c63607dc3030ecbbfb27ed5f54a7b400136e112d186fd637180c86318d35978d6e5c17854c694e56aed52e051d6
7
+ data.tar.gz: 5c5c03b3acb0ab6e8ba30808d4f18744e6f24021c6b6fa78c31666e220dd8a6fdbd9504213cfceb09c714da71722b87a060cfd1e3c42ee662bbad11380375c0d
data/.gitignore CHANGED
@@ -11,3 +11,4 @@
11
11
  tmp/.netrc
12
12
  .irb.history
13
13
  .env
14
+ .ruby-version
data/.rubocop.yml CHANGED
@@ -42,7 +42,7 @@ Documentation:
42
42
  - !ruby/regexp /spec\/*\/*/
43
43
 
44
44
  ClassLength:
45
- Max: 175
45
+ Max: 115
46
46
  Exclude:
47
47
  - !ruby/regexp /spec\/*\/*/
48
48
 
@@ -20,10 +20,95 @@ module Escobar
20
20
  "https://dashboard.heroku.com/apps/#{name}"
21
21
  end
22
22
 
23
+ def locked?
24
+ response = client.heroku.get("/apps/#{id}/config-vars")
25
+ response["id"] == "two_factor"
26
+ end
27
+
23
28
  # Accepts either google authenticator or yubikey second_factor formatting
24
29
  def preauth(second_factor)
25
30
  !client.heroku.put("/apps/#{id}/pre-authorizations", second_factor).any?
26
31
  end
32
+
33
+ def create_build(ref, environment, force, custom_payload)
34
+ deployment = create_github_deployment("deploy", ref, environment,
35
+ force, custom_payload)
36
+
37
+ return({ error: deployment["message"] }) unless deployment["sha"]
38
+
39
+ sha = github_deployment["sha"]
40
+ build = create_heroku_build(app.name, sha)
41
+ create_deployment_from(app, deployment, sha, build)
42
+ end
43
+
44
+ # rubocop:disable Metrics/LineLength
45
+ def create_deployment_from(app, github_deployment, sha, build)
46
+ case build["id"]
47
+ when "two_factor"
48
+ description = "A second factor is required. Use your configured " \
49
+ "authenticator app or yubikey."
50
+ create_github_deployment_status(github_deployment["url"], nil, "failure", description)
51
+ { error: build["message"] }
52
+ when Escobar::Heroku::BuildRequestSuccess
53
+ target_url = "https://dashboard.heroku.com/apps/#{app.name}/" \
54
+ "activity/builds/#{build['id']}"
55
+
56
+ create_github_deployment_status(github_deployment["url"],
57
+ target_url,
58
+ "pending",
59
+ "Build running..")
60
+ {
61
+ sha: sha,
62
+ name: name,
63
+ repo: github_repository,
64
+ app_id: app.name,
65
+ build_id: build["id"],
66
+ target_url: target_url,
67
+ deployment_url: github_deployment["url"]
68
+ }
69
+ else
70
+ { error: "Unable to create heroku build for #{name}" }
71
+ end
72
+ end
73
+ # rubocop:enable Metrics/LineLength
74
+
75
+ def create_heroku_build(app_name, sha)
76
+ body = {
77
+ source_blob: {
78
+ url: github_client.archive_link(sha),
79
+ version: sha[0..7],
80
+ version_description: "#{github_repository}:#{sha}"
81
+ }
82
+ }
83
+ client.heroku.post("/apps/#{app_name}/builds", body)
84
+ end
85
+
86
+ def create_github_deployment(task, ref, environment, force, extras = {})
87
+ required_contexts = required_commit_contexts(force)
88
+
89
+ options = {
90
+ ref: ref,
91
+ task: task,
92
+ auto_merge: !force,
93
+ payload: extras.merge(custom_deployment_payload),
94
+ environment: environment,
95
+ required_contexts: required_contexts
96
+ }
97
+ github_client.create_deployment(options)
98
+ end
99
+
100
+ def create_github_deployment_status(url, target_url, state, description)
101
+ payload = {
102
+ state: state,
103
+ target_url: target_url,
104
+ description: description
105
+ }
106
+ create_deployment_status(url, payload)
107
+ end
108
+
109
+ def create_deployment_status(url, payload)
110
+ github_client.create_deployment_status(url, payload)
111
+ end
27
112
  end
28
113
  end
29
114
  end
@@ -91,44 +91,20 @@ module Escobar
91
91
  end
92
92
  end
93
93
 
94
- # rubocop:disable Metrics/LineLength
95
- def create_deployment_from(app, github_deployment, sha, build)
96
- case build["id"]
97
- when "two_factor"
98
- description = "A second factor is required. Use your configured authenticator app or yubikey."
99
- create_github_deployment_status(github_deployment["url"], nil, "failure", description)
100
- { error: build["message"] }
101
- when Escobar::Heroku::BuildRequestSuccess
102
- target_url = "https://dashboard.heroku.com/apps/#{app.name}/activity/builds/#{build['id']}"
103
-
104
- create_github_deployment_status(github_deployment["url"], target_url, "pending", "Build running..")
105
- {
106
- sha: sha,
107
- name: name,
108
- repo: github_repository,
109
- app_id: app.name,
110
- build_id: build["id"],
111
- target_url: target_url,
112
- deployment_url: github_deployment["url"]
113
- }
94
+ def create_deployment(ref, environment, force = false, payload = {})
95
+ app = environments[environment] && environments[environment].last
96
+ if app
97
+ if !app.locked?
98
+ app.create_build(ref, environment, force, payload)
99
+ else
100
+ { error: "Application #{name} is locked by a second factor",
101
+ url: app.dashboard_url }
102
+ end
114
103
  else
115
- { error: "Unable to create heroku build for #{name}" }
104
+ { error: "No '#{environment}' environment for #{name}." }
116
105
  end
117
106
  end
118
107
 
119
- def create_deployment(ref, environment, force = false, custom_payload = {})
120
- app = environments[environment] && environments[environment].last
121
- return({ error: "No '#{environment}' environment for #{name}." }) unless app
122
-
123
- github_deployment = create_github_deployment("deploy", ref, environment, force, custom_payload)
124
- return({ error: github_deployment["message"] }) unless github_deployment["sha"]
125
-
126
- sha = github_deployment["sha"]
127
- build = create_heroku_build(app.name, sha)
128
- create_deployment_from(app, github_deployment, sha, build)
129
- end
130
- # rubocop:enable Metrics/LineLength
131
-
132
108
  def get(path)
133
109
  response = kolkrabbi_client.get do |request|
134
110
  request.url path
@@ -143,10 +119,6 @@ module Escobar
143
119
  @kolkrabbi ||= Faraday.new(url: "https://#{ENV['KOLKRABBI_HOSTNAME']}")
144
120
  end
145
121
 
146
- def create_deployment_status(url, payload)
147
- github_client.create_deployment_status(url, payload)
148
- end
149
-
150
122
  private
151
123
 
152
124
  def remote_repository
@@ -157,40 +129,6 @@ module Escobar
157
129
  { name: name, pipeline: self.to_hash, provider: "slash-heroku" }
158
130
  end
159
131
 
160
- def create_github_deployment(task, ref, environment, force, extras = {})
161
- required_contexts = required_commit_contexts(force)
162
-
163
- options = {
164
- ref: ref,
165
- task: task,
166
- auto_merge: !force,
167
- payload: extras.merge(custom_deployment_payload),
168
- environment: environment,
169
- required_contexts: required_contexts
170
- }
171
- github_client.create_deployment(options)
172
- end
173
-
174
- def create_github_deployment_status(url, target_url, state, description)
175
- payload = {
176
- state: state,
177
- target_url: target_url,
178
- description: description
179
- }
180
- create_deployment_status(url, payload)
181
- end
182
-
183
- def create_heroku_build(app_name, sha)
184
- body = {
185
- source_blob: {
186
- url: github_client.archive_link(sha),
187
- version: sha[0..7],
188
- version_description: "#{github_repository}:#{sha}"
189
- }
190
- }
191
- client.heroku.post("/apps/#{app_name}/builds", body)
192
- end
193
-
194
132
  def github_client
195
133
  @github_client ||= Escobar::GitHub::Client.new(client.github_token,
196
134
  github_repository)
@@ -1,3 +1,3 @@
1
1
  module Escobar
2
- VERSION = "0.2.1".freeze
2
+ VERSION = "0.2.2.pre1".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: escobar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Donohoe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-22 00:00:00.000000000 Z
11
+ date: 2017-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -196,9 +196,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
196
196
  version: '0'
197
197
  required_rubygems_version: !ruby/object:Gem::Requirement
198
198
  requirements:
199
- - - ">="
199
+ - - ">"
200
200
  - !ruby/object:Gem::Version
201
- version: '0'
201
+ version: 1.3.1
202
202
  requirements: []
203
203
  rubyforge_project:
204
204
  rubygems_version: 2.5.1