Go to file
Aaron Sky 8af051e8ff Removed Encodable requirement for GraphQL.Content, and added subscripts to JSONValue 2020-05-24 19:29:28 -04:00
.github/workflows Run unit tests on macOS too 2020-05-19 01:38:51 -04:00
.swiftpm/xcode Basic pagination support 2020-05-05 16:52:20 -04:00
Example Renamed Buildkite to BuildkiteClient 2020-05-24 16:38:38 -04:00
Sources/Buildkite Removed Encodable requirement for GraphQL.Content, and added subscripts to JSONValue 2020-05-24 19:29:28 -04:00
Tests Removed Encodable requirement for GraphQL.Content, and added subscripts to JSONValue 2020-05-24 19:29:28 -04:00
.gitignore Corrected some syntax errors in my example code 2020-05-19 09:09:29 -04:00
LICENSE Added support for Buildkite's JSON errors, and wrote more tests for pagination 2020-05-08 10:06:46 -04:00
Package.swift ran swiftlint 2020-05-08 13:17:46 -04:00
README.md Renamed Buildkite to BuildkiteClient 2020-05-24 16:38:38 -04:00

README.md

Buildkite

Build Status

A Swift library and client for the Buildkite REST and GraphQL APIs.

Usage

Add the dependency to your Package.swift file:

let package = Package(
    name: "myproject",
    dependencies: [
        .package(url: "https://github.com/aaronsky/buildkite-swift.git", from: "0.0.3"),
        ],
    targets: [
        .target(
            name: "myproject",
            dependencies: ["Buildkite"]),
        ]
)

As an example, here is a way you can use the closure-based interface to list all pipelines:

import Buildkite

let client = BuildkiteClient()
client.token = "..." // Your scoped Buildkite API access token
client.send(Pipeline.Resources.List(organization: "buildkite")) { result in
    do {
        let response = try result.get()
        let pipelines = response.content
        print(pipelines)
    } catch {
        print(error)
    }
}

You can even use Combine, if you'd like!

import Buildkite

let client = BuildkiteClient()
client.token = "..." // Your scoped Buildkite API access token

var cancellables: Set<AnyCancellable> = []
client.sendPublisher(Pipeline.Resources.List(organization: "buildkite"))
    .map(\.content)
    .sink(receiveCompletion: { _ in }) { pipelines in
        print(pipelines)
    }.store(in: &cancellables)

The entire publicly documented REST API surface is supported by this package.

GraphQL

GraphQL support is present, but currently rudimentary. For example, here's what the same query as above would look like in GraphQL:

import Foundation
import Buildkite

let client = BuildkiteClient()
client.token = "..."

let query = """
query MyPipelines($first: Int!) {
    organization(slug: "buildkite") {
        pipelines(first: $first) {
            edges {
                node {
                    name
                    uuid
                }
            }
        }
    }
}
"""

struct MyPipeline: Codable {
    var organization: Organization?

    struct Organization: Codable {
        var pipelines: Pipelines

        struct Pipelines: Codable {
            var edges: [PipelineEdge]

            struct PipelineEdge: Codable {
                var node: Pipeline

                struct Pipeline: Codable {
                    var name: String
                    var uuid: UUID
                }
            }
        }
    }
}

var cancellables: Set<AnyCancellable> = []
client.sendPublisher(GraphQL<MyPipeline>(rawQuery: query, variables: ["first": 30]))
    .map(\.content)
    .sink(receiveCompletion: { _ in }) { pipelines in
        print(pipelines)
    }.store(in: &cancellables)

References

License

Buildkite for Swift is released under the BSD-2 license. See LICENSE for details.