buildkiterb 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.env.example +2 -1
  3. data/.github/workflows/ci.yml +2 -2
  4. data/Gemfile +3 -1
  5. data/Gemfile.lock +4 -2
  6. data/README.md +110 -39
  7. data/bin/console +4 -1
  8. data/lib/buildkite/client.rb +52 -53
  9. data/lib/buildkite/configuration.rb +11 -0
  10. data/lib/buildkite/models/access_token.rb +18 -0
  11. data/lib/buildkite/models/agent.rb +23 -0
  12. data/lib/buildkite/models/annotation.rb +14 -0
  13. data/lib/buildkite/models/artifact.rb +33 -0
  14. data/lib/buildkite/models/build.rb +44 -0
  15. data/lib/buildkite/models/cluster.rb +34 -0
  16. data/lib/buildkite/models/cluster_queue.rb +44 -0
  17. data/lib/buildkite/models/cluster_token.rb +34 -0
  18. data/lib/buildkite/models/emoji.rb +14 -0
  19. data/lib/buildkite/models/job.rb +33 -0
  20. data/lib/buildkite/models/organization.rb +19 -0
  21. data/lib/buildkite/models/pipeline.rb +48 -0
  22. data/lib/buildkite/models/user.rb +14 -0
  23. data/lib/buildkite/version.rb +1 -1
  24. data/lib/buildkite.rb +32 -28
  25. metadata +24 -31
  26. data/lib/buildkite/objects/access_token.rb +0 -4
  27. data/lib/buildkite/objects/agent.rb +0 -4
  28. data/lib/buildkite/objects/annotation.rb +0 -4
  29. data/lib/buildkite/objects/artifact.rb +0 -4
  30. data/lib/buildkite/objects/build.rb +0 -4
  31. data/lib/buildkite/objects/emoji.rb +0 -4
  32. data/lib/buildkite/objects/job.rb +0 -4
  33. data/lib/buildkite/objects/organization.rb +0 -4
  34. data/lib/buildkite/objects/pipeline.rb +0 -4
  35. data/lib/buildkite/objects/user.rb +0 -4
  36. data/lib/buildkite/resource.rb +0 -59
  37. data/lib/buildkite/resources/access_token.rb +0 -13
  38. data/lib/buildkite/resources/agents.rb +0 -18
  39. data/lib/buildkite/resources/annotations.rb +0 -10
  40. data/lib/buildkite/resources/artifacts.rb +0 -27
  41. data/lib/buildkite/resources/builds.rb +0 -36
  42. data/lib/buildkite/resources/emojis.rb +0 -10
  43. data/lib/buildkite/resources/jobs.rb +0 -25
  44. data/lib/buildkite/resources/organizations.rb +0 -14
  45. data/lib/buildkite/resources/pipelines.rb +0 -39
  46. data/lib/buildkite/resources/user.rb +0 -9
  47. /data/lib/buildkite/{objects → models}/artifact_download.rb +0 -0
  48. /data/lib/buildkite/{objects → models}/job_env.rb +0 -0
  49. /data/lib/buildkite/{objects → models}/job_log.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d17326f3ed42ef0a798a0716d1fa179f78ed88d9ba50e71577cd5178c3dd01ed
4
- data.tar.gz: 389c4e4a122256db5c50c319ed842102f2590b85feb8ad46bef3074145ca77a1
3
+ metadata.gz: f6ecaa3ffea095a7da23de6dac919c1eef744c42d645d75288ae2a3411f4e10c
4
+ data.tar.gz: 2a03c413f50559febd8d3f4432640153af6e380028a1ba39a42757ec1cb528ea
5
5
  SHA512:
6
- metadata.gz: b9acd806d5629f3ecb086dc388eb3be47eead385a6e74f2b2af3cf7150192c655c559b79a938171aff07af389428d59554ebe9af8e60c2121f14ba3cc7bcaf74
7
- data.tar.gz: 9936c96c5bc35e1d59e4b4d50c53c3d7b440e17762b833d6f477a8f00a18195c6a9a5ad940cb01ffe957e3ac1a79e3d22c815ca808688d7f3d787283f556f84c
6
+ metadata.gz: 8e4d2348ff0f7ab4418e78c5a273b63dce1d441cf50a39cdd6d5dcf5632413aa25d54d55b61cb627f3d56d41b54ec941ecaa526fee633313541e022b17808e2e
7
+ data.tar.gz: f8e8a39511244f94c497b6443d0acc9b7d37c8ef2a375be3ba1ed2df485584c4025153f9577dd38f0d2d7c9b1202c6b67f97a3872e7f96c0d6b7beac44682b82
data/.env.example CHANGED
@@ -1 +1,2 @@
1
- API_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.2.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,164 +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(token: "abc123")
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
34
  ### Access Token
