escobar 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce8e5d85695d1007dd59db4960a71c0158a96221
4
- data.tar.gz: c6a576fb58636df2cca3a1ecd59802296d8bcaf5
3
+ metadata.gz: 072e5a1bc94a5f953adb447a45e7703f4bfe0467
4
+ data.tar.gz: b8a9972fe4f9dce4fe5417840b015779c4c88275
5
5
  SHA512:
6
- metadata.gz: 0c3c32e791117f9062813e6d2c499540a29accf2f840f934cc417c47cb6f3f934f23893feee76278193379d9c81d4ac61933f7d5a4ecf95e0dc321a574faf0eb
7
- data.tar.gz: 3e8e4683e2dd4e7a70cc628768eeabf9b0995114dc7e1c86564ea4c4c37d3dc4dd4dc085ebacf4ce1a574c95b0c7de11adb90b51393fb93f4311bcdd3443d985
6
+ metadata.gz: 5e6ee165a7329ca2afb2993375ace8b53be9366cca8448bc49ede681ab15a33e4be7ec6c329fef0f50c90a44c75c282c3490cc32fbbe7094dab0dac6839ceb29
7
+ data.tar.gz: 7fb5e12910a483946bc8f209ba7dba6623852aae5922c006f5d59b9679be983f67722d52d9f97ba690bbf3e214460acc8b75f68db53b7d9186f94c70e5daa037
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  *.gem
11
11
  tmp/.netrc
12
12
  .irb.history
13
+ .env
@@ -7,7 +7,7 @@ module Escobar
7
7
 
8
8
  attr_reader :github, :heroku
9
9
  def initialize(github_token, heroku_token)
10
- @github = Escobar::GitHub.new(github_token)
10
+ @github = Escobar::GitHub::Client.new(github_token)
11
11
  @heroku = Escobar::Heroku::Client.new(heroku_token)
12
12
  end
13
13
 
@@ -24,5 +24,65 @@ module Escobar
24
24
  Escobar::Heroku::Pipeline.new(heroku, pipe["id"], pipe["name"])
25
25
  end
26
26
  end
27
+
28
+ def dashboard_url(name)
29
+ "https://dashboard.heroku.com/apps/#{name}"
30
+ end
31
+
32
+ def reap_deployment(heroku_app_id, heroku_build_id)
33
+ info = heroku.get("/apps/#{heroku_app_id}/builds/#{heroku_build_id}")
34
+ case info["status"]
35
+ when "succeeded", "failed"
36
+ info
37
+ else
38
+ false
39
+ end
40
+ end
41
+
42
+ # rubocop:disable Metrics/AbcSize
43
+ # rubocop:disable Metrics/LineLength
44
+ # rubocop:disable Metrics/MethodLength
45
+ def create_deployment(name, repo, ref, environment, force)
46
+ deployment = Escobar::GitHub::Deployment.new(github.client)
47
+ deployment.ref = ref
48
+ deployment.repo = repo
49
+ deployment.force = force
50
+ deployment.environment = environment
51
+
52
+ archive_link = deployment.archive_link
53
+
54
+ pipeline = self[name]
55
+ if pipeline
56
+ payload = pipeline.to_hash
57
+ payload[:name] = name
58
+ payload[:provider] = "slash-heroku"
59
+
60
+ github_deployment = deployment.create(payload)
61
+
62
+ body = {
63
+ source_blob: {
64
+ url: archive_link,
65
+ version: github_deployment.sha[0..7],
66
+ version_description: "#{deployment.repo}:#{github_deployment.sha}"
67
+ }
68
+ }
69
+
70
+ app = pipeline.environments[environment].last
71
+
72
+ build = heroku.post("/apps/#{app.name}/builds", body)
73
+ if build["id"]
74
+ status_payload = {
75
+ target_url: "#{dashboard_url(app.name)}/activity/builds/#{build['id']}",
76
+ description: "Deploying from slash-heroku"
77
+ }
78
+
79
+ deployment.create_status(github_deployment.url, "pending", status_payload)
80
+ {
81
+ app_id: app.name, build_id: build["id"],
82
+ deployment_url: github_deployment.url
83
+ }
84
+ end
85
+ end
86
+ end
27
87
  end
28
88
  end
