shipyrd 0.2.12 → 0.2.14

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
  SHA256:
3
- metadata.gz: 4dabe0011e5ccdc8b89120b5a9b0a45053b8889b30f18df503a47a6830ac0d05
4
- data.tar.gz: 9d6eb3e80786b3d4b2e8d78eb6f661fbc65549c7d06db4be5fbeccce35893bcf
3
+ metadata.gz: f51f6d4663e34e128254858cacb0c275bcf74e9f86b3b1d38bf4281cc75c327f
4
+ data.tar.gz: 4be800ad91fd2f15ee6b826eacf2dda9e31f3c3660fa86020e6de3903005b5c5
5
5
  SHA512:
6
- metadata.gz: 62220c52b938866e33b67a2927d9b2255687ddd66c04e86415a4d9228cef38e71a3867279e6ea52e00d99b983071d057584417aac050fbfcecbc5848f5cba87b
7
- data.tar.gz: b1a59c0ede51edea372bba60512bfe43668063507e07b9040909f6079a3cd10c4d8d6221a6df0362ab175658e97467daed54e441bd359bb2d8dd775e72f59185
6
+ metadata.gz: b805ab9d7a8391f7a8884e79c199321b89bb42d7fc097601e5a683ba710e3d09d0ca387a977bbdfd250f1150c4d229e7dc823f6201ff882c48c3762ecb5c18e2
7
+ data.tar.gz: 2b6b6e8ad39023ed1c344f6f953312ccd767b66a31a5d9e738a286102426301c61fd9d4db05623a366720c0c6cb03fc139a915fa789387c380e40df140e73247
@@ -25,11 +25,11 @@ class Shipyrd::Client
25
25
  SHIPYRD_SERVICE_VERSION
26
26
  SHIPYRD_SUBCOMMAND
27
27
  SHIPYRD_VERSION
28
- ]
28
+ ].freeze
29
29
 
30
30
  class DestinationBlocked < StandardError; end
31
31
 
32
- def initialize(host: ENV["SHIPYRD_HOST"], api_key: ENV["SHIPYRD_API_KEY"], **options)
32
+ def initialize(host: Shipyrd.configuration.host, api_key: Shipyrd.configuration.api_key, **options)
33
33
  @host = parse_host(host)
34
34
  @api_key = api_key
35
35
  @logger = options[:logger] || Shipyrd::Logger.new
@@ -39,6 +39,7 @@ class Shipyrd::Client
39
39
  def trigger(event)
40
40
  return false unless valid_configuration
41
41
 
42
+ config = Shipyrd.configuration
42
43
  uri = URI("#{host}/deploys.json")
