Skip to content

Commit

Permalink
Adds ability to fetch all builds for a workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
polpielladev committed Mar 17, 2024
1 parent 351ac5d commit cff8a26
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Sources/XcodeCloudKit/Build/Build.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Foundation

public struct Build {
let number: Int?
let id: String
let createdAt: Date?
let endedAt: Date?
let startedAt: Date?
}
14 changes: 14 additions & 0 deletions Sources/XcodeCloudKit/Workflow/RequestBuilder+Workflow.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import AppStoreConnect_Swift_SDK

extension RequestBuilder {
static func allBuilds(for workflowId: String) -> TransportRequest<CiBuildRunsResponse> {
let endpoint = APIEndpoint
.v1
.ciWorkflows
.id(workflowId)
.buildRuns
.get()

return .init(path: endpoint.path, method: endpoint.method, queryParameters: endpoint.query)
}
}
20 changes: 20 additions & 0 deletions Sources/XcodeCloudKit/Workflow/Workflow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,24 @@ public struct Workflow {
let name: String

let transport: Transport

public func allBuilds() async throws -> [Build] {
let allBuilds = try await transport.perform(request: RequestBuilder.allBuilds(for: id))

return allBuilds
.data
.map {
Build(
number: $0.attributes?.number,
id: $0.id,
createdAt: $0.attributes?.createdDate,
endedAt: $0.attributes?.finishedDate,
startedAt: $0.attributes?.startedDate
)
}
}

public func build(with number: Int) async throws -> Build? {
try await allBuilds().first(where: { $0.number == number })
}
}

0 comments on commit cff8a26

Please sign in to comment.