@@ -0,0 +1,19 @@
1
+ module Escobar
2
+ module GitHub
3
+ # Top-level class for interacting with GitHub API
4
+ class Client
5
+ attr_reader :client
6
+ def initialize(token)
7
+ @client = Octokit::Client.new(access_token: token)
8
+ end
9
+
10
+ def whoami
11
+ client.get("/user")
12
+ end
13
+
14
+ def archive_link(name_with_owner, ref)
15
+ client.archive_link(name_with_owner, ref: ref)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ module Escobar
2
+ module GitHub
3
+ # Class to create a Deployment record on GitHub
4
+ class Deployment
5
+ attr_accessor :client, :environment, :force, :ref, :repo
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ def payload(custom_payload)
11
+ {
12
+ task: "deploy",
13
+ payload: custom_payload,
14
+ auto_merge: !force,
15
+ required_contexts: [],
16
+ environment: "staging",
17
+ description: "Shipped from chat with slash-heroku"
18
+ }
19
+ end
20
+
21
+ def archive_link
22
+ client.archive_link(repo, ref: ref)
23
+ end
24
+
25
+ def create(custom_payload)
26
+ client.create_deployment(repo, ref, payload(custom_payload))
27
+ end
28
+
29
+ def create_status(url, state, extra_payload)
30
+ client.create_deployment_status(url, state, extra_payload)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -2,10 +2,10 @@ module Escobar
2
2
  module Heroku
3
3
  # Class representing a deployable environment
4
4
  class Coupling
5
- attr_reader :app, :app_id, :client, :id, :name
5
+ attr_reader :app, :app_id, :client, :id, :stage
6
6
  def initialize(client, coupling)
7
7
  @id = coupling["id"]
8
- @name = coupling["stage"]
8
+ @stage = coupling["stage"]
9
9
  @app_id = coupling["app"]["id"]
10
10
  @client = client
11
11
  end
@@ -13,6 +13,19 @@ module Escobar
13
13
  def app
14
14
  @app ||= Escobar::Heroku::App.new(client, app_id)
15
15
  end
16
+
17
+ def name
18
+ app && app.name
19
+ end
20
+
21
+ def to_hash
22
+ {
23
+ id: id,
24
+ name: name,
25
+ stage: stage,
26
+ app_id: app_id
27
+ }
28
+ end
16
29
  end
17
30
  end
18
31
  end
@@ -15,12 +15,27 @@ module Escobar
15
15
 
16
16
  def environments
17
17
  @environments ||= couplings.each_with_object({}) do |part, sum|
18
- sum[part.name] ||= []
19
- sum[part.name].push(part)
18
+ sum[part.stage] ||= []
19
+ sum[part.stage].push(part)
20
20
  sum
21
21
  end
22
22
  end
23
23
 
24
+ def environment_hash
25
+ sorted_environments.each_with_object({}) do |environment, sum|
26
+ sum[environment.to_sym] = environments[environment].map(&:to_hash)
27
+ sum
28
+ end
29
+ end
30
+
31
+ def to_hash
32
+ {
33
+ name: name,
34
+ github_repository: github_repository,
35
+ environments: environment_hash
36
+ }
37
+ end
38
+
24
39
  def repository
25
40
  @repository ||= get("/pipelines/#{id}/repository")
26
41
  end
@@ -1,3 +1,3 @@
1
1
  module Escobar
2
- VERSION = "0.1.6".freeze
2
+ VERSION = "0.1.7".freeze
3
3
  end
data/lib/escobar.rb CHANGED
@@ -46,7 +46,8 @@ module Escobar
46
46
  end
47
47
 
48
48
  require_relative "./escobar/client"
49
- require_relative "./escobar/github"
49
+ require_relative "./escobar/github/client"
50
+ require_relative "./escobar/github/deployment"
50
51
  require_relative "./escobar/heroku/app"
51
52
  require_relative "./escobar/heroku/client"
52
53
  require_relative "./escobar/heroku/coupling"
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.1.6
4
+ version: 0.1.7
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-03-17 00:00:00.000000000 Z
11
+ date: 2016-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -189,7 +189,8 @@ files:
189
189
  - exe/escobar
190
190
  - lib/escobar.rb
191
191
  - lib/escobar/client.rb
192
- - lib/escobar/github.rb
192
+ - lib/escobar/github/client.rb
193
+ - lib/escobar/github/deployment.rb
193
194
  - lib/escobar/heroku/app.rb
194
195
  - lib/escobar/heroku/client.rb
195
196
  - lib/escobar/heroku/coupling.rb
@@ -1,13 +0,0 @@
1
- module Escobar
2
- # Top-level class for interacting with GitHub API
3
- class GitHub
4
- attr_reader :client
5
- def initialize(token)
6
- @client = Octokit::Client.new(access_token: token)
7
- end
8
-
9
- def whoami
10
- client.get("/user")
11
- end
12
- end
13
- end