escobar 0.2.2.pre3 → 0.3.1

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: b2a510f255cf7e5e1d3979586716960d5dd9bc3f
4
- data.tar.gz: 599a9088845f54d822d58cfdf351cb7942b049ac
3
+ metadata.gz: 923902c750e029b0b46ecdda4bff5eb2960846b0
4
+ data.tar.gz: 4a95e5cc637b28ed6f0b38e19edca6e6cddd595c
5
5
  SHA512:
6
- metadata.gz: 78a531be9e75d38d2f56f49291809c2b6f90b4cf9f5105ca6b42f39a74457f405e6f17cdd49d7a3da8c205a6f898a7575e0babcd436e75c3a202964f8eb8caad
7
- data.tar.gz: 7e768592916a29b1de3148ec4a08661d7fca3aed3216c70955f9570c1df5ff0e9dd62497ec9cacf4aac1018879cda46d15eb23087e98758e3e6a5764283ce5fb
6
+ metadata.gz: b28917db0f1ef6ca05efb1d53a3f135fdd6b6e3ac04741a129e963d8d0f4f131bf7a5f5c5202eb07254f0d6bbdb63ebba299373239bfe3ccf828b3efa3c311ea
7
+ data.tar.gz: 2b370d85d2f1137566dd50c7b5131c56a9f47ccbeaeddda04ec8a20b3dcb55647b91091ea40dc144646b0e53e23b1904f9a81cd39950f15b970d07c51986f483
data/.gitignore CHANGED
@@ -12,3 +12,4 @@ tmp/.netrc
12
12
  .irb.history
13
13
  .env
14
14
  .ruby-version
15
+ .byebug_history
data/.rubocop.yml CHANGED
@@ -42,7 +42,7 @@ Documentation:
42
42
  - !ruby/regexp /spec\/*\/*/
43
43
 
44
44
  ClassLength:
45
- Max: 115
45
+ Max: 175
46
46
  Exclude:
47
47
  - !ruby/regexp /spec\/*\/*/
48
48
 
data/escobar.gemspec CHANGED
@@ -26,8 +26,8 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency "netrc", "~> 0.11"
27
27
 
28
28
  spec.add_development_dependency "bundler", "~> 1.11"
29
+ spec.add_development_dependency "byebug"
29
30
  spec.add_development_dependency "guard-rspec", "~> 4.6.2"
30
- spec.add_development_dependency "pry"
31
31
  spec.add_development_dependency "rake", "~> 10.0"
32
32
  spec.add_development_dependency "rspec", "~> 3.5.0.beta2"
33
33
  spec.add_development_dependency "rubocop", "~> 0.38"
data/lib/escobar.rb CHANGED
@@ -44,14 +44,12 @@ module Escobar
44
44
  def self.github_api_token
45
45
  netrc["api.github.com"]["password"]
46
46
  end
47
- module Heroku
48
- BuildRequestSuccess = Escobar::UUID_REGEX
49
- end
50
47
  end
51
48
 
52
49
  require_relative "./escobar/client"
53
50
  require_relative "./escobar/github/client"
54
51
  require_relative "./escobar/heroku/app"
52
+ require_relative "./escobar/heroku/build"
55
53
  require_relative "./escobar/heroku/client"
56
54
  require_relative "./escobar/heroku/coupling"
57
55
  require_relative "./escobar/heroku/pipeline"
@@ -20,94 +20,14 @@ 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
-
28
23
  # Accepts either google authenticator or yubikey second_factor formatting
29
24
  def preauth(second_factor)
30
25
  !client.heroku.put("/apps/#{id}/pre-authorizations", second_factor).any?
31
26
  end
32
27
 
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)
28
+ def locked?
29
+ response = client.heroku.get("/apps/#{id}/config-vars")
30
+ response["id"] == "two_factor"
111
31
  end
112
32
  end
113
33
  end
@@ -0,0 +1,50 @@
1
+ module Escobar
2
+ module Heroku
3
+ # Class representing a heroku build
4
+ class Build
5
+ attr_reader :app_id, :app_name, :client, :id
6
+
7
+ attr_accessor :command_id
8
+ attr_accessor :github_url
9
+ attr_accessor :pipeline_name
10
+ attr_accessor :sha
11
+
12
+ def initialize(client, app, id)
13
+ @id = id
14
+ @app_id = app.id
15
+ @app_name = app.name
16
+ @client = client
17
+ end
18
+
19
+ def info
20
+ @info ||= client.heroku.get("/apps/#{app_id}/builds/#{id}")
21
+ end
22
+
23
+ def dashboard_build_output_url
24
+ "https://dashboard.heroku.com/apps/#{app_name}/activity/builds/#{id}"
25
+ end
26
+
27
+ def repository_regex
28
+ %r{https:\/\/api\.github\.com\/repos\/([-_\.0-9a-z]+\/[-_\.0-9a-z]+)}
29
+ end
30
+
31
+ def repository
32
+ github_url.match(repository_regex)[1]
33
+ end
34
+
35
+ def to_job_json
36
+ {
37
+ sha: sha,
38
+ name: pipeline_name,
39
+ repo: repository,
40
+ app_id: app_id,
41
+ app_name: app_name,
42
+ build_id: id,
43
+ command_id: command_id,
44
+ target_url: dashboard_build_output_url,
45
+ deployment_url: github_url
46
+ }
47
+ end
48
+ end
49
+ end
50
+ end
@@ -91,20 +91,47 @@ module Escobar
91
91
  end
