Added Teams endpoint, and fixed file header copyrighting

This commit is contained in:
Aaron Sky 2020-05-07 00:24:33 -04:00
parent 7fbff87651
commit ab1946d778
51 changed files with 256 additions and 50 deletions

View File

@ -1,8 +1,9 @@
//
// Buildkite.swift
//
// Buildkite
//
// Created by Aaron Sky on 3/22/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -3,7 +3,7 @@
// Buildkite
//
// Created by Aaron Sky on 5/3/20.
// Copyright © 2020 Fangamer. All rights reserved.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -3,7 +3,7 @@
// Buildkite
//
// Created by Aaron Sky on 5/3/20.
// Copyright © 2020 Fangamer. All rights reserved.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -3,7 +3,7 @@
// Buildkite
//
// Created by Aaron Sky on 5/3/20.
// Copyright © 2020 Fangamer. All rights reserved.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -3,7 +3,7 @@
// Buildkite
//
// Created by Aaron Sky on 5/3/20.
// Copyright © 2020 Fangamer. All rights reserved.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -3,7 +3,7 @@
// Buildkite
//
// Created by Aaron Sky on 5/3/20.
// Copyright © 2020 Fangamer. All rights reserved.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -3,7 +3,7 @@
// Buildkite
//
// Created by Aaron Sky on 5/3/20.
// Copyright © 2020 Fangamer. All rights reserved.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -3,7 +3,7 @@
// Buildkite
//
// Created by Aaron Sky on 5/3/20.
// Copyright © 2020 Fangamer. All rights reserved.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -3,7 +3,7 @@
// Buildkite
//
// Created by Aaron Sky on 5/3/20.
// Copyright © 2020 Fangamer. All rights reserved.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -3,7 +3,7 @@
// Buildkite
//
// Created by Aaron Sky on 5/3/20.
// Copyright © 2020 Fangamer. All rights reserved.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -0,0 +1,37 @@
//
// Team.swift
// Buildkite
//
// Created by Aaron Sky on 5/3/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
public struct Team: Codable, Equatable {
/// ID of the team
public var id: UUID
/// Name of the team
public var name: String
/// URL slug of the team
public var slug: String
/// Description of the team
public var description: String
/// Privacy setting of the team
public var privacy: Visibility
/// Whether users join this team by default
public var `default`: Bool
/// Time of when the team was created
public var createdAt: Date
/// User who created the team
public var createdBy: User
public enum Visibility: String, Codable, Equatable {
case visible
case secret
}
}

View File

@ -3,7 +3,7 @@
// Buildkite
//
// Created by Aaron Sky on 5/3/20.
// Copyright © 2020 Fangamer. All rights reserved.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// APIVersion.swift
//
// Buildkite
//
// Created by Aaron Sky on 3/22/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// Configuration.swift
//
// Buildkite
//
// Created by Aaron Sky on 3/22/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// Formatters.swift
//
// Buildkite
//
// Created by Aaron Sky on 3/23/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// Pagination.swift
//
// Buildkite
//
// Created by Aaron Sky on 5/5/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// Resource.swift
//
// Buildkite
//
// Created by Aaron Sky on 3/22/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// Response.swift
//
// Buildkite
//
// Created by Aaron Sky on 3/22/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// StatusCode.swift
//
// Buildkite
//
// Created by Aaron Sky on 3/22/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// Transport.swift
//
// Buildkite
//
// Created by Aaron Sky on 3/22/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// URL+Buildkite.swift
//
// Buildkite
//
// Created by Aaron Sky on 5/5/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// AccessTokens.swift
//
// Buildkite
//
// Created by Aaron Sky on 4/21/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// Agents.swift
//
// Buildkite
//
// Created by Aaron Sky on 4/21/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// Annotations.swift
//
// Buildkite
//
// Created by Aaron Sky on 4/21/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// Artifacts.swift
//
// Buildkite
//
// Created by Aaron Sky on 4/21/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// Builds.swift
//
// Buildkite
//
// Created by Aaron Sky on 4/21/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// Emojis.swift
//
// Buildkite
//
// Created by Aaron Sky on 4/21/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// Jobs.swift
//
// Buildkite
//
// Created by Aaron Sky on 4/21/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// Organizations.swift
//
// Buildkite
//
// Created by Aaron Sky on 4/21/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// Pipelines.swift
//
// Buildkite
//
// Created by Aaron Sky on 4/21/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -0,0 +1,53 @@
//
// File.swift
// Buildkite
//
// Created by Aaron Sky on 5/6/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
extension Team {
public enum Resources { }
}
extension Team.Resources {
public struct List: Resource, HasResponseBody {
public typealias Content = [Team]
/// organization slug
public var organization: String
public var userId: UUID?
public var pageOptions: PageOptions?
public var path: String {
"organizations/\(organization)/teams"
}
public init(organization: String, userId: UUID? = nil, pageOptions: PageOptions? = nil) {
self.organization = organization
self.userId = userId
self.pageOptions = pageOptions
}
public func transformRequest(_ request: inout URLRequest) {
guard let url = request.url,
var components = URLComponents(url: url, resolvingAgainstBaseURL: true) else {
return
}
var queryItems: [URLQueryItem] = []
queryItems.appendIfNeeded(userId, forKey: "user_id")
if let options = pageOptions {
queryItems.append(contentsOf: [URLQueryItem](pageOptions: options))
}
components.queryItems = queryItems
request.url = components.url
}
}
}

