buildkiterb 0.2.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.env.example +2 -1
  3. data/.github/FUNDING.yml +1 -3
  4. data/.github/workflows/ci.yml +2 -2
  5. data/Gemfile +3 -1
  6. data/Gemfile.lock +5 -3
  7. data/README.md +110 -39
  8. data/bin/console +4 -1
  9. data/lib/buildkite/client.rb +54 -53
  10. data/lib/buildkite/configuration.rb +11 -0
  11. data/lib/buildkite/models/access_token.rb +18 -0
  12. data/lib/buildkite/models/agent.rb +23 -0
  13. data/lib/buildkite/models/annotation.rb +14 -0
  14. data/lib/buildkite/models/artifact.rb +33 -0
  15. data/lib/buildkite/models/build.rb +44 -0
  16. data/lib/buildkite/models/cluster.rb +34 -0
  17. data/lib/buildkite/models/cluster_queue.rb +44 -0
  18. data/lib/buildkite/models/cluster_token.rb +34 -0
  19. data/lib/buildkite/models/emoji.rb +14 -0
  20. data/lib/buildkite/models/job.rb +33 -0
  21. data/lib/buildkite/models/organization.rb +19 -0
  22. data/lib/buildkite/models/pipeline.rb +48 -0
  23. data/lib/buildkite/models/user.rb +14 -0
  24. data/lib/buildkite/version.rb +1 -1
  25. data/lib/buildkite.rb +32 -28
  26. metadata +20 -27
  27. data/lib/buildkite/objects/access_token.rb +0 -4
  28. data/lib/buildkite/objects/agent.rb +0 -4
  29. data/lib/buildkite/objects/annotation.rb +0 -4
  30. data/lib/buildkite/objects/artifact.rb +0 -4
  31. data/lib/buildkite/objects/build.rb +0 -4
  32. data/lib/buildkite/objects/emoji.rb +0 -4
  33. data/lib/buildkite/objects/job.rb +0 -4
  34. data/lib/buildkite/objects/organization.rb +0 -4
  35. data/lib/buildkite/objects/pipeline.rb +0 -4
  36. data/lib/buildkite/objects/user.rb +0 -4
  37. data/lib/buildkite/resource.rb +0 -59
  38. data/lib/buildkite/resources/access_token.rb +0 -13
  39. data/lib/buildkite/resources/agents.rb +0 -18
  40. data/lib/buildkite/resources/annotations.rb +0 -10
  41. data/lib/buildkite/resources/artifacts.rb +0 -27
  42. data/lib/buildkite/resources/builds.rb +0 -36
  43. data/lib/buildkite/resources/emojis.rb +0 -10
  44. data/lib/buildkite/resources/jobs.rb +0 -25
  45. data/lib/buildkite/resources/organizations.rb +0 -14
  46. data/lib/buildkite/resources/pipelines.rb +0 -39
  47. data/lib/buildkite/resources/user.rb +0 -9
  48. /data/lib/buildkite/{objects → models}/artifact_download.rb +0 -0
  49. /data/lib/buildkite/{objects → models}/job_env.rb +0 -0
  50. /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: 484245307221c31727a064c2e1f32fc77cc2819d7e9a00fc14f756f0e873b548
4
+ data.tar.gz: 05e6129c17ead38b64ca8d8517721b9d44eac5d5a348fe0fc1973620dfe52e5a
5
5
  SHA512:
6
- metadata.gz: b9acd806d5629f3ecb086dc388eb3be47eead385a6e74f2b2af3cf7150192c655c559b79a938171aff07af389428d59554ebe9af8e60c2121f14ba3cc7bcaf74
7
- data.tar.gz: 9936c96c5bc35e1d59e4b4d50c53c3d7b440e17762b833d6f477a8f00a18195c6a9a5ad940cb01ffe957e3ac1a79e3d22c815ca808688d7f3d787283f556f84c
6
+ metadata.gz: f90019b496c9de1f7dd84553082ea2a611ae4bea27014a6a2059e83a8fe5511b8e63db14f3a80d7ea377f8b5e33c3d62ea18efac33cbbfb6748b96e0934620c0
7
+ data.tar.gz: 3d0f017e72d3928b61da3d703928a485bdbe99de156c854a4694101024252188bebbe0442287df422ec1579101c94ef6f80e70e400adf7be83e0d1719a01af4a
data/.env.example CHANGED
@@ -1 +1,2 @@
1
- API_TOKEN=
1
+ BUILDKITE_TOKEN=
2
+ BUILDKITE_ORG=
data/.github/FUNDING.yml CHANGED
@@ -1,3 +1 @@
1
- # These are supported funding model platforms
2
-
3
- ko_fi: deanpcmad
1
+ buy_me_a_coffee: deanpcmad
@@ -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.1)
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
- 2.3.21
31
+ 2.5.7
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,71 @@
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 422
55
+ raise Error, "Error 422: Unprocessable Content. '#{response.body["message"]}'"
56
+ when 429
57
+ raise Error, "Error 429: Your request exceeded the API rate limit. '#{response.body["message"]}'"
58
+ when 500
59
+ raise Error, "Error 500: We were unable to perform the request due to server-side problems. '#{response.body["message"]}'"
60
+ when 503
61
+ raise Error, "Error 503: You have been rate limited for sending more than 20 requests per second. '#{response.body["message"]}'"
62
+ when 501
63
+ raise Error, "Error 501: This resource has not been implemented. '#{response.body["message"]}'"
64
+ when 204
65
+ return true
66
+ end
67
+
68
+ response
68
69
  end
69
70
  end
70
71
 
@@ -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