25
35
 
26
36
  ```ruby
27
37
  # Get details of the current token
28
- @client.access_token.get
38
+ Buildkite::AccessToken.retrieve
29
39
 
30
40
  # Revoke the current token
31
- @client.access_token.revoke
41
+ Buildkite::AccessToken.revoke
32
42
  ```
33
43
 
34
44
  ### Organizations
35
45
 
36
46
  ```ruby
37
- # List all of your organizations
38
- @client.organizations.list
39
-
40
47
  # Retrieves an organization
41
- @client.organizations.get slug: "my-org-slug"
48
+ Buildkite::Organization.get slug: "my-org-slug"
42
49
  ```
43
50
 
44
51
  ### Pipelines
45
52
 
46
53
  ```ruby
47
54
  # List all pipelines for an org
48
- @client.pipelines.list org: "org-slug"
55
+ Buildkite::Pipeline.list
49
56
  #=> #<Buildkite::Collection...
50
57
 
51
58
  # Get a pipeline
52
- @client.pipelines.get org: "org-slug", slug: "pipeline-slug"
59
+ Buildkite::Pipeline.retrieve pipeline: "my pipeline"
53
60
 
54
61
  # Create a Pipeline. View the 2 docs links for the correct params
55
62
  # Docs: https://buildkite.com/docs/apis/rest-api/pipelines#create-a-yaml-pipeline
56
63
  # Docs: https://buildkite.com/docs/apis/rest-api/pipelines#create-a-visual-step-pipeline
57
- @client.pipelines.create org: "org-slug", name: "my pipeline", repository: "git@github.com:user/repo.git", configuration: {}
64
+ Buildkite::Pipeline.create name: "my pipeline", repository: "git@github.com:user/repo.git", configuration: {}
58
65
 
59
66
  # Update a pipeline
60
67
  # Docs: https://buildkite.com/docs/apis/rest-api/pipelines#update-a-pipeline
61
- @client.pipelines.update org: "org-slug", slug: "my-pipeline", {}
68
+ Buildkite::Pipeline.update pipeline: "my-pipeline", {}
62
69
 
63
70
  # Archive a pipeline
64
- @client.pipelines.archive org: "org-slug", slug: "my-pipeline"
71
+ Buildkite::Pipeline.archive pipeline: "my-pipeline"
65
72
 
66
73
  # Unarchive a pipeline
67
- @client.pipelines.unarchive org: "org-slug", slug: "my-pipeline"
74
+ Buildkite::Pipeline.unarchive pipeline: "my-pipeline"
68
75
 
69
76
  # Delete a pipeline
70
- @client.pipelines.delete org: "org-slug", slug: "my-pipeline"
77
+ Buildkite::Pipeline.delete pipeline: "my-pipeline"
71
78
 
72
79
  # Setup automatic webhooks
73
80
  # Returns 422 if not supported or cannot be done
74
- @client.pipelines.webhook org: "org-slug", slug: "my-pipeline"
81
+ Buildkite::Pipeline.webhook pipeline: "my-pipeline"
75
82
  ```
76
83
 
77
84
  ### Builds
78
85
 