View File

@ -1,8 +1,9 @@
//
// Users.swift
//
// Buildkite
//
// Created by Aaron Sky on 4/21/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// BuildkiteTests.swift
//
// Buildkite
//
// Created by Aaron Sky on 3/22/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// StatusCodeTests.swift
//
// Buildkite
//
// Created by Aaron Sky on 3/23/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// TransportTests.swift
//
// Buildkite
//
// Created by Aaron Sky on 3/22/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// AccessTokensTests.swift
//
// Buildkite
//
// Created by Aaron Sky on 5/4/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// AgentsTests.swift
//
// Buildkite
//
// Created by Aaron Sky on 5/4/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// AnnotationsTests.swift
//
// Buildkite
//
// Created by Aaron Sky on 5/4/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// ArtifactsTests.swift
//
// Buildkite
//
// Created by Aaron Sky on 5/4/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// BuildsTests.swift
//
// Buildkite
//
// Created by Aaron Sky on 5/4/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation
@ -69,7 +70,7 @@ class BuildsTests: XCTestCase {
finishedFrom: Date(timeIntervalSince1970: 1000),
includeRetriedJobs: true,
metadata: ["buildkite": "is cool"],
state: [.passed]))
state: [.passed, .blocked, .failed]))
let expectation = XCTestExpectation()
@ -89,9 +90,11 @@ class BuildsTests: XCTestCase {
let expected = [Build(), Build()]
let context = try MockContext(content: expected)
let resource = Build.Resources.ListForOrganization(organization: "buildkite", queryOptions: Build.Resources.QueryOptions())
let expectation = XCTestExpectation()
context.client.send(Build.Resources.ListForOrganization(organization: "buildkite")) { result in
context.client.send(resource) { result in
do {
let response = try result.get()
XCTAssertEqual(expected, response.content)

View File

@ -1,8 +1,9 @@
//
// EmojisTests.swift
//
// Buildkite
//
// Created by Aaron Sky on 5/4/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// JobsTests.swift
//
// Buildkite
//
// Created by Aaron Sky on 5/4/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// OrganizationsTests.swift
//
// Buildkite
//
// Created by Aaron Sky on 5/4/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// PipelinesTests.swift
//
// Buildkite
//
// Created by Aaron Sky on 5/4/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation
@ -195,3 +196,31 @@ class PipelinesTests: XCTestCase {
wait(for: [expectation])
}
}
extension PipelinesTests {
private struct EnvVarTestData {
let object: EnvVars = [
"doors": nil,
"boats": .number(1),
"houses": .string("ghosts"),
"rocks": .bool(true),
"horses": .array([
.number(1),
.number(2),
.number(3),
.number(4),
]),
"bigs": .dictionary([
"vending": .string("machine"),
"yes": nil
])
]
}
func testEnvVarDecodeEncode() throws {
let testData = EnvVarTestData()
let data = try JSONEncoder().encode(testData.object)
let object = try JSONDecoder().decode(EnvVars.self, from: data)
XCTAssertEqual(object, testData.object)
}
}

View File

@ -0,0 +1,48 @@
//
// TeamsTests.swift
// Buildkite
//
// Created by Aaron Sky on 5/4/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation
import XCTest
@testable import Buildkite
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
private extension Team {
init() {
self.init(id: UUID(),
name: "",
slug: "",
description: "",
privacy: .visible,
default: true,
createdAt: Date(timeIntervalSince1970: 1000),
createdBy: User())
}
}
class TeamsTests: XCTestCase {
func testTeamsList() throws {
let expected = [Team(), Team()]
let context = try MockContext(content: expected)
let expectation = XCTestExpectation()
context.client.send(Team.Resources.List(organization: "buildkite", userId: UUID(), pageOptions: PageOptions(page: 1, perPage: 30))) { result in
do {
let response = try result.get()
XCTAssertEqual(expected, response.content)
} catch {
XCTFail(error.localizedDescription)
}
expectation.fulfill()
}
wait(for: [expectation])
}
}

View File

@ -1,8 +1,9 @@
//
// UsersTests.swift
//
// Buildkite
//
// Created by Aaron Sky on 5/4/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// MockContext.swift
//
// Buildkite
//
// Created by Aaron Sky on 5/4/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// MockData.swift
//
// Buildkite
//
// Created by Aaron Sky on 3/22/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// MockTransport.swift
//
// Buildkite
//
// Created by Aaron Sky on 3/22/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// URL+Buildkite.swift
//
// Buildkite
//
// Created by Aaron Sky on 5/5/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation

View File

@ -1,8 +1,9 @@
//
// Extensions.swift
//
// Buildkite
//
// Created by Aaron Sky on 3/24/20.
// Copyright © 2020 Aaron Sky. All rights reserved.
//
import Foundation