92
92
  end
93
93
 
94
- def create_deployment(ref, environment, force = false, payload = {})
95
- app = environments[environment] && environments[environment].last.app
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
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
+ raise ArgumentError, build["message"]
101
+ when Escobar::UUID_REGEX
102
+ heroku_build = Escobar::Heroku::Build.new(
103
+ client, app, build["id"]
104
+ )
105
+ heroku_build.github_url = github_deployment["url"]
106
+ heroku_build.pipeline_name = name
107
+ heroku_build.sha = sha
108
+
109
+ create_github_deployment_status(
110
+ github_deployment["url"],
111
+ heroku_build.dashboard_build_output_url,
112
+ "pending",
113
+ "Build running.."
114
+ )
115
+
116
+ heroku_build
103
117
  else
104
- { error: "No '#{environment}' environment for #{name}." }
118
+ raise ArgumentError, "Unable to create heroku build for #{name}"
105
119
  end
106
120
  end
107
121
 
122
+ def create_deployment(ref, environment, force = false, custom_payload = {})
123
+ app = environments[environment] && environments[environment].last
124
+ return({ error: "No '#{environment}' environment for #{name}." }) unless app
125
+
126
+ github_deployment = create_github_deployment("deploy", ref, environment, force, custom_payload)
127
+ return({ error: github_deployment["message"] }) unless github_deployment["sha"]
128
+
129
+ sha = github_deployment["sha"]
130
+ build = create_heroku_build(app.name, sha)
131
+ create_deployment_from(app, github_deployment, sha, build)
132
+ end
133
+ # rubocop:enable Metrics/LineLength
134
+
108
135
  def get(path)
109
136
  response = kolkrabbi_client.get do |request|
110
137
  request.url path
@@ -119,6 +146,10 @@ module Escobar
119
146
  @kolkrabbi ||= Faraday.new(url: "https://#{ENV['KOLKRABBI_HOSTNAME']}")
120
147
  end
121
148
 
149
+ def create_deployment_status(url, payload)
150
+ github_client.create_deployment_status(url, payload)
151
+ end
152
+
122
153
  private
123
154
 
124
155
  def remote_repository
@@ -129,6 +160,40 @@ module Escobar
129
160
  { name: name, pipeline: self.to_hash, provider: "slash-heroku" }
130
161
  end
131
162
 
163
+ def create_github_deployment(task, ref, environment, force, extras = {})
164
+ required_contexts = required_commit_contexts(force)
165
+
166
+ options = {
167
+ ref: ref,
168
+ task: task,
169
+ auto_merge: !force,
170
+ payload: extras.merge(custom_deployment_payload),
171
+ environment: environment,
172
+ required_contexts: required_contexts
173
+ }
174
+ github_client.create_deployment(options)
175
+ end
176
+
177
+ def create_github_deployment_status(url, target_url, state, description)
178
+ payload = {
179
+ state: state,
180
+ target_url: target_url,
181
+ description: description
182
+ }
183
+ create_deployment_status(url, payload)
184
+ end
185
+
186
+ def create_heroku_build(app_name, sha)
187
+ body = {
188
+ source_blob: {
189
+ url: github_client.archive_link(sha),
190
+ version: sha[0..7],
191
+ version_description: "#{github_repository}:#{sha}"
192
+ }
193
+ }
194
+ client.heroku.post("/apps/#{app_name}/builds", body)
195
+ end
196
+
132
197
  def github_client
133
198
  @github_client ||= Escobar::GitHub::Client.new(client.github_token,
134
199
  github_repository)
@@ -1,3 +1,3 @@
1
1
  module Escobar
2
- VERSION = "0.2.2.pre3".freeze
2
+ VERSION = "0.3.1".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.2.pre3
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Donohoe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-03 00:00:00.000000000 Z
11
+ date: 2017-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -53,33 +53,33 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.11'
55
55
  - !ruby/object:Gem::Dependency
56
- name: guard-rspec
56
+ name: byebug
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 4.6.2
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 4.6.2
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: pry
70
+ name: guard-rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 4.6.2
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 4.6.2
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -177,6 +177,7 @@ files:
177
177
  - lib/escobar/client.rb
178
178
  - lib/escobar/github/client.rb
179
179
  - lib/escobar/heroku/app.rb
180
+ - lib/escobar/heroku/build.rb
180
181
  - lib/escobar/heroku/client.rb
181
182
  - lib/escobar/heroku/coupling.rb
182
183
  - lib/escobar/heroku/pipeline.rb
@@ -196,9 +197,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
196
197
  version: '0'
197
198
  required_rubygems_version: !ruby/object:Gem::Requirement
198
199
  requirements:
199
- - - ">"
200
+ - - ">="
200
201
  - !ruby/object:Gem::Version
201
- version: 1.3.1
202
+ version: '0'
202
203
  requirements: []
203
204
  rubyforge_project:
204
205
  rubygems_version: 2.5.1