Class: UnofficialBuildkiteClient
- Inherits:
-
Object
- Object
- UnofficialBuildkiteClient
- Defined in:
- lib/unofficial_buildkite_client.rb,
lib/unofficial_buildkite_client/version.rb,
lib/unofficial_buildkite_client/json_api_client.rb
Defined Under Namespace
Classes: Error, JsonApiClient
Constant Summary collapse
- GRAPHQL_ENDPOINT =
"https://graphql.buildkite.com/v1"- INTERNAL_API_HOST =
"https://buildkite.com"- VERSION =
"0.1.0"
Class Method Summary collapse
Instance Method Summary collapse
- #fetch_build(org_slug: @org_slug, pipeline_slug: @pipeline_slug, number:) ⇒ Object
- #fetch_builds(org_slug: @org_slug, pipeline_slug: @pipeline_slug, created_at_from:, first:, state:) ⇒ Object
- #fetch_log(org_slug: @org_slug, pipeline_slug: @pipeline_slug, build_number:, job_id:) ⇒ Object
-
#initialize(access_token: ENV["BUILDKITE_ACCESS_TOKEN"], org_slug: nil, pipeline_slug: nil) ⇒ UnofficialBuildkiteClient
constructor
A new instance of UnofficialBuildkiteClient.
- #post_graphql(query, variables: {}) ⇒ Object
Constructor Details
#initialize(access_token: ENV["BUILDKITE_ACCESS_TOKEN"], org_slug: nil, pipeline_slug: nil) ⇒ UnofficialBuildkiteClient
Returns a new instance of UnofficialBuildkiteClient.
22 23 24 25 26 |
# File 'lib/unofficial_buildkite_client.rb', line 22 def initialize(access_token: ENV["BUILDKITE_ACCESS_TOKEN"], org_slug: nil, pipeline_slug: nil) @client = JsonApiClient.new(authorization_header: "Bearer #{access_token}") @org_slug = org_slug @pipeline_slug = pipeline_slug end |
Class Method Details
.logger ⇒ Object
12 13 14 |
# File 'lib/unofficial_buildkite_client.rb', line 12 def logger @logger end |
.logger=(logger) ⇒ Object
8 9 10 |
# File 'lib/unofficial_buildkite_client.rb', line 8 def logger=(logger) @logger = logger end |
Instance Method Details
#fetch_build(org_slug: @org_slug, pipeline_slug: @pipeline_slug, number:) ⇒ Object
66 67 68 |
# File 'lib/unofficial_buildkite_client.rb', line 66 def fetch_build(org_slug: @org_slug, pipeline_slug: @pipeline_slug, number:) @client.request(:get, "#{INTERNAL_API_HOST}/#{org_slug}/#{pipeline_slug}/builds/#{number}") end |
#fetch_builds(org_slug: @org_slug, pipeline_slug: @pipeline_slug, created_at_from:, first:, state:) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/unofficial_buildkite_client.rb', line 28 def fetch_builds(org_slug: @org_slug, pipeline_slug: @pipeline_slug, created_at_from:, first:, state:) variables = {slug: "#{org_slug}/#{pipeline_slug}", createdAtFrom: created_at_from, first: first, state: state} post_graphql(<<~GRAPHQL, variables: variables).dig(:data, :pipeline, :builds, :edges).map {|b| b[:node] } query ($createdAtFrom: DateTime, $slug: ID!, $first: Int, $state: [BuildStates!]) { pipeline(slug: $slug) { builds( first: $first state: $state createdAtFrom: $createdAtFrom ) { edges { node { branch canceledAt commit createdAt env finishedAt id message number scheduledAt source { name } startedAt state url uuid } } } } } GRAPHQL end |
#fetch_log(org_slug: @org_slug, pipeline_slug: @pipeline_slug, build_number:, job_id:) ⇒ Object
70 71 72 |
# File 'lib/unofficial_buildkite_client.rb', line 70 def fetch_log(org_slug: @org_slug, pipeline_slug: @pipeline_slug, build_number:, job_id:) @client.request(:get, "#{INTERNAL_API_HOST}/organizations/#{org_slug}/pipelines/#{pipeline_slug}/builds/#{build_number}/jobs/#{job_id}/log") end |
#post_graphql(query, variables: {}) ⇒ Object
74 75 76 |
# File 'lib/unofficial_buildkite_client.rb', line 74 def post_graphql(query, variables: {}) @client.request(:post, GRAPHQL_ENDPOINT, params: {query: query, variables: variables}) end |