class UnofficialBuildkiteClient

Constants

GRAPHQL_ENDPOINT
INTERNAL_API_HOST
VERSION

Public Class Methods

new(access_token: ENV["BUILDKITE_ACCESS_TOKEN"], org_slug: nil, pipeline_slug: nil, logger: Logger.new(STDERR)) click to toggle source
# File lib/unofficial_buildkite_client.rb, line 11
def initialize(access_token: ENV["BUILDKITE_ACCESS_TOKEN"], org_slug: nil, pipeline_slug: nil, logger: Logger.new(STDERR))
  @client = HttpClient.new(authorization_header: "Bearer #{access_token}", logger: logger)
  @org_slug = org_slug
  @pipeline_slug = pipeline_slug
end

Public Instance Methods

fetch_artifact(org_slug: @org_slug, pipeline_slug: @pipeline_slug, build_number:, job_id:, artifact_id:) click to toggle source
# File lib/unofficial_buildkite_client.rb, line 64
def fetch_artifact(org_slug: @org_slug, pipeline_slug: @pipeline_slug, build_number:, job_id:, artifact_id:)
  @client.request(:get, "#{INTERNAL_API_HOST}/organizations/#{org_slug}/pipelines/#{pipeline_slug}/builds/#{build_number}/jobs/#{job_id}/artifacts/#{artifact_id}", json: false)
end
fetch_artifacts(org_slug: @org_slug, pipeline_slug: @pipeline_slug, build_number:, job_id:) click to toggle source
# File lib/unofficial_buildkite_client.rb, line 60
def fetch_artifacts(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}/artifacts")
end
fetch_build(org_slug: @org_slug, pipeline_slug: @pipeline_slug, number:) click to toggle source
# File lib/unofficial_buildkite_client.rb, line 56
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: nil, first: nil, last: nil, state: nil) click to toggle source
# File lib/unofficial_buildkite_client.rb, line 17
  def fetch_builds(org_slug: @org_slug, pipeline_slug: @pipeline_slug, created_at_from: nil, first: nil, last: nil, state: nil)
    variables = {slug: "#{org_slug}/#{pipeline_slug}", createdAtFrom: created_at_from, first: first, last: last, state: state}

    post_graphql(<<~GRAPHQL, variables: variables).dig(:data, :pipeline, :builds, :edges).map {|b| b[:node] }
      query ($createdAtFrom: DateTime, $slug: ID!, $first: Int, $last: Int, $state: [BuildStates!]) {
        pipeline(slug: $slug) {
          builds(
            first: $first
            last: $last
            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:) click to toggle source
# File lib/unofficial_buildkite_client.rb, line 68
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: {}) click to toggle source
# File lib/unofficial_buildkite_client.rb, line 72
def post_graphql(query, variables: {})
  @client.request(:post, GRAPHQL_ENDPOINT, params: {query: query, variables: variables})
end