Skip to content

Commit 8f96e29

Browse files
committed
Move Current.triggerBuild to buildSystem.triggerBuild
1 parent 9feeb9c commit 8f96e29

File tree

7 files changed

+101
-95
lines changed

7 files changed

+101
-95
lines changed

Sources/App/Core/AppEnvironment.swift

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ struct AppEnvironment: Sendable {
2929
var logger: @Sendable () -> Logger
3030
var setLogger: @Sendable (Logger) -> Void
3131
var shell: Shell
32-
var triggerBuild: @Sendable (_ client: Client,
33-
_ buildId: Build.Id,
34-
_ cloneURL: String,
35-
_ isDocBuild: Bool,
36-
_ platform: Build.Platform,
37-
_ reference: Reference,
38-
_ swiftVersion: SwiftVersion,
39-
_ versionID: Version.Id) async throws -> Build.TriggerResponse
4032
}
4133

4234

@@ -52,17 +44,7 @@ extension AppEnvironment {
5244
},
5345
logger: { logger },
5446
setLogger: { logger in Self.logger = logger },
55-
shell: .live,
56-
triggerBuild: { client, buildId, cloneURL, isDocBuild, platform, ref, swiftVersion, versionID in
57-
try await Gitlab.Builder.triggerBuild(client: client,
58-
buildId: buildId,
59-
cloneURL: cloneURL,
60-
isDocBuild: isDocBuild,
61-
platform: platform,
62-
reference: ref,
63-
swiftVersion: swiftVersion,
64-
versionID: versionID)
65-
}
47+
shell: .live
6648
)
6749
}
6850

Sources/App/Core/Dependencies/BuildSystemClient.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ import Vapor
2121
struct BuildSystemClient {
2222
#warning("remove client")
2323
var getStatusCount: @Sendable (_ client: Client, _ status: Gitlab.Builder.Status) async throws -> Int
24+
#warning("remove client")
25+
var triggerBuild: @Sendable (_ client: Client,
26+
_ buildId: Build.Id,
27+
_ cloneURL: String,
28+
_ isDocBuild: Bool,
29+
_ platform: Build.Platform,
30+
_ reference: Reference,
31+
_ swiftVersion: SwiftVersion,
32+
_ versionID: Version.Id) async throws -> Build.TriggerResponse
2433
}
2534

2635

@@ -33,6 +42,16 @@ extension BuildSystemClient: DependencyKey {
3342
page: 1,
3443
pageSize: 100,
3544
maxPageCount: 5)
45+
},
46+
triggerBuild: { client, buildId, cloneURL, isDocBuild, platform, ref, swiftVersion, versionID in
47+
try await Gitlab.Builder.triggerBuild(client: client,
48+
buildId: buildId,
49+
cloneURL: cloneURL,
50+
isDocBuild: isDocBuild,
51+
platform: platform,
52+
reference: ref,
53+
swiftVersion: swiftVersion,
54+
versionID: versionID)
3655
}
3756
)
3857
}

Sources/App/Models/Build.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import Dependencies
1516
import Fluent
1617
import PostgresKit
1718
import Vapor
@@ -186,14 +187,16 @@ extension Build {
186187
.with(\.$package)
187188
.first()
188189
.unwrap(or: Abort(.notFound))
189-
return try await Current.triggerBuild(client,
190-
buildId,
191-
version.package.url,
192-
isDocBuild,
193-
platform,
194-
version.reference,
195-
swiftVersion,
196-
versionId)
190+
191+
@Dependency(\.buildSystem) var buildSystem
192+
return try await buildSystem.triggerBuild(client,
193+
buildId,
194+
version.package.url,
195+
isDocBuild,
196+
platform,
197+
version.reference,
198+
swiftVersion,
199+
versionId)
197200
}
198201

199202
}

Tests/AppTests/BuildTests.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,9 @@ class BuildTests: AppTestCase {
135135
$0.environment.buildTimeout = { 10 }
136136
$0.environment.gitlabPipelineToken = { "pipeline token" }
137137
$0.environment.siteURL = { "http://example.com" }
138-
} operation: {
139-
// setup
140-
let p = try await savePackage(on: app.db, "1")
141-
let v = try Version(package: p, reference: .branch("main"))
142-
try await v.save(on: app.db)
143-
let buildId = UUID()
144-
let versionID = try XCTUnwrap(v.id)
145-
146138
// Use live dependency but replace actual client with a mock so we can
147139
// assert on the details being sent without actually making a request
148-
Current.triggerBuild = { client, buildId, cloneURL, isDocBuild, platform, ref, swiftVersion, versionID in
140+
$0.buildSystem.triggerBuild = { @Sendable client, buildId, cloneURL, isDocBuild, platform, ref, swiftVersion, versionID in
149141
try await Gitlab.Builder.triggerBuild(client: client,
150142
buildId: buildId,
151143
cloneURL: cloneURL,
@@ -155,6 +147,14 @@ class BuildTests: AppTestCase {
155147
swiftVersion: swiftVersion,
156148
versionID: versionID)
157149
}
150+
} operation: {
151+
// setup
152+
let p = try await savePackage(on: app.db, "1")
153+
let v = try Version(package: p, reference: .branch("main"))
154+
try await v.save(on: app.db)
155+
let buildId = UUID()
156+
let versionID = try XCTUnwrap(v.id)
157+
158158
var called = false
159159
let client = MockClient { req, res in
160160
called = true
@@ -203,19 +203,9 @@ class BuildTests: AppTestCase {
203203
$0.environment.buildTimeout = { 10 }
204204
$0.environment.gitlabPipelineToken = { "pipeline token" }
205205
$0.environment.siteURL = { "http://example.com" }
206-
} operation: {
207-
// Same test as test_trigger above, except we trigger with isDocBuild: true
208-
// and expect a 15m TIMEOUT instead of 10m
209-
// setup
210-
let p = try await savePackage(on: app.db, "1")
211-
let v = try Version(package: p, reference: .branch("main"))
212-
try await v.save(on: app.db)
213-
let buildId = UUID()
214-
let versionID = try XCTUnwrap(v.id)
215-
216206
// Use live dependency but replace actual client with a mock so we can
217207
// assert on the details being sent without actually making a request
218-
Current.triggerBuild = { client, buildId, cloneURL, isDocBuild, platform, ref, swiftVersion, versionID in
208+
$0.buildSystem.triggerBuild = { @Sendable client, buildId, cloneURL, isDocBuild, platform, ref, swiftVersion, versionID in
219209
try await Gitlab.Builder.triggerBuild(client: client,
220210
buildId: buildId,
221211
cloneURL: cloneURL,
@@ -225,6 +215,16 @@ class BuildTests: AppTestCase {
225215
swiftVersion: swiftVersion,
226216
versionID: versionID)
227217
}
218+
} operation: {
219+
// Same test as test_trigger above, except we trigger with isDocBuild: true
220+
// and expect a 15m TIMEOUT instead of 10m
221+
// setup
222+
let p = try await savePackage(on: app.db, "1")
223+
let v = try Version(package: p, reference: .branch("main"))
224+
try await v.save(on: app.db)
225+
let buildId = UUID()
226+
let versionID = try XCTUnwrap(v.id)
227+
228228
var called = false
229229
let client = MockClient { req, res in
230230
called = true

0 commit comments

Comments
 (0)