buildkite-builder 3.6.0 → 3.8.0

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
  SHA256:
3
- metadata.gz: 93d05d1f845781bebfd8b0ad224f1b50ca3d48237817a7ae4391add514dc6103
4
- data.tar.gz: 2c33310049a5c2c47e00813bbc02304c9dd8fe2b8842e013ea03ace5e5e607d0
3
+ metadata.gz: 07cfaad01e1707290fd929b02cdad2b8b0510cfbebbb1ebbed60e6fd81c17fae
4
+ data.tar.gz: a521689c32580d0240f9cc545b8bcce09749ea09eb9922d716bd7d26c7fa0294
5
5
  SHA512:
6
- metadata.gz: 03675ba911feade1199a7ca2b86a7656107160e6b2994f0994a5cc8cc9b1e24e28c6e132f05e335827da1f4c191a7a07854707ba15015348734b67fa078eb2b7
7
- data.tar.gz: ad283bfdeb754f8fb04373d39a9b383e3d66fcfefc51ed41627958b144993d9b21ceec3e8f41af607163334895c3e2f0da0ce02f92b5ab31f6be04ce47240d29
6
+ metadata.gz: 33e4b16b7ec06ee1be8573a6b0ab71503a3311b29bb75e4e0ab7b37a97858a0932654dfae5cf05aa2612db20dc3bebe9d9f9ad444889625ef6bfd1da1107ec27
7
+ data.tar.gz: feeff303efbe6e5aa742da8bd2b540a7518a823ce4d3d9f030a82ffcf6cb77704d74a556c77d0deedc1647230ac5186abad7ba2daa505b6a5dbba788b4e54ef1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.6.0
1
+ 3.8.0
@@ -14,10 +14,12 @@ module Buildkite
14
14
 
15
15
  attr_reader :context
16
16
  attr_reader :options
17
+ attr_reader :option_block
17
18
 
18
- def initialize(context, **options)
19
+ def initialize(context, **options, &block)
19
20
  @context = context
20
21
  @options = options
22
+ @option_block = block
21
23
 
22
24
  prepare
23
25
  end
@@ -32,16 +34,6 @@ module Buildkite
32
34
  context.logger
33
35
  end
34
36
 
35
- def buildkite
36
- @buildkite ||= begin
37
- unless Buildkite.env
38
- raise 'Must be in Buildkite environment to access the Buildkite API'
39
- end
40
-
41
- Buildkite::Pipelines::Api.new(Buildkite.env.api_token)
42
- end
43
- end
44
-
45
37
  def prepare
46
38
  # Override to provide extra functionality.
47
39
  end
@@ -6,26 +6,34 @@ module Buildkite
6
6
 
7
7
  def initialize(context)
8
8
  @context = context
9
- @extensions = []
9
+ @extensions = {}
10
10
 
11
11
  @loader = Loaders::Extensions.load(@context.root)
12
12
  end
13
13
 
14
- def use(extension, native: false, **args)
14
+ def use(extension, native: false, **args, &block)
15
15
  unless extension < Buildkite::Builder::Extension
16
- raise "#{extension} must subclass Buildkite::Builder::Extension"
16
+ raise "#{extension.name} must subclass Buildkite::Builder::Extension"
17
17
  end
18
18
 
19
- @extensions.push(extension.new(@context, **args))
19
+ if @extensions[extension]
20
+ raise "#{extension.name} already registered"
21
+ end
22
+
23
+ @extensions[extension] = extension.new(@context, **args, &block)
20
24
  @context.dsl.extend(extension)
21
25
  end
22
26
 
23
27
  def build
24
- @extensions.each do |extension|
25
- log_build(extension.class.name) { extension.build }
28
+ @extensions.each do |extension_class, extension|
29
+ log_build(extension_class.name) { extension.build }
26
30
  end
27
31
  end
28
32
 
33
+ def find(klass)
34
+ @extensions.fetch(klass)
35
+ end
36
+
29
37
  private
30
38
 
31
39
  def log
@@ -3,8 +3,8 @@ module Buildkite
3
3
  module Extensions
4
4
  class Use < Extension
5
5
  dsl do
6
- def use(extension_class, **args)
7
- context.use(extension_class, **args)
6
+ def use(extension_class, **args, &block)
7
+ context.use(extension_class, **args, &block)
8
8
  end
9
9
  end
10
10
  end
@@ -2,7 +2,6 @@
2
2
 
3
3
  module Buildkite
4
4
  module Pipelines