79
86
  ```ruby
80
87
  # List all builds
81
- @client.builds.list
88
+ Buildkite::Build.list
82
89
 
83
90
  # List all builds for an org
84
- @client.builds.list org: "org-slug"
91
+ Buildkite::Build.list org: "org-slug"
85
92
 
86
93
  # List all builds for a pipeline
87
- @client.builds.list org: "org-slug", pipeline: "pipeline-slug"
94
+ Buildkite::Build.list org: "org-slug", pipeline: "pipeline-slug"
88
95
 
89
96
  # Get a build
90
97
  # The Build Number is used, not the ID
91
- @client.builds.get org: "org-slug", pipeline: "pipeline-slug", number: 123
98
+ Buildkite::Build.retrieve pipeline: "pipeline-slug", number: 123
92
99
 
93
100
  # Create a Build
94
101
  # Docs: https://buildkite.com/docs/apis/rest-api/builds#create-a-build
95
- @client.builds.create org: "org-slug", pipeline: "pipeline-slug", commit: "abc123", branch: "master"
102
+ Buildkite::Build.create pipeline: "pipeline-slug", commit: "abc123", branch: "master"
96
103
 
97
104
  # Cancel a build
98
- @client.builds.cancel org: "org-slug", pipeline: "pipeline-slug", number: 123
105
+ Buildkite::Build.cancel pipeline: "pipeline-slug", number: 123
99
106
 
100
107
  # Rebuild a build
101
- @client.builds.rebuild org: "org-slug", pipeline: "pipeline-slug", number: 123
108
+ Buildkite::Build.rebuild pipeline: "pipeline-slug", number: 123
102
109
  ```
103
110
 
104
111
  ### Agents
105
112
 
106
113
  ```ruby
107
114
  # List all agents for an org
108
- @client.agents.list org: "org-slug"
115
+ Buildkite::Agent.list
109
116
 
110
117
  # Get an agent
111
- @client.agents.get org: "org-slug", id: "abc123"
118
+ Buildkite::Agent.retrieve id: "abc123"
112
119
 
113
120
  # Stop an agent
114
121
  # To force an agent to stop, add `force: true`
115
- @client.agents.get org: "org-slug", id: "abc123"
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"
116
142
  ```
117
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
+
118
189
  ### Jobs
119
190
 
120
191
  ```ruby
121
192
  # Retry a job
122
- @client.jobs.retry org: "org-slug", pipeline: "pipeline-slug", number: 123, job: "abc123"
193
+ Buildkite::Job.retry pipeline: "pipeline-slug", number: 123, job: "abc123"
123
194
 
124
195
  # Unblock a job
125
196
  # Docs: https://buildkite.com/docs/apis/rest-api/jobs#unblock-a-job
126
- @client.jobs.unblock org: "org-slug", pipeline: "pipeline-slug", number: 123, job: "abc123", {}
197
+ Buildkite::Job.unblock pipeline: "pipeline-slug", number: 123, job: "abc123", {}
127
198
 
128
199
  # Get a job's logs
129
- @client.jobs.log org: "org-slug", pipeline: "pipeline-slug", number: 123, job: "abc123"
200
+ Buildkite::Job.log pipeline: "pipeline-slug", number: 123, job: "abc123"
130
201
 
131
202
  # Delete a job's log
132
- @client.jobs.delete_log org: "org-slug", pipeline: "pipeline-slug", number: 123, job: "abc123"
203
+ Buildkite::Job.delete_log pipeline: "pipeline-slug", number: 123, job: "abc123"
133
204
 
134
205
  # Get a job's environment variables
135
- @client.jobs.env org: "org-slug", pipeline: "pipeline-slug", number: 123, job: "abc123"
206
+ Buildkite::Job.env pipeline: "pipeline-slug", number: 123, job: "abc123"
136
207
  ```
137
208
 
138
209
  ### Annotations
139
210
 
140
211
  ```ruby
141
212
  # List annotations for a build
142
- @client.annotations.list org: "org-slug", pipeline: "pipeline-slug", number: 123
213
+ Buildkite::Annotation.list pipeline: "pipeline-slug", number: 123
143
214
  ```
144
215
 
145
216
  ### Artifacts
146
217
 
