Skip to content

Commit 535aace

Browse files
committed
Move firstCommitDate to GitClient
1 parent 3fa3540 commit 535aace

File tree

12 files changed

+23
-22
lines changed

12 files changed

+23
-22
lines changed

Sources/App/Commands/Analyze.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ extension Analyze {
336336
throw AppError.invalidPackageCachePath(package.model.id, package.model.url)
337337
}
338338

339-
repo.commitCount = (try? await git.commitCount(gitDirectory)) ?? 0
340-
repo.firstCommitDate = try? await Current.git.firstCommitDate(gitDirectory)
339+
repo.commitCount = (try? await git.commitCount(at: gitDirectory)) ?? 0
340+
repo.firstCommitDate = try? await git.firstCommitDate(at: gitDirectory)
341341
repo.lastCommitDate = try? await Current.git.lastCommitDate(gitDirectory)
342342
repo.authors = try? await PackageContributors.extract(gitCacheDirectoryPath: gitDirectory, packageID: package.model.id)
343343

Sources/App/Core/AppEnvironment.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,13 @@ extension AppEnvironment {
4444

4545

4646
struct Git: Sendable {
47-
var firstCommitDate: @Sendable (String) async throws -> Date
4847
var lastCommitDate: @Sendable (String) async throws -> Date
4948
var getTags: @Sendable (String) async throws -> [Reference]
5049
var hasBranch: @Sendable (Reference, String) async throws -> Bool
5150
var revisionInfo: @Sendable (Reference, String) async throws -> RevisionInfo
5251
var shortlog: @Sendable (String) async throws -> String
5352

5453
static let live: Self = .init(
55-
firstCommitDate: { path in try await firstCommitDate(at: path) },
5654
lastCommitDate: { path in try await lastCommitDate(at: path) },
5755
getTags: { path in try await getTags(at: path) },
5856
hasBranch: { ref, path in try await hasBranch(ref, at: path) },

Sources/App/Core/Dependencies/GitClient.swift

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

15+
import Foundation
16+
1517
import Dependencies
1618
import DependenciesMacros
1719
import IssueReporting
@@ -20,13 +22,15 @@ import IssueReporting
2022
@DependencyClient
2123
struct GitClient {
2224
var commitCount: @Sendable (_ at: String) async throws -> Int
25+
var firstCommitDate: @Sendable (_ at: String) async throws -> Date
2326
}
2427

2528

2629
extension GitClient: DependencyKey {
2730
static var liveValue: Self {
2831
.init(
29-
commitCount: { path in try await Git.commitCount(at: path) }
32+
commitCount: { path in try await Git.commitCount(at: path) },
33+
firstCommitDate: { path in try await Git.firstCommitDate(at: path) }
3034
)
3135
}
3236
}

Tests/AppTests/AnalyzeErrorTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ final class AnalyzeErrorTests: AppTestCase {
7373
Repository(package: pkgs[1], defaultBranch: "main", name: "2", owner: "foo"),
7474
].save(on: app.db)
7575

76-
Current.git.firstCommitDate = { @Sendable _ in .t0 }
7776
Current.git.lastCommitDate = { @Sendable _ in .t1 }
7877
Current.git.getTags = { @Sendable checkoutDir in
7978
if checkoutDir.hasSuffix("foo-1") { return [] }
@@ -104,6 +103,7 @@ final class AnalyzeErrorTests: AppTestCase {
104103
$0.date.now = .t0
105104
$0.environment.allowSocialPosts = { true }
106105
$0.git.commitCount = { @Sendable _ in 1 }
106+
$0.git.firstCommitDate = { @Sendable _ in .t0 }
107107
$0.httpClient.mastodonPost = { @Sendable [socialPosts = self.socialPosts] message in
108108
socialPosts.withValue { $0.append(message) }
109109
}

Tests/AppTests/AnalyzerTests.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ class AnalyzerTests: AppTestCase {
223223
$0.environment.loadSPIManifest = { _ in nil }
224224
$0.fileManager.fileExists = { @Sendable _ in true }
225225
$0.git.commitCount = { @Sendable _ in 12 }
226+
$0.git.firstCommitDate = { @Sendable _ in .t0 }
226227
$0.httpClient.mastodonPost = { @Sendable _ in }
227228
} operation: {
228229
// setup
@@ -247,7 +248,6 @@ class AnalyzerTests: AppTestCase {
247248
packageName: "foo-1",
248249
reference: .tag(1, 0, 0)).save(on: app.db)
249250

250-
Current.git.firstCommitDate = { @Sendable _ in .t0 }
251251
Current.git.lastCommitDate = { @Sendable _ in .t2 }
252252
Current.git.getTags = { @Sendable _ in [.tag(1, 0, 0), .tag(1, 1, 1)] }
253253
Current.git.hasBranch = { @Sendable _, _ in true }
@@ -317,14 +317,14 @@ class AnalyzerTests: AppTestCase {
317317
$0.date.now = .now
318318
$0.fileManager.fileExists = { @Sendable _ in true }
319319
$0.git.commitCount = { @Sendable _ in 12 }
320+
$0.git.firstCommitDate = { @Sendable _ in .t0 }
320321
} operation: {
321322
// setup
322323
do {
323324
let pkg = try await savePackage(on: app.db, "https://github.com/foo/1", processingStage: .ingestion)
324325
try await Repository(package: pkg, defaultBranch: "main").save(on: app.db)
325326
}
326327

327-
Current.git.firstCommitDate = { @Sendable _ in .t0 }
328328
Current.git.lastCommitDate = { @Sendable _ in .t1 }
329329
Current.git.hasBranch = { @Sendable _, _ in false } // simulate analysis error via branch mismatch
330330
Current.git.shortlog = { @Sendable _ in "" }
@@ -362,6 +362,7 @@ class AnalyzerTests: AppTestCase {
362362
$0.environment.loadSPIManifest = { _ in nil }
363363
$0.fileManager.fileExists = { @Sendable _ in true }
364364
$0.git.commitCount = { @Sendable _ in 12 }
365+
$0.git.firstCommitDate = { @Sendable _ in .t0 }
365366
} operation: {
366367
// setup
367368
let urls = ["https://github.com/foo/1", "https://github.com/foo/2"]
@@ -371,7 +372,6 @@ class AnalyzerTests: AppTestCase {
371372
}
372373
let lastUpdate = Date()
373374

374-
Current.git.firstCommitDate = { @Sendable _ in .t0 }
375375
Current.git.lastCommitDate = { @Sendable _ in .t1 }
376376
Current.git.getTags = { @Sendable _ in [.tag(1, 0, 0)] }
377377
Current.git.hasBranch = { @Sendable _, _ in true }
@@ -524,9 +524,9 @@ class AnalyzerTests: AppTestCase {
524524
try await withDependencies {
525525
$0.fileManager.fileExists = { @Sendable _ in true }
526526
$0.git.commitCount = { @Sendable _ in 12 }
527+
$0.git.firstCommitDate = { @Sendable _ in .t0 }
527528
} operation: {
528529
// setup
529-
Current.git.firstCommitDate = { @Sendable _ in .t0 }
530530
Current.git.lastCommitDate = { @Sendable _ in .t1 }
531531
Current.git.shortlog = { @Sendable _ in
532532
"""
@@ -897,9 +897,9 @@ class AnalyzerTests: AppTestCase {
897897
$0.environment.loadSPIManifest = { _ in nil }
898898
$0.fileManager.fileExists = { @Sendable _ in true }
899899
$0.git.commitCount = { @Sendable _ in 12 }
900+
$0.git.firstCommitDate = { @Sendable _ in .t0 }
900901
} operation: {
901902
// setup
902-
Current.git.firstCommitDate = { @Sendable _ in .t0 }
903903
Current.git.lastCommitDate = { @Sendable _ in .t1 }
904904
Current.git.getTags = { @Sendable _ in [.tag(1, 0, 0), .tag(2, 0, 0)] }
905905
Current.git.hasBranch = { @Sendable _, _ in true }
@@ -1303,6 +1303,7 @@ class AnalyzerTests: AppTestCase {
13031303
try await withDependencies {
13041304
$0.fileManager.fileExists = { @Sendable _ in true }
13051305
$0.git.commitCount = { @Sendable _ in 2 }
1306+
$0.git.firstCommitDate = { @Sendable _ in .t0 }
13061307
} operation: {
13071308
let pkgId = UUID()
13081309
let pkg = Package(id: pkgId, url: "1".asGithubUrl.url, processingStage: .ingestion)
@@ -1323,7 +1324,6 @@ class AnalyzerTests: AppTestCase {
13231324
latest: .release,
13241325
packageName: "foo-1",
13251326
reference: .tag(1, 0, 0)).save(on: app.db)
1326-
Current.git.firstCommitDate = { @Sendable _ in .t0 }
13271327
Current.git.hasBranch = { @Sendable _, _ in true }
13281328
Current.git.lastCommitDate = { @Sendable _ in .t1 }
13291329
struct Error: Swift.Error { }
@@ -1409,6 +1409,7 @@ class AnalyzerTests: AppTestCase {
14091409
$0.date.now = .now
14101410
$0.fileManager.fileExists = { @Sendable _ in true }
14111411
$0.git.commitCount = { @Sendable _ in 2 }
1412+
$0.git.firstCommitDate = { @Sendable _ in .t0 }
14121413
} operation: {
14131414
let pkgId = UUID()
14141415
let pkg = Package(id: pkgId, url: "1".asGithubUrl.url, processingStage: .ingestion)
@@ -1429,7 +1430,6 @@ class AnalyzerTests: AppTestCase {
14291430
latest: .release,
14301431
packageName: "foo-1",
14311432
reference: .tag(1, 0, 0)).save(on: app.db)
1432-
Current.git.firstCommitDate = { @Sendable _ in .t0 }
14331433
Current.git.hasBranch = { @Sendable _, _ in true }
14341434
Current.git.lastCommitDate = { @Sendable _ in .t1 }
14351435
struct Error: Swift.Error { }
@@ -1520,6 +1520,7 @@ class AnalyzerTests: AppTestCase {
15201520
$0.environment.loadSPIManifest = { _ in nil }
15211521
$0.fileManager.fileExists = { @Sendable _ in true }
15221522
$0.git.commitCount = { @Sendable _ in 12 }
1523+
$0.git.firstCommitDate = { @Sendable _ in .t0 }
15231524
} operation: {
15241525
// setup
15251526
let pkg = try await savePackage(on: app.db, id: .id0, "https://github.com/foo/1".url, processingStage: .ingestion)
@@ -1530,7 +1531,6 @@ class AnalyzerTests: AppTestCase {
15301531
stars: 100).save(on: app.db)
15311532
Current.git.getTags = { @Sendable _ in [] }
15321533
Current.git.hasBranch = { @Sendable _, _ in true }
1533-
Current.git.firstCommitDate = { @Sendable _ in .t0 }
15341534
Current.git.lastCommitDate = { @Sendable _ in .t1 }
15351535
Current.git.revisionInfo = { @Sendable _, _ in .init(commit: "sha1", date: .t0) }
15361536
Current.git.shortlog = { @Sendable _ in "10\tPerson 1" }

Tests/AppTests/IngestionTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ class IngestionTests: AppTestCase {
434434
$0.environment.loadSPIManifest = { _ in nil }
435435
$0.fileManager.fileExists = { @Sendable _ in true }
436436
$0.git.commitCount = { @Sendable _ in 1 }
437+
$0.git.firstCommitDate = { @Sendable _ in .t0 }
437438
} operation: { [db = app.db] in
438-
Current.git.firstCommitDate = { @Sendable _ in .t0 }
439439
Current.git.lastCommitDate = { @Sendable _ in .t0 }
440440
Current.git.getTags = { @Sendable _ in [] }
441441
Current.git.hasBranch = { @Sendable _, _ in true }

Tests/AppTests/MastodonTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ final class MastodonTests: AppTestCase {
2828
$0.environment.loadSPIManifest = { _ in nil }
2929
$0.fileManager.fileExists = { @Sendable _ in true }
3030
$0.git.commitCount = { @Sendable _ in 12 }
31+
$0.git.firstCommitDate = { @Sendable _ in .t0 }
3132
$0.github.fetchLicense = { @Sendable _, _ in nil }
3233
$0.github.fetchMetadata = { @Sendable owner, repository in .mock(owner: owner, repository: repository) }
3334
$0.github.fetchReadme = { @Sendable _, _ in nil }
@@ -41,7 +42,6 @@ final class MastodonTests: AppTestCase {
4142
} operation: {
4243
// setup
4344
let url = "https://github.com/foo/bar"
44-
Current.git.firstCommitDate = { @Sendable _ in .t0 }
4545
Current.git.lastCommitDate = { @Sendable _ in .t2 }
4646
Current.git.getTags = { @Sendable _ in [Reference.tag(1, 2, 3)] }
4747
Current.git.hasBranch = { @Sendable _, _ in true }

Tests/AppTests/Mocks/Git+mock.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
extension Git {
1919
static let mock: Self = .init(
20-
firstCommitDate: { _ in fatalError("not initialized") },
2120
lastCommitDate: { _ in fatalError("not initialized") },
2221
getTags: { _ in fatalError("not initialized") },
2322
hasBranch: { _, _ in fatalError("not initialized") },

Tests/AppTests/PackageController+routesTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,7 @@ class PackageController_routesTests: SnapshotTestCase {
15061506
return true
15071507
}
15081508
$0.git.commitCount = { @Sendable _ in 2}
1509+
$0.git.firstCommitDate = { @Sendable _ in .t0 }
15091510
$0.httpClient.fetchDocumentation = { @Sendable _ in .ok(body: .mockIndexHTML()) }
15101511
$0.timeZone = .utc
15111512
} operation: {
@@ -1522,7 +1523,6 @@ class PackageController_routesTests: SnapshotTestCase {
15221523
reference: .branch("main"))
15231524
.save(on: app.db)
15241525
Current.git = .init(
1525-
firstCommitDate: { _ in .t0 },
15261526
lastCommitDate: { _ in .t1 },
15271527
getTags: { _ in [] },
15281528
hasBranch: { _, _ in true },

Tests/AppTests/PackageTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ final class PackageTests: AppTestCase {
313313
$0.date.now = .now
314314
$0.fileManager.fileExists = { @Sendable _ in true }
315315
$0.git.commitCount = { @Sendable _ in 12 }
316+
$0.git.firstCommitDate = { @Sendable _ in Date(timeIntervalSince1970: 0) }
316317
$0.github.fetchLicense = { @Sendable _, _ in nil }
317318
$0.github.fetchMetadata = { @Sendable owner, repository in .mock(owner: owner, repository: repository) }
318319
$0.github.fetchReadme = { @Sendable _, _ in nil }
@@ -321,7 +322,6 @@ final class PackageTests: AppTestCase {
321322
$0.packageListRepository.fetchCustomCollections = { @Sendable _ in [] }
322323
} operation: {
323324
// setup
324-
Current.git.firstCommitDate = { @Sendable _ in Date(timeIntervalSince1970: 0) }
325325
Current.git.getTags = { @Sendable _ in [] }
326326
Current.git.hasBranch = { @Sendable _, _ in true }
327327
Current.git.lastCommitDate = { @Sendable _ in Date(timeIntervalSince1970: 1) }

0 commit comments

Comments
 (0)