buildkiterb 0.1.0 → 1.0.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: 8c74759ca24a01e1c3014a40e390bf0e6856f6f822afbe9b3ec04ce4eedf47a3
4
- data.tar.gz: 15155f0dd6b2925cd986ca1fe4f800070b14f532b26bdf75dd368c40996afdc0
3
+ metadata.gz: f6ecaa3ffea095a7da23de6dac919c1eef744c42d645d75288ae2a3411f4e10c
4
+ data.tar.gz: 2a03c413f50559febd8d3f4432640153af6e380028a1ba39a42757ec1cb528ea
5
5
  SHA512:
6
- metadata.gz: 6471e3269bedfda857df898a96435d6b71759720880d4707e95ee1e9dd1d1eb54539446c9a05ada092413c7bc67327414781153ffec061dad8136c39d753ae04
7
- data.tar.gz: 1424178e0527a785d2ac7b63d6632ee02fa7b8e19bae68e2a4a02dc15df3e0b04066395ba7de968a9db24df2c4be6f06dbaeb68a73b444e1fff65aa3cffe41be
6
+ metadata.gz: 8e4d2348ff0f7ab4418e78c5a273b63dce1d441cf50a39cdd6d5dcf5632413aa25d54d55b61cb627f3d56d41b54ec941ecaa526fee633313541e022b17808e2e
7
+ data.tar.gz: f8e8a39511244f94c497b6443d0acc9b7d37c8ef2a375be3ba1ed2df485584c4025153f9577dd38f0d2d7c9b1202c6b67f97a3872e7f96c0d6b7beac44682b82
data/.env.example CHANGED
@@ -1 +1,2 @@
1
- ACCESS_TOKEN=
1
+ BUILDKITE_TOKEN=
2
+ BUILDKITE_ORG=
@@ -7,12 +7,12 @@ jobs:
7
7
  fail-fast: false
8
8
  matrix:
9
9
  ruby_version:
10
- - 2.6
11
10
  - 2.7
12
11
  - 3.0
13
12
  - 3.1
13
+ - 3.2
14
14
  steps:
15
- - uses: actions/checkout@v2
15
+ - uses: actions/checkout@v3
16
16
  - uses: ruby/setup-ruby@v1
17
17
  with:
18
18
  ruby-version: ${{ matrix.ruby_version }}
data/Gemfile CHANGED
@@ -5,4 +5,6 @@ gemspec
5
5
 
6
6
  gem "rake", "~> 12.0"
7
7
  gem "minitest", "~> 5.0"
