unofficial_buildkite_client 0.3.0 → 0.4.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afa192680f4d0216d5ac1015671130414f34f4f93fc807564474f41642f89e45
|
4
|
+
data.tar.gz: 2dae276b1a0ec78ec8028434d0a8b1fe892f9efeaef5dc6e94ff263af7842826
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d633d7fec4be055875b5c6960541a03f4e0083c38d4e1534ecf0a2a42d8311248edcd991cdbf0ec1d88088e8383e9a9a152c2d17f96a79c4f068a796edf3f113
|
7
|
+
data.tar.gz: 6e35016d2bfb96837c684207c01046542320acc2e11fd61ebaa528a828e61ec889fca34200d649509aacd45114c9eb326197ec0009597a22e4e5bd94f31026d9
|
data/CHANGELOG.md
CHANGED
data/bin/console
CHANGED
@@ -11,6 +11,8 @@ builds = client.fetch_builds(created_at_from: "2019-04-19T07:00", first: 1, stat
|
|
11
11
|
build = client.fetch_build(number: builds.first[:number])
|
12
12
|
job = build[:jobs].first
|
13
13
|
log = client.fetch_log(build_number: job[:build_number], job_id: job[:id])
|
14
|
+
artifacts = client.fetch_artifacts(build_number: job[:build_number], job_id: job[:id])
|
15
|
+
artifact = client.fetch_artifact(build_number: job[:build_number], job_id: job[:id], artifact_id: artifacts.first[:id])
|
14
16
|
|
15
17
|
Bundler.require
|
16
18
|
Pry.start
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require "unofficial_buildkite_client/version"
|
2
|
-
require "unofficial_buildkite_client/
|
2
|
+
require "unofficial_buildkite_client/http_client"
|
3
3
|
require "logger"
|
4
4
|
|
5
5
|
class UnofficialBuildkiteClient
|
@@ -9,7 +9,7 @@ class UnofficialBuildkiteClient
|
|
9
9
|
INTERNAL_API_HOST = "https://buildkite.com"
|
10
10
|
|
11
11
|
def initialize(access_token: ENV["BUILDKITE_ACCESS_TOKEN"], org_slug: nil, pipeline_slug: nil, logger: Logger.new(STDERR))
|
12
|
-
@client =
|
12
|
+
@client = HttpClient.new(authorization_header: "Bearer #{access_token}", logger: logger)
|
13
13
|
@org_slug = org_slug
|
14
14
|
@pipeline_slug = pipeline_slug
|
15
15
|
end
|
@@ -56,6 +56,14 @@ class UnofficialBuildkiteClient
|
|
56
56
|
@client.request(:get, "#{INTERNAL_API_HOST}/#{org_slug}/#{pipeline_slug}/builds/#{number}")
|
57
57
|
end
|
58
58
|
|
59
|
+
def fetch_artifacts(org_slug: @org_slug, pipeline_slug: @pipeline_slug, build_number:, job_id:)
|
60
|
+
@client.request(:get, "#{INTERNAL_API_HOST}/organizations/#{org_slug}/pipelines/#{pipeline_slug}/builds/#{build_number}/jobs/#{job_id}/artifacts")
|
61
|
+
end
|
62
|
+
|
63
|
+
def fetch_artifact(org_slug: @org_slug, pipeline_slug: @pipeline_slug, build_number:, job_id:, artifact_id:)
|
64
|
+
@client.request(:get, "#{INTERNAL_API_HOST}/organizations/#{org_slug}/pipelines/#{pipeline_slug}/builds/#{build_number}/jobs/#{job_id}/artifacts/#{artifact_id}", json: false)
|
65
|
+
end
|
66
|
+
|
59
67
|
def fetch_log(org_slug: @org_slug, pipeline_slug: @pipeline_slug, build_number:, job_id:)
|
60
68
|
@client.request(:get, "#{INTERNAL_API_HOST}/organizations/#{org_slug}/pipelines/#{pipeline_slug}/builds/#{build_number}/jobs/#{job_id}/log")
|
61
69
|
end
|
@@ -3,18 +3,18 @@ require "uri"
|
|
3
3
|
require "json"
|
4
4
|
|
5
5
|
class UnofficialBuildkiteClient
|
6
|
-
class
|
6
|
+
class HttpClient
|
7
7
|
def initialize(authorization_header: nil, logger:)
|
8
8
|
@authorization_header = authorization_header
|
9
9
|
@logger = logger
|
10
10
|
end
|
11
11
|
|
12
|
-
def request(method, url, params: nil)
|
12
|
+
def request(method, url, params: nil, json: true, auth: true)
|
13
13
|
uri = URI.parse(url)
|
14
14
|
http = Net::HTTP.new(uri.host, uri.port)
|
15
15
|
http.use_ssl = true
|
16
16
|
|
17
|
-
logger.info("method: #{method}
|
17
|
+
logger.info("method: #{method} url: #{url} params: #{params.inspect}")
|
18
18
|
|
19
19
|
request =
|
20
20
|
case method
|
@@ -29,12 +29,23 @@ class UnofficialBuildkiteClient
|
|
29
29
|
raise NotImplementedError
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
request["Content-Type"] = request["Accept"] = "application/json" if json
|
33
|
+
request["Authorization"] = @authorization_header if auth
|
34
|
+
|
35
35
|
response = http.request(request)
|
36
|
-
|
37
|
-
|
36
|
+
|
37
|
+
case response
|
38
|
+
when Net::HTTPSuccess
|
39
|
+
if json
|
40
|
+
JSON.parse(response.body, symbolize_names: true)
|
41
|
+
else
|
42
|
+
response.body
|
43
|
+
end
|
44
|
+
when Net::HTTPRedirection
|
45
|
+
request(:get, response["location"], json: json, auth: false)
|
46
|
+
else
|
47
|
+
response.error!
|
48
|
+
end
|
38
49
|
end
|
39
50
|
|
40
51
|
private
|
@@ -42,12 +53,10 @@ class UnofficialBuildkiteClient
|
|
42
53
|
attr_reader :logger
|
43
54
|
|
44
55
|
def json_headers
|
45
|
-
|
56
|
+
{
|
46
57
|
"Content-Type" => "application/json",
|
47
58
|
"Accept" => "application/json",
|
48
59
|
}
|
49
|
-
h.merge!("Authorization" => @authorization_header)
|
50
|
-
h
|
51
60
|
end
|
52
61
|
end
|
53
62
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unofficial_buildkite_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fumiaki MATSUSHIMA
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,7 +58,7 @@ files:
|
|
58
58
|
- bin/setup
|
59
59
|
- docker-compose.yml
|
60
60
|
- lib/unofficial_buildkite_client.rb
|
61
|
-
- lib/unofficial_buildkite_client/
|
61
|
+
- lib/unofficial_buildkite_client/http_client.rb
|
62
62
|
- lib/unofficial_buildkite_client/version.rb
|
63
63
|
- unofficial_buildkite_client.gemspec
|
64
64
|
homepage: https://github.com/mtsmfm/unofficial_buildkite_client
|