147
218
  ```ruby
148
219
  # List artifacts for a build
149
- @client.artifacts.list org: "org-slug", pipeline: "pipeline-slug", number: 123
220
+ Buildkite::Artifact.list pipeline: "pipeline-slug", number: 123
150
221
 
151
222
  # List artifacts for a build job
152
- @client.artifacts.list org: "org-slug", pipeline: "pipeline-slug", number: 123, job: "abc123"
223
+ Buildkite::Artifact.list pipeline: "pipeline-slug", number: 123, job: "abc123"
153
224
 
154
225
  # Get an artifact
155
- @client.artifacts.get org: "org-slug", pipeline: "pipeline-slug", number: 123, job: "abc123", id: "123abc"
226
+ Buildkite::Artifact.retrieve pipeline: "pipeline-slug", number: 123, job: "abc123", id: "123abc"
156
227
 
157
228
  # Download an artifact
158
- @client.artifacts.download org: "org-slug", pipeline: "pipeline-slug", number: 123, job: "abc123", id: "123abc"
229
+ Buildkite::Artifact.download pipeline: "pipeline-slug", number: 123, job: "abc123", id: "123abc"
159
230
 
160
231
  # Delete an artifact
161
- @client.artifacts.delete org: "org-slug", pipeline: "pipeline-slug", number: 123, job: "abc123", id: "123abc"
232
+ Buildkite::Artifact.delete pipeline: "pipeline-slug", number: 123, job: "abc123", id: "123abc"
162
233
  ```
163
234
 
164
235
  ### Emojis
165
236
 
166
237
  ```ruby
167
238
  # List emojis for an organization
168
- @client.emojis.list org: "org-slug"
239
+ Buildkite::Emoji.list
169
240
  ```
170
241
 
171
242
  ### User
172
243
 
173
244
  ```ruby
174
245
  # Get the current user
175
- @client.user.get
246
+ Buildkite::User.retrieve
176
247
  ```
177
248
 
178
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(token: ENV["API_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,70 +1,69 @@
1
1
  module Buildkite
2
2
  class Client
3
- BASE_URL = "https://api.buildkite.com/v2"
4
-
5
- attr_reader :token, :adapter
6
-
7
- def initialize(token:, adapter: Faraday.default_adapter, stubs: nil)
8
- @token = token
9
- @adapter = adapter
10
3
 
11
- # Test stubs for requests
12
- @stubs = stubs
13
- end
14
-
15
- def access_token
16
- AccessTokenResource.new(self)
17
- end
4
+ BASE_URL = "https://api.buildkite.com/v2"
18
5
 
19
- def organizations
20
- OrganizationsResource.new(self)
21
- end
6
+ class << self
22
7
 
23
- def pipelines
24
- PipelinesResource.new(self)
25
- end
8
+ def connection
9
+ @connection ||= Faraday.new(BASE_URL) do |conn|
10
+ conn.request :authorization, :Bearer, Buildkite.config.token
26
11
 
27
- def builds
28
- BuildsResource.new(self)
29
- end
12
+ conn.headers = {
13
+ "User-Agent" => "buildkiterb/v#{VERSION} (github.com/deanpcmad/buildkiterb)"
14
+ }
30
15
 
31
- def jobs
32
- JobsResource.new(self)
33
- end
16
+ conn.request :json
34
17
 
35
- def agents
36
- AgentsResource.new(self)
37
- end
38
-
39
- def artifacts
40
- ArtifactsResource.new(self)
41
- end
18
+ conn.response :json, content_type: "application/json"
19
+ end
20
+ end
42
21
 
43
- def annotations
44
- AnnotationsResource.new(self)
45
- end
22
+ def get_request(url, params: {}, headers: {})
23
+ handle_response connection.get(url, params, headers)
24
+ end
46
25
 
47
- def emojis
48
- EmojisResource.new(self)
49
- end
26
+ def post_request(url, body: {}, headers: {})
27
+ handle_response connection.post(url, body, headers)
28
+ end
50
29
 
51
- def user
52
- UserResource.new(self)
53
- end
30
+ def put_request(url, body:, headers: {})
31
+ handle_response connection.put(url, body, headers)
32
+ end
54
33
 
55
- def connection
56
- @connection ||= Faraday.new(BASE_URL) do |conn|
57
- conn.request :authorization, :Bearer, token
58
-
59
- conn.headers = {
60
- "User-Agent" => "buildkiterb/v#{VERSION} (github.com/deanpcmad/buildkiterb)"
61
- }
62
-
63
- conn.request :json
34
+ def patch_request(url, body:, headers: {})
35
+ handle_response connection.patch(url, body, headers)
36
+ end
64
37
 
65
- conn.response :json, content_type: "application/json"
38
+ def delete_request(url, headers: {})
39
+ handle_response connection.delete(url, headers)
40
+ end
66
41
 
67
- conn.adapter adapter, @stubs
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
65
+
66
+ response
68
67
  end
69
68
  end
70
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,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