8
- gem "dotenv"
8
+ gem "dotenv"
9
+
10
+ gem "vcr"
data/Gemfile.lock CHANGED
@@ -1,20 +1,21 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- buildkiterb (0.1.0)
4
+ buildkiterb (1.0.0)
5
5
  faraday (~> 2.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  dotenv (2.7.6)
11
- faraday (2.7.4)
11
+ faraday (2.7.10)
12
12
  faraday-net_http (>= 2.0, < 3.1)
13
13
  ruby2_keywords (>= 0.0.4)
14
14
  faraday-net_http (3.0.2)
15
15
  minitest (5.15.0)
16
16
  rake (12.3.3)
17
17
  ruby2_keywords (0.0.5)
18
+ vcr (6.2.0)
18
19
 
19
20
  PLATFORMS
20
21
  ruby
@@ -24,6 +25,7 @@ DEPENDENCIES
24
25
  dotenv
25
26
  minitest (~> 5.0)
26
27
  rake (~> 12.0)
28
+ vcr
27
29
 
28
30
  BUNDLED WITH
29
31
  2.3.21
data/README.md CHANGED
@@ -15,20 +15,235 @@ gem "buildkiterb"
15
15
  ### Set Client Details
16
16
 
17
17
  Firstly you'll need to create an API Token on [Buildkite](https://buildkite.com/user/api-access-tokens)
18
- and then set it like so:
18
+ and then configure it like below.
19
+
20
+ Buildkite tokens are created for a single organization now, so I recommend setting the `org` the same way,
21
+ to tidy up your code.
22
+
23
+ You can optionally set a pipeline too.
19
24
 
20
25
  ```ruby
21
- @client = Buildkite::Client.new(access_token: "")
26
+ Buildkite.configure do |config|
27
+ config.token = ENV["BUILDKITE_TOKEN"]
28
+ config.org = ENV["BUILDKITE_ORG"]
29
+ config.pipeline = ENV["BUILDKITE_PIPELINE"]
30
+ end
31
+
22
32
  ```
23
33
 
24
- ### Organizations
34
+ ### Access Token
25
35
 
26
36
  ```ruby
27
- # List all of your organizations
28
- @client.organizations.list
37
+ # Get details of the current token
38
+ Buildkite::AccessToken.retrieve
39
+
40
+ # Revoke the current token
41
+ Buildkite::AccessToken.revoke
42
+ ```
29
43
 
44
+ ### Organizations
45
+
46
+ ```ruby
30
47
  # Retrieves an organization
31
- @client.organizations.get slug: "my-org-slug"
48
+ Buildkite::Organization.get slug: "my-org-slug"
49
+ ```
50
+
51
+ ### Pipelines
52
+
53
+ ```ruby
54
+ # List all pipelines for an org
55
+ Buildkite::Pipeline.list
56
+ #=> #<Buildkite::Collection...
57
+
58
+ # Get a pipeline
59
+ Buildkite::Pipeline.retrieve pipeline: "my pipeline"
60
+
61
+ # Create a Pipeline. View the 2 docs links for the correct params
62
+ # Docs: https://buildkite.com/docs/apis/rest-api/pipelines#create-a-yaml-pipeline
63
+ # Docs: https://buildkite.com/docs/apis/rest-api/pipelines#create-a-visual-step-pipeline
64
+ Buildkite::Pipeline.create name: "my pipeline", repository: "git@github.com:user/repo.git", configuration: {}
65
+
66
+ # Update a pipeline
67
+ # Docs: https://buildkite.com/docs/apis/rest-api/pipelines#update-a-pipeline
68
+ Buildkite::Pipeline.update pipeline: "my-pipeline", {}
69
+
70
+ # Archive a pipeline
71
+ Buildkite::Pipeline.archive pipeline: "my-pipeline"
72
+
73
+ # Unarchive a pipeline
74
+ Buildkite::Pipeline.unarchive pipeline: "my-pipeline"
75
+
76
+ # Delete a pipeline
77
+ Buildkite::Pipeline.delete pipeline: "my-pipeline"
78
+
79
+ # Setup automatic webhooks
80
+ # Returns 422 if not supported or cannot be done
81
+ Buildkite::Pipeline.webhook pipeline: "my-pipeline"
82
+ ```
83
+
84
+ ### Builds
85
+
86
+ ```ruby
87
+ # List all builds
88
+ Buildkite::Build.list
89
+
90
+ # List all builds for an org
91
+ Buildkite::Build.list org: "org-slug"
92
+
93
+ # List all builds for a pipeline
94
+ Buildkite::Build.list org: "org-slug", pipeline: "pipeline-slug"
95
+
96
+ # Get a build
97
+ # The Build Number is used, not the ID
98
+ Buildkite::Build.retrieve pipeline: "pipeline-slug", number: 123
99
+
100
+ # Create a Build
101
+ # Docs: https://buildkite.com/docs/apis/rest-api/builds#create-a-build
102
+ Buildkite::Build.create pipeline: "pipeline-slug", commit: "abc123", branch: "master"
103
+
104
+ # Cancel a build
105
+ Buildkite::Build.cancel pipeline: "pipeline-slug", number: 123
106
+
107
+ # Rebuild a build
108
+ Buildkite::Build.rebuild pipeline: "pipeline-slug", number: 123
109
+ ```
110
+
111
+ ### Agents
112
+
113
+ ```ruby
114
+ # List all agents for an org
115
+ Buildkite::Agent.list
116
+
117
+ # Get an agent
118
+ Buildkite::Agent.retrieve id: "abc123"
119
+
120
+ # Stop an agent
121
+ # To force an agent to stop, add `force: true`
122
+ Buildkite::Agent.stop id: "abc123"
123
+ ```
124
+
125
+ ### Clusters
126
+
127
+ ```ruby
128
+ # List all clusters for an org
129
+ Buildkite::Cluster.list
130
+
131
+ # Get a cluster
132
+ Buildkite::Cluster.retrieve id: "abc123"
133
+
134
+ # Create a cluster
135
+ Buildkite::Cluster.create name: "Open Source"
136
+
137
+ # Update a cluster
138
+ Buildkite::Cluster.update id: "abc123", description: "A cluster for our Open Source projects"
139
+
140
+ # Delete a cluster
141
+ Buildkite::Cluster.delete id: "abc123"
142
+ ```
143
+
144
+ ### Cluster Queues
145
+
146
+ ```ruby
147
+ # List all queues for a cluster
148
+ Buildkite::ClusterQueue.list cluster: "abc123",
149
+
150
+ # Get a cluster queue
151
+ Buildkite::ClusterQueue.retrieve cluster: "abc123", id: "abc123"
152
+
153
+ # Create a cluster queue
154
+ Buildkite::ClusterQueue.create cluster: "abc123", key: "arm64"
155
+
156
+ # Update a cluster queue
157
+ Buildkite::ClusterQueue.update cluster: "abc123", id: "abc123", description: "For ARM64 builds"
158
+
159
+ # Pause a cluster queue
160
+ Buildkite::ClusterQueue.pause cluster: "abc123", id: "abc123", note: "For maintenance"
161
+
162
+ # Unpause a cluster queue
163
+ Buildkite::ClusterQueue.unpause cluster: "abc123", id: "abc123"
164
+
165
+ # Delete a cluster queue
166
+ Buildkite::ClusterQueue.delete cluster: "abc123", id: "abc123"
167
+ ```
168
+
169
+ ### Cluster Tokens
170
+
171
+ ```ruby
172
+ # List all tokens for a cluster
173
+ Buildkite::ClusterToken.list cluster: "abc123",
174
+
175
+ # Get a cluster token
176
+ Buildkite::ClusterToken.retrieve cluster: "abc123", id: "abc123"
177
+
178
+ # Create a cluster token
179
+ Buildkite::ClusterToken.create cluster: "abc123", description: "Windows Agents"
180
+
181
+ # Update a cluster token
182
+ Buildkite::ClusterToken.update cluster: "abc123", id: "abc123", allowed_ip_addresses: "1.1.1.1"
183
+
184
+ # Delete a cluster token
185
+ Buildkite::ClusterToken.delete cluster: "abc123", id: "abc123"
186
+ ```
187
+
188
+
189
+ ### Jobs
190
+
191
+ ```ruby
192
+ # Retry a job
193
+ Buildkite::Job.retry pipeline: "pipeline-slug", number: 123, job: "abc123"
194
+
195
+ # Unblock a job
196
+ # Docs: https://buildkite.com/docs/apis/rest-api/jobs#unblock-a-job
197
+ Buildkite::Job.unblock pipeline: "pipeline-slug", number: 123, job: "abc123", {}
198
+
199
+ # Get a job's logs
200
+ Buildkite::Job.log pipeline: "pipeline-slug", number: 123, job: "abc123"
201
+
202
+ # Delete a job's log
203
+ Buildkite::Job.delete_log pipeline: "pipeline-slug", number: 123, job: "abc123"
204
+
205
+ # Get a job's environment variables
206
+ Buildkite::Job.env pipeline: "pipeline-slug", number: 123, job: "abc123"
207
+ ```
208
+
209
+ ### Annotations
210
+
211
+ ```ruby
212
+ # List annotations for a build
213
+ Buildkite::Annotation.list pipeline: "pipeline-slug", number: 123
214
+ ```
215
+
216
+ ### Artifacts
217
+
218
+ ```ruby
219
+ # List artifacts for a build
220
+ Buildkite::Artifact.list pipeline: "pipeline-slug", number: 123
221
+
222
+ # List artifacts for a build job
223
+ Buildkite::Artifact.list pipeline: "pipeline-slug", number: 123, job: "abc123"
224
+
225
+ # Get an artifact
226
+ Buildkite::Artifact.retrieve pipeline: "pipeline-slug", number: 123, job: "abc123", id: "123abc"
227
+
228
+ # Download an artifact
229
+ Buildkite::Artifact.download pipeline: "pipeline-slug", number: 123, job: "abc123", id: "123abc"
230
+
231
+ # Delete an artifact
232
+ Buildkite::Artifact.delete pipeline: "pipeline-slug", number: 123, job: "abc123", id: "123abc"
233
+ ```
234
+
235
+ ### Emojis
236
+
237
+ ```ruby
238
+ # List emojis for an organization
239
+ Buildkite::Emoji.list
240
+ ```
241
+
242
+ ### User
243
+
244
+ ```ruby
245
+ # Get the current user
246
+ Buildkite::User.retrieve
32
247
  ```
33
248
 
34
249
  ## Contributing
data/bin/console CHANGED
@@ -13,7 +13,10 @@ require 'dotenv/load'
13
13
  # require "pry"
14
14
  # Pry.start
15
15
 
16
- @client = Buildkite::Client.new(access_token: ENV["ACCESS_TOKEN"])
16
+ Buildkite.configure do |config|
17
+ config.token = ENV["BUILDKITE_TOKEN"]
18
+ config.org = ENV["BUILDKITE_ORG"]
19
+ end
17
20
 
18
21
  require "irb"
19
22
  IRB.start(__FILE__)
@@ -1,34 +1,69 @@
1
1
  module Buildkite
2
2
  class Client
3
+
3
4
  BASE_URL = "https://api.buildkite.com/v2"
4
5
 
5
- attr_reader :access_token, :adapter
6
+ class << self
6
7
 
7
- def initialize(access_token:, adapter: Faraday.default_adapter, stubs: nil)
8
- @access_token = access_token
9
- @adapter = adapter
8
+ def connection
9
+ @connection ||= Faraday.new(BASE_URL) do |conn|
10
+ conn.request :authorization, :Bearer, Buildkite.config.token
10
11
 
11
- # Test stubs for requests
12
- @stubs = stubs
13
- end
12
+ conn.headers = {
13
+ "User-Agent" => "buildkiterb/v#{VERSION} (github.com/deanpcmad/buildkiterb)"
14
+ }
14
15
 
15
- def organizations
16
- OrganizationsResource.new(self)
17
- end
16
+ conn.request :json
17
+
18
+ conn.response :json, content_type: "application/json"
19
+ end
20
+ end
21
+
22
+ def get_request(url, params: {}, headers: {})
23
+ handle_response connection.get(url, params, headers)
24
+ end
18
25
 
19
- def connection
20
- @connection ||= Faraday.new(BASE_URL) do |conn|
21
- conn.request :authorization, :Bearer, access_token
22
-
23
- conn.headers = {
24
- "User-Agent" => "buildkiterb/v#{VERSION} (github.com/deanpcmad/buildkiterb)"
25
- }
26
-
27
- conn.request :json
26
+ def post_request(url, body: {}, headers: {})
27
+ handle_response connection.post(url, body, headers)
28
+ end
29
+
30
+ def put_request(url, body:, headers: {})
31
+ handle_response connection.put(url, body, headers)
32
+ end
33
+
34
+ def patch_request(url, body:, headers: {})
35
+ handle_response connection.patch(url, body, headers)
36
+ end
37
+
38
+ def delete_request(url, headers: {})
39
+ handle_response connection.delete(url, headers)
40
+ end
28
41
 
29
- conn.response :json, content_type: "application/json"
42
+ def handle_response(response)
43
+ case response.status
44
+ when 400
45
+ raise Error, "Error 400: Your request was malformed. '#{response.body["message"]}'"
46
+ when 401
47
+ raise Error, "Error 401: You did not supply valid authentication credentials. '#{response.body["message"]}'"
48
+ when 403
49
+ raise Error, "Error 403: You are not allowed to perform that action. '#{response.body["message"]}'"
50
+ when 404
51
+ raise Error, "Error 404: No results were found for your request. '#{response.body["message"]}'"
52
+ when 409
53
+ raise Error, "Error 409: Your request was a conflict. '#{response.body["message"]}'"
54
+ when 429
55
+ raise Error, "Error 429: Your request exceeded the API rate limit. '#{response.body["message"]}'"
56
+ when 500
57
+ raise Error, "Error 500: We were unable to perform the request due to server-side problems. '#{response.body["message"]}'"
58
+ when 503
59
+ raise Error, "Error 503: You have been rate limited for sending more than 20 requests per second. '#{response.body["message"]}'"
60
+ when 501
61
+ raise Error, "Error 501: This resource has not been implemented. '#{response.body["message"]}'"
62
+ when 204
63
+ return true
64
+ end
30
65
 
31
- conn.adapter adapter, @stubs
66
+ response
32
67
  end
33
68
  end
34
69
 
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Buildkite
4
+ class Configuration
5
+
6
+ attr_accessor :token
7
+ attr_accessor :org
8
+ attr_accessor :pipeline
9
+
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ module Buildkite
2
+ class AccessToken < Object
3
+
4
+ class << self
5
+
6
+ def retrieve
7
+ response = Client.get_request("access-token")
8
+ AccessToken.new response.body
9
+ end
10
+
11
+ def revoke
12
+ Client.delete_request("access-token")
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ module Buildkite
2
+ class Agent < Object
3
+
4
+ class << self
5
+
6
+ def list(org: Buildkite.config.org)
7
+ response = Client.get_request("organizations/#{org}/agents")
8
+ Collection.from_response(response, type: Agent)
9
+ end
10
+
11
+ def retrieve(org: Buildkite.config.org, id:)
12
+ response = Client.get_request("organizations/#{org}/agents/#{id}")
13
+ Agent.new response.body
14
+ end
15
+
16
+ def stop(org: Buildkite.config.org, id:, **args)
17
+ Client.put_request("organizations/#{org}/agents/#{id}/stop", body: args)
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ module Buildkite
2
+ class Annotation < Object
3
+
4
+ class << self
5
+
6
+ def list(org: Buildkite.config.org, pipeline: Buildkite.config.pipeline, build:)
7
+ response = Client.get_request("organizations/#{org}/pipelines/#{pipeline}/builds/#{build}/annotations")
8
+ Collection.from_response(response, type: Annotation)
9
+ end
10
+
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,33 @@
1
+ module Buildkite
2
+ class Artifact < Object
3
+
4
+ class << self
5
+
6
+ def list(org: Buildkite.config.org, pipeline: Buildkite.config.pipeline, build:, job: nil)
7
+ if job
8
+ response = Client.get_request("organizations/#{org}/pipelines/#{pipeline}/builds/#{build}/jobs/#{job}/artifacts")
9
+ else
10
+ response = Client.get_request("organizations/#{org}/pipelines/#{pipeline}/builds/#{build}/artifacts")
11
+ end
12
+
13
+ Collection.from_response(response, type: Artifact)
14
+ end
15
+
16
+ def retrieve(org: Buildkite.config.org, pipeline: Buildkite.config.pipeline, build:, job:, id:)
17
+ response = Client.get_request("organizations/#{org}/pipelines/#{pipeline}/builds/#{build}/jobs/#{job}/artifacts/#{id}")
18
+ Artifact.new response.body
19
+ end
20
+
21
+ def download(org: Buildkite.config.org, pipeline: Buildkite.config.pipeline, build:, job:, id:)
22
+ response = Client.get_request("organizations/#{org}/pipelines/#{pipeline}/builds/#{build}/jobs/#{job}/artifacts/#{id}/download")
23
+ ArtifactDownload.new response.body
24
+ end
25
+
26
+ def delete(org: Buildkite.config.org, pipeline: Buildkite.config.pipeline, build:, job:, id:)
27
+ Client.delete_request("organizations/#{org}/pipelines/#{pipeline}/builds/#{build}/jobs/#{job}/artifacts/#{id}")
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,4 @@
1
+ module Buildkite
2
+ class ArtifactDownload < Object
3
+ end
4
+ end
@@ -0,0 +1,44 @@
1
+ module Buildkite
2
+ class Build < Object
3
+
4
+ class << self
5
+
6
+ def list(org: nil, pipeline: nil)
7
+ if org && pipeline
8
+ response = Client.get_request("organizations/#{org}/pipelines/#{pipeline}/builds")
9
+ elsif org
10
+ response = Client.get_request("organizations/#{org}/builds")
11
+ else
12
+ response = Client.get_request("builds")
13
+ end
14
+
15
+ if response
16
+ Collection.from_response(response, type: Build)
17
+ end
18
+ end
19
+
20
+ def retrieve(org: Buildkite.config.org, pipeline: Buildkite.config.pipeline, number:)
21
+ response = Client.get_request("organizations/#{org}/pipelines/#{pipeline}/builds/#{number}")
22
+ Build.new response.body
23
+ end
24
+
25
+ def create(org: Buildkite.config.org, pipeline: Buildkite.config.pipeline, commit:, branch:, **args)
26
+ data = {commit: commit, branch: branch}
27
+ response = Client.post_request("organizations/#{org}/pipelines/#{pipeline}/builds", body: data.merge(args))
28
+ Build.new response.body
29
+ end
30
+
31
+ def cancel(org: Buildkite.config.org, pipeline: Buildkite.config.pipeline, number:)
32
+ response = Client.put_request("organizations/#{org}/pipelines/#{pipeline}/builds/#{number}/cancel", body: {})
33
+ Build.new response.body
34
+ end
35
+
36
+ def rebuild(org: Buildkite.config.org, pipeline: Buildkite.config.pipeline, number:)
37
+ response = Client.put_request("organizations/#{org}/pipelines/#{pipeline}/builds/#{number}/rebuild", body: {})
38
+ Build.new response.body
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,34 @@
1
+ module Buildkite
2
+ class Cluster < Object
3
+
4
+ class << self
5
+
6
+ def list(org: Buildkite.config.org)
7
+ response = Client.get_request("organizations/#{org}/clusters")
8
+ Collection.from_response(response, type: Cluster)
9
+ end
10
+
11
+ def retrieve(org: Buildkite.config.org, id:)
12
+ response = Client.get_request("organizations/#{org}/clusters/#{id}")
13
+ Cluster.new response.body
14
+ end
15
+
16
+ def create(org: Buildkite.config.org, name:, **args)
17
+ data = {name: name}
18
+ response = Client.post_request("organizations/#{org}/clusters", body: data.merge(args))
19
+ Cluster.new response.body
20
+ end
21
+
22
+ def update(org: Buildkite.config.org, id:, **args)
23
+ response = Client.patch_request("organizations/#{org}/clusters/#{id}", body: args)
24
+ Cluster.new response.body
25
+ end
26
+
27
+ def delete(org: Buildkite.config.org, id:)
28
+ Client.delete_request("organizations/#{org}/clusters/#{id}")
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,44 @@
1
+ module Buildkite
2
+ class ClusterQueue < Object
3
+
4
+ class << self
5
+
6
+ def list(org: Buildkite.config.org, cluster:)
7
+ response = Client.get_request("organizations/#{org}/clusters/#{cluster}/queues")
8
+ Collection.from_response(response, type: ClusterQueue)
9
+ end
10
+
11
+ def retrieve(org: Buildkite.config.org, cluster:, id:)
12
+ response = Client.get_request("organizations/#{org}/clusters/#{cluster}/queues/#{id}")
13
+ ClusterQueue.new response.body
14
+ end
15
+
16
+ def create(org: Buildkite.config.org, cluster:, key:, **args)
17
+ data = {key: key}
18
+ response = Client.post_request("organizations/#{org}/clusters/#{cluster}/queues", body: data.merge(args))
19
+ ClusterQueue.new response.body
20
+ end
21
+
22
+ def update(org: Buildkite.config.org, cluster:, id:, **args)
23
+ response = Client.patch_request("organizations/#{org}/clusters/#{cluster}/queues/#{id}", body: args)
24
+ ClusterQueue.new response.body
25
+ end
26
+
27
+ def pause(org: Buildkite.config.org, cluster:, id:, note: nil)
28
+ response = Client.post_request("organizations/#{org}/clusters/#{cluster}/queues/#{id}/pause_dispatch", body: {note: note})
29
+ ClusterQueue.new response.body
30
+ end
31
+
32
+ def resume(org: Buildkite.config.org, cluster:, id:)
33
+ response = Client.post_request("organizations/#{org}/clusters/#{cluster}/queues/#{id}/resume_dispatch", body: {})
34
+ ClusterQueue.new response.body
35
+ end
36
+
37
+ def delete(org: Buildkite.config.org, cluster:, id:)
38
+ Client.delete_request("organizations/#{org}/clusters/#{cluster}/queues/#{id}")
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,34 @@
1
+ module Buildkite
2
+ class ClusterToken < Object
3
+
4
+ class << self
5
+
6
+ def list(org: Buildkite.config.org, cluster:)
7
+ response = Client.get_request("organizations/#{org}/clusters/#{cluster}/tokens")
8
+ Collection.from_response(response, type: ClusterToken)
9
+ end
10
+
11
+ def retrieve(org: Buildkite.config.org, cluster:, id:)
12
+ response = Client.get_request("organizations/#{org}/clusters/#{cluster}/tokens/#{id}")
13
+ ClusterToken.new response.body
14
+ end
15
+
16
+ def create(org: Buildkite.config.org, cluster:, description:, **args)
17
+ data = {description: description}
18
+ response = Client.post_request("organizations/#{org}/clusters/#{cluster}/tokens", body: data.merge(args))
19
+ ClusterToken.new response.body
20
+ end
21
+
22
+ def update(org: Buildkite.config.org, cluster:, id:, **args)
23
+ response = Client.patch_request("organizations/#{org}/clusters/#{cluster}/tokens/#{id}", body: args)
24
+ ClusterToken.new response.body
25
+ end
26
+
27
+ def delete(org: Buildkite.config.org, cluster:, id:)
28
+ Client.delete_request("organizations/#{org}/clusters/#{cluster}/tokens/#{id}")
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,14 @@
1
+ module Buildkite
2
+ class Emoji < Object
3
+
4
+ class << self
5
+
6
+ def list(org: Buildkite.config.org)
7
+ response = Client.get_request("organizations/#{org}/emojis")
8
+ Collection.from_response(response, type: Emoji)
9
+ end
10
+
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,33 @@
1
+ module Buildkite
2
+ class Job < Object
3
+
4
+ class << self
5
+
6
+ def retry(org: Buildkite.config.org, pipeline: Buildkite.config.pipeline, number:, job:)
7
+ response = Client.put_request("organizations/#{org}/pipelines/#{pipeline}/builds/#{number}/jobs/#{job}/retry", body: {})
8
+ Job.new response.body
9
+ end
10
+
11
+ def unblock(org: Buildkite.config.org, pipeline: Buildkite.config.pipeline, number:, job:, **args)
12
+ response = Client.put_request("organizations/#{org}/pipelines/#{pipeline}/builds/#{number}/jobs/#{job}/unblock", body: args)
13
+ Job.new response.body
14
+ end
15
+
16
+ def log(org: Buildkite.config.org, pipeline: Buildkite.config.pipeline, number:, job:)
17
+ response = Client.get_request("organizations/#{org}/pipelines/#{pipeline}/builds/#{number}/jobs/#{job}/log")
18
+ JobLog.new response.body
19
+ end
20
+
21
+ def delete_log(org: Buildkite.config.org, pipeline: Buildkite.config.pipeline, number:, job:)
22
+ Client.delete_request("organizations/#{org}/pipelines/#{pipeline}/builds/#{number}/jobs/#{job}/log")
23
+ end
24
+
25
+ def env(org: Buildkite.config.org, pipeline: Buildkite.config.pipeline, number:, job:)
26
+ response = Client.get_request("organizations/#{org}/pipelines/#{pipeline}/builds/#{number}/jobs/#{job}/env")
27
+ JobEnv.new response.body["env"]
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,4 @@
1
+ module Buildkite
2
+ class JobEnv < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Buildkite
2
+ class JobLog < Object
3
+ end
4
+ end
@@ -0,0 +1,19 @@
1
+ module Buildkite
2
+ class Organization < Object
3
+
4
+ class << self
5
+
6
+ def list
7
+ response = Client.get_request("organizations")
8
+ Collection.from_response(response, type: Organization)
9
+ end
10
+
11
+ def retrieve(slug:)
12
+ response = Client.get_request("organizations/#{slug}")
13
+ Organization.new(response.body)
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,48 @@
1
+ module Buildkite
2
+ class Pipeline < Object
3
+
4
+ class << self
5
+
6
+ def list(org: Buildkite.config.org)
7
+ response = Client.get_request("organizations/#{org}/pipelines")
8
+ Collection.from_response(response, type: Pipeline)
9
+ end
10
+
11
+ def retrieve(org: Buildkite.config.org, pipeline: Buildkite.config.pipeline)
12
+ response = Client.get_request("organizations/#{org}/pipelines/#{pipeline}")
13
+ Pipeline.new response.body
14
+ end
15
+
16
+ def create(org: Buildkite.config.org, name:, repository:, configuration:, **args)
17
+ data = {name: name, repository: repository, configuration: configuration}
18
+ response = Client.post_request("organizations/#{org}/pipelines", body: data.merge(args))
19
+ Pipeline.new response.body
20
+ end
21
+
22
+ def update(org: Buildkite.config.org, pipeline: Buildkite.config.pipeline, **args)
23
+ response = Client.patch_request("organizations/#{org}/pipelines/#{pipeline}", body: args)
24
+ Pipeline.new response.body
25
+ end
26
+
27
+ def archive(org: Buildkite.config.org, pipeline: Buildkite.config.pipeline)
28
+ response = Client.post_request("organizations/#{org}/pipelines/#{pipeline}/archive", body: {})
29
+ Pipeline.new response.body
30
+ end
31
+
32
+ def unarchive(org: Buildkite.config.org, pipeline: Buildkite.config.pipeline)
33
+ response = Client.post_request("organizations/#{org}/pipelines/#{pipeline}/unarchive", body: {})
34
+ Pipeline.new response.body
35
+ end
36
+
37
+ def delete(org: Buildkite.config.org, pipeline: Buildkite.config.pipeline)
38
+ Client.delete_request("organizations/#{org}/pipelines/#{pipeline}")
39
+ end
40
+
41
+ def webhook(org: Buildkite.config.org, pipeline: Buildkite.config.pipeline)
42
+ Client.post_request("organizations/#{org}/pipelines/#{pipeline}/webhook", body: {})
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,14 @@
1
+ module Buildkite
2
+ class User < Object
3
+
4
+ class << self
5
+
6
+ def retrieve
7
+ response = Client.get_request("user")
8
+ User.new response.body
9
+ end
10
+
11
+ end
12
+
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module Buildkite
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/buildkite.rb CHANGED
@@ -1,18 +1,42 @@
1
1
  require "faraday"
2
- require "json"
3
- require "buildkite/version"
2
+
3
+ require_relative "buildkite/version"
4
4
 
5
5
  module Buildkite
6
6
 
7
+ autoload :Configuration, "buildkite/configuration"
7
8
  autoload :Client, "buildkite/client"
8
9
  autoload :Collection, "buildkite/collection"
9
10
  autoload :Error, "buildkite/error"
10
- autoload :Resource, "buildkite/resource"
11
11
  autoload :Object, "buildkite/object"
12
-
13
12
 
14
- autoload :OrganizationsResource, "buildkite/resources/organizations"
13
+ class << self
14
+ attr_writer :config
15
+ end
16
+
17
+ def self.configure
18
+ yield(config) if block_given?
19
+ end
20
+
21
+ def self.config
22
+ @config ||= Buildkite::Configuration.new
23
+ end
15
24
 
16
- autoload :Organization, "buildkite/objects/organization"
25
+ autoload :AccessToken, "buildkite/models/access_token"
26
+ autoload :Organization, "buildkite/models/organization"
27
+ autoload :Pipeline, "buildkite/models/pipeline"
28
+ autoload :Build, "buildkite/models/build"
29
+ autoload :Job, "buildkite/models/job"
30
+ autoload :JobLog, "buildkite/models/job_log"
31
+ autoload :JobEnv, "buildkite/models/job_env"
32
+ autoload :Agent, "buildkite/models/agent"
33
+ autoload :Cluster, "buildkite/models/cluster"
34
+ autoload :ClusterQueue, "buildkite/models/cluster_queue"
35
+ autoload :ClusterToken, "buildkite/models/cluster_token"
36
+ autoload :Annotation, "buildkite/models/annotation"
37
+ autoload :Artifact, "buildkite/models/artifact"
38
+ autoload :ArtifactDownload, "buildkite/models/artifact_download"
39
+ autoload :Emoji, "buildkite/models/emoji"
40
+ autoload :User, "buildkite/models/user"
17
41
 
18
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buildkiterb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dean Perry
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-06 00:00:00.000000000 Z
11
+ date: 2023-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -24,7 +24,7 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
- description:
27
+ description:
28
28
  email:
29
29
  - dean@deanpcmad.com
30
30
  executables: []
@@ -46,11 +46,25 @@ files:
46
46
  - lib/buildkite.rb
47
47
  - lib/buildkite/client.rb
48
48
  - lib/buildkite/collection.rb
49
+ - lib/buildkite/configuration.rb
49
50
  - lib/buildkite/error.rb
51
+ - lib/buildkite/models/access_token.rb
52
+ - lib/buildkite/models/agent.rb
53
+ - lib/buildkite/models/annotation.rb
54
+ - lib/buildkite/models/artifact.rb
55
+ - lib/buildkite/models/artifact_download.rb
56
+ - lib/buildkite/models/build.rb
57
+ - lib/buildkite/models/cluster.rb
58
+ - lib/buildkite/models/cluster_queue.rb
59
+ - lib/buildkite/models/cluster_token.rb
60
+ - lib/buildkite/models/emoji.rb
61
+ - lib/buildkite/models/job.rb
62
+ - lib/buildkite/models/job_env.rb
63
+ - lib/buildkite/models/job_log.rb
64
+ - lib/buildkite/models/organization.rb
65
+ - lib/buildkite/models/pipeline.rb
66
+ - lib/buildkite/models/user.rb
50
67
  - lib/buildkite/object.rb
51
- - lib/buildkite/objects/organization.rb
52
- - lib/buildkite/resource.rb
53
- - lib/buildkite/resources/organizations.rb
54
68
  - lib/buildkite/version.rb
55
69
  - lib/buildkiterb.rb
56
70
  homepage: https://deanpcmad.com
@@ -59,7 +73,7 @@ licenses:
59
73
  metadata:
60
74
  homepage_uri: https://deanpcmad.com
61
75
  source_code_uri: https://github.com/deanpcmad/buildkiterb
62
- post_install_message:
76
+ post_install_message:
63
77
  rdoc_options: []
64
78
  require_paths:
65
79
  - lib
@@ -74,8 +88,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
88
  - !ruby/object:Gem::Version
75
89
  version: '0'
76
90
  requirements: []
77
- rubygems_version: 3.4.6
78
- signing_key:
91
+ rubygems_version: 3.4.18
92
+ signing_key:
79
93
  specification_version: 4
80
94
  summary: A Ruby library for the Buildkite API
81
95
  test_files: []
@@ -1,4 +0,0 @@
1
- module Buildkite
2
- class Organization < Object
3
- end
4
- end
@@ -1,59 +0,0 @@
1
- module Buildkite
2
- class Resource
3
- attr_reader :client
4
-
5
- def initialize(client)
6
- @client = client
7
- end
8
-
9
- private
10
-
11
- def get_request(url, params: {}, headers: {})
12
- handle_response client.connection.get(url, params, headers)
13
- end
14
-
15
- def post_request(url, body:, headers: {})
16
- handle_response client.connection.post(url, body, headers)
17
- end
18
-
19
- def patch_request(url, body:, headers: {})
20
- handle_response client.connection.patch(url, body, headers)
21
- end
22
-
23
- def put_request(url, body:, headers: {})
24
- handle_response client.connection.put(url, body, headers)
25
- end
26
-
27
- def delete_request(url, params: {}, headers: {})
28
- handle_response client.connection.delete(url, params, headers)
29
- end
30
-
31
- def handle_response(response)
32
- case response.status
33
- when 400
34
- raise Error, "Error 400: Your request was malformed. '#{response.body["message"]}'"
35
- when 401
36
- raise Error, "Error 401: You did not supply valid authentication credentials. '#{response.body["error"]}'"
37
- when 403
38
- raise Error, "Error 403: You are not allowed to perform that action. '#{response.body["error"]}'"
39
- when 404
40
- raise Error, "Error 404: No results were found for your request. '#{response.body["error"]}'"
41
- when 409
42
- raise Error, "Error 409: Your request was a conflict. '#{response.body["message"]}'"
43
- when 422
44
- raise Error, "Error 422: Unprocessable Entity. '#{response.body["message"]}"
45
- when 429
46
- raise Error, "Error 429: Your request exceeded the API rate limit. '#{response.body["error"]}'"
47
- when 500
48
- raise Error, "Error 500: We were unable to perform the request due to server-side problems. '#{response.body["error"]}'"
49
- when 503
50
- raise Error, "Error 503: You have been rate limited for sending more than 20 requests per second. '#{response.body["error"]}'"
51
- when 204
52
- # 204 is a response for success on Twitch's API
53
- return true
54
- end
55
-
56
- response
57
- end
58
- end
59
- end
@@ -1,14 +0,0 @@
1
- module Buildkite
2
- class OrganizationsResource < Resource
3
-
4
- def list
5
- response = get_request("organizations")
6
- Collection.from_response(response, type: Organization)
7
- end
8
-
9
- def get(slug:)
10
- Organization.new get_request("organizations/#{slug}").body
11
- end
12
-
13
- end
14
- end