43
44
  headers = {
44
45
  "Content-Type": "application/json",
@@ -48,17 +49,17 @@ class Shipyrd::Client
48
49
  details = {
49
50
  deploy: {
50
51
  status: event,
51
- recorded_at: env_var("RECORDED_AT"),
52
+ recorded_at: config.recorded_at,
52
53
  performer: performer,
53
- commit_message: ENV["SHIPYRD_COMMIT_MESSAGE"] || commit_message,
54
- version: env_var("VERSION"),
55
- service_version: env_var("SERVICE_VERSION"),
56
- hosts: env_var("HOSTS"),
57
- command: env_var("COMMAND"),
58
- subcommand: env_var("SUBCOMMAND"),
59
- role: env_var("ROLE"),
60
- destination: env_var("DESTINATION"),
61
- runtime: env_var("RUNTIME")
54
+ commit_message: config.commit_message || commit_message,
55
+ version: config.version,
56
+ service_version: config.service_version,
57
+ hosts: config.hosts,
58
+ command: config.command,
59
+ subcommand: config.subcommand,
60
+ role: config.role,
61
+ destination: config.destination,
62
+ runtime: config.runtime
62
63
  }
63
64
  }
64
65
 
@@ -96,7 +97,7 @@ class Shipyrd::Client
96
97
  end
97
98
 
98
99
  def performer
99
- github_username.empty? ? env_var("PERFORMER") : "https://github.com/#{github_username}"
100
+ github_username.empty? ? Shipyrd.configuration.performer : "https://github.com/#{github_username}"
100
101
  end
101
102
 
102
103
  def github_username
@@ -106,7 +107,7 @@ class Shipyrd::Client
106
107
  end
107
108
 
108
109
  def commit_message
109
- message = `git show -s --format=%s`.chomp
110
+ message = `git show -s --format=%s --no-show-signature`.chomp
110
111
 
111
112
  if message.length >= 90
112
113
  "#{message[0..90]}..."
@@ -137,10 +138,4 @@ class Shipyrd::Client
137
138
 
138
139
  "https://#{host}"
139
140
  end
140
-
141
- private
142
-
143
- def env_var(name)
144
- ENV["SHIPYRD_#{name}"] || ENV["KAMAL_#{name}"]
145
- end
146
141
  end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Shipyrd::Configuration
4
+ attr_writer :host, :api_key, :commit_message,
5
+ :recorded_at, :performer, :version, :service_version,
6
+ :hosts, :command, :subcommand, :role, :destination, :runtime
7
+
8
+ def host
9
+ @host || ENV["SHIPYRD_HOST"]
10
+ end
11
+
12
+ def api_key
13
+ @api_key || ENV["SHIPYRD_API_KEY"]
14
+ end
15
+
16
+ def commit_message
17
+ @commit_message || ENV["SHIPYRD_COMMIT_MESSAGE"]
18
+ end
19
+
20
+ def recorded_at
21
+ @recorded_at || ENV["SHIPYRD_RECORDED_AT"] || ENV["KAMAL_RECORDED_AT"]
22
+ end
23
+
24
+ def performer
25
+ @performer || ENV["SHIPYRD_PERFORMER"] || ENV["KAMAL_PERFORMER"]
26
+ end
27
+
28
+ def version
29
+ @version || ENV["SHIPYRD_VERSION"] || ENV["KAMAL_VERSION"]
30
+ end
31
+
32
+ def service_version
33
+ @service_version || ENV["SHIPYRD_SERVICE_VERSION"] || ENV["KAMAL_SERVICE_VERSION"]
34
+ end
35
+
36
+ def hosts
37
+ @hosts || ENV["SHIPYRD_HOSTS"] || ENV["KAMAL_HOSTS"]
38
+ end
39
+
40
+ def command
41
+ @command || ENV["SHIPYRD_COMMAND"] || ENV["KAMAL_COMMAND"]
42
+ end
43
+
44
+ def subcommand
45
+ @subcommand || ENV["SHIPYRD_SUBCOMMAND"] || ENV["KAMAL_SUBCOMMAND"]
46
+ end
47
+
48
+ def role
49
+ @role || ENV["SHIPYRD_ROLE"] || ENV["KAMAL_ROLE"]
50
+ end
51
+
52
+ def destination
53
+ @destination || ENV["SHIPYRD_DESTINATION"] || ENV["KAMAL_DESTINATION"]
54
+ end
55
+
56
+ def runtime
57
+ @runtime || ENV["SHIPYRD_RUNTIME"] || ENV["KAMAL_RUNTIME"]
58
+ end
59
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Shipyrd
4
- VERSION = "0.2.12"
4
+ VERSION = "0.2.14"
5
5
  end
data/lib/shipyrd.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "shipyrd/version"
4
+ require_relative "shipyrd/configuration"
4
5
  require "uri"
5
6
  require "net/http"
6
7
  require "json"
@@ -9,4 +10,17 @@ require "shipyrd/client"
9
10
  require "shipyrd/logger"
10
11
 
11
12
  module Shipyrd
13
+ class << self
14
+ def configure
15
+ yield(configuration)
16
+ end
17
+
18
+ def configuration
19
+ @configuration ||= Shipyrd::Configuration.new
20
+ end
21
+
22
+ def reset_configuration!
23
+ @configuration = nil
24
+ end
25
+ end
12
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shipyrd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.2.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Hammond
@@ -25,6 +25,7 @@ files:
25
25
  - Rakefile
26
26
  - lib/shipyrd.rb
27
27
  - lib/shipyrd/client.rb
28
+ - lib/shipyrd/configuration.rb
28
29
  - lib/shipyrd/logger.rb
29
30
  - lib/shipyrd/version.rb
30
31
  - shipyrd.gemspec