5
- autoload :Api, File.expand_path('pipelines/api', __dir__)
6
5
  autoload :Attributes, File.expand_path('pipelines/attributes', __dir__)
7
6
  autoload :Command, File.expand_path('pipelines/command', __dir__)
8
7
  autoload :Helpers, File.expand_path('pipelines/helpers', __dir__)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buildkite-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.0
4
+ version: 3.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ngan Pham
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-11-03 00:00:00.000000000 Z
12
+ date: 2022-11-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rainbow
@@ -132,7 +132,6 @@ files:
132
132
  - lib/buildkite/builder/template_manager.rb
133
133
  - lib/buildkite/env.rb
134
134
  - lib/buildkite/pipelines.rb
135
- - lib/buildkite/pipelines/api.rb
136
135
  - lib/buildkite/pipelines/attributes.rb
137
136
  - lib/buildkite/pipelines/command.rb
138
137
  - lib/buildkite/pipelines/helpers.rb
@@ -178,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
177
  - !ruby/object:Gem::Version
179
178
  version: '0'
180
179
  requirements: []
181
- rubygems_version: 3.2.32
180
+ rubygems_version: 3.3.7
182
181
  signing_key:
183
182
  specification_version: 4
184
183
  summary: A gem for programmatically creating Buildkite pipelines.
@@ -1,119 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'uri'
4
- require 'net/http'
5
- require 'json'
6
-
7
- module Buildkite
8
- module Pipelines
9
- class Api
10
- BASE_URI = URI('https://api.buildkite.com/v2').freeze
11
- URI_PARTS = {
12
- organization: 'organizations',
13
- pipeline: 'pipelines',
14
- pipelines: 'pipelines',
15
- build: 'builds',
16
- builds: 'builds',
17
- access_token: 'access-token',
18
- }.freeze
19
-
20
- def initialize(token)
21
- @token = token
22
- end
23
-
24
- def get_access_token
25
- uri = uri_for(access_token: nil)
26
- JSON.parse(get_request(uri).body)
27
- end
28
-
29
- def list_pipelines(organization)
30
- raise NotImplementedError
31
- end
32
-
33
- def get_pipeline(organization, pipeline)
34
- response = get_request(
35
- uri_for(
36
- organization: organization,
37
- pipeline: pipeline
38
- )
39
- )
40
- if response.is_a?(Net::HTTPSuccess)
41
- JSON.parse(response.body)
42
- end
43
- end
44
-
45
- def create_pipeline(organization, params)
46
- uri = uri_for(
47
- organization: organization,
48
- pipelines: nil
49
- )
50
- JSON.parse(post_request(uri, params).body)
51
- end
52
-
53
- def get_pipeline_builds(organization, pipeline, **params)
54
- uri = uri_for(params.merge(
55
- organization: organization,
56
- pipeline: pipeline,
57
- builds: nil
58
- ))
59
- JSON.parse(get_request(uri).body)
60
- end
61
-
62
- def get_build(organization, pipeline, build)
63
- uri = uri_for(
64
- organization: organization,
65
- pipeline: pipeline,
66
- build: build
67
- )
68
- JSON.parse(get_request(uri).body)
69
- end
70
-
71
- def create_build(organization, pipeline)
72
- raise NotImplementedError
73
- end
74
-
75
- def cancel_build(organization, pipeline, build)
76
- raise NotImplementedError
77
- end
78
-
79
- def rebuild_build(organization, pipeline, build)
80
- raise NotImplementedError
81
- end
82
-
83
- private
84
-
85
- def get_request(uri)
86
- Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
87
- request = prepare_request(Net::HTTP::Get.new(uri))
88
- http.request(request)
89
- end
90
- end
91
-
92
- def post_request(uri, data)
93
- Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
94
- request = prepare_request(Net::HTTP::Post.new(uri))
95
- request.content_type = 'application/json'
96
- request.body = data.to_json
97
- http.request(request)
98
- end
99
- end
100
-
101
- def uri_for(options)
102
- uri_parts = URI_PARTS.each_with_object([]) do |(resource, path), parts|
103
- if options.key?(resource)
104
- parts << [path, options.delete(resource)].compact
105
- end
106
- end
107
- uri = URI(uri_parts.flatten.unshift(BASE_URI).join('/'))
108
- uri.query = URI.encode_www_form(options) if options.any?
109
- uri
110
- end
111
-
112
- def prepare_request(request)
113
- request['Authorization'] = "Bearer #{@token}"
114
- request['Accept'] = 'application/json'
115
- request
116
- end
117
- end
118
- end
119
- end