Skip to content

Commit 57096c3

Browse files
authored
Add author to collection package release metadata (#6408) (#6412)
Motivation: Package collection should have information about how a version was created. This includes the creator and timestamp. - "Who created the package version?": added in this PR - "When was the version created?": this is version's `createdAt`, which already exists. rdar://106674475 Modifications: Extract `author` from GitHub API's release data and make it available through package collection's `Package` model.
1 parent e1fd996 commit 57096c3

11 files changed

+62
-23
lines changed

Sources/PackageCollections/Model/PackageTypes.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2020-2021 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -140,6 +140,9 @@ extension PackageCollectionsModel.Package {
140140

141141
/// The package version's license
142142
public let license: PackageCollectionsModel.License?
143+
144+
/// The package version's author
145+
public let author: PackageCollectionsModel.Package.Author?
143146

144147
/// When the package version was created
145148
public let createdAt: Date?

Sources/PackageCollections/PackageCollections.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2020-2022 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -657,6 +657,7 @@ public struct PackageCollections: PackageCollectionsProtocol, Closable {
657657
defaultToolsVersion: packageVersion.defaultToolsVersion,
658658
verifiedCompatibility: packageVersion.verifiedCompatibility,
659659
license: packageVersion.license,
660+
author: versionMetadata?.author,
660661
createdAt: versionMetadata?.createdAt ?? packageVersion.createdAt)
661662
}
662663
versions.sort(by: >)

Sources/PackageCollections/PackageIndex.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2022 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2022-2023 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -262,6 +262,7 @@ extension PackageIndex: PackageMetadataProvider {
262262
version: version.version,
263263
title: version.title,
264264
summary: version.summary,
265+
author: version.author,
265266
createdAt: version.createdAt
266267
)
267268
},

Sources/PackageCollections/Providers/GitHubPackageMetadataProvider.swift

+17-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2020-2022 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -24,6 +24,7 @@ import struct TSCUtility.Version
2424

2525
struct GitHubPackageMetadataProvider: PackageMetadataProvider, Closable {
2626
private static let apiHostPrefix = "api."
27+
private static let service = Model.Package.Author.Service(name: "GitHub")
2728

2829
let configuration: Configuration
2930
private let observabilityScope: ObservabilityScope
@@ -152,12 +153,18 @@ struct GitHubPackageMetadataProvider: PackageMetadataProvider, Closable {
152153
guard let version = $0.tagName.flatMap(TSCUtility.Version.init(tag:)) else {
153154
return nil
154155
}
155-
return Model.PackageBasicVersionMetadata(version: version, title: $0.name, summary: $0.body, createdAt: $0.createdAt)
156+
return Model.PackageBasicVersionMetadata(
157+
version: version,
158+
title: $0.name,
159+
summary: $0.body,
160+
author: $0.author.map { .init(username: $0.login, url: $0.url, service: Self.service) },
161+
createdAt: $0.createdAt
162+
)
156163
},
157164
watchersCount: metadata.watchersCount,
158165
readmeURL: readme?.downloadURL,
159166
license: license.flatMap { .init(type: Model.LicenseType(string: $0.license.spdxID), url: $0.downloadURL) },
160-
authors: contributors?.map { .init(username: $0.login, url: $0.url, service: .init(name: "GitHub")) },
167+
authors: contributors?.map { .init(username: $0.login, url: $0.url, service: Self.service) },
161168
languages: languages.flatMap(Set.init) ?? metadata.language.map { [$0] }
162169
)
163170

@@ -394,13 +401,20 @@ extension GitHubPackageMetadataProvider {
394401
let body: String?
395402
let createdAt: Date
396403
let publishedAt: Date?
404+
let author: Author?
397405

398406
private enum CodingKeys: String, CodingKey {
399407
case name
400408
case tagName = "tag_name"
401409
case body
402410
case createdAt = "created_at"
403411
case publishedAt = "published_at"
412+
case author
413+
}
414+
415+
fileprivate struct Author: Codable {
416+
let login: String
417+
let url: URL?
404418
}
405419
}
406420

Sources/PackageCollections/Providers/JSONPackageCollectionProvider.swift

+1
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ struct JSONPackageCollectionProvider: PackageCollectionProvider {
258258
defaultToolsVersion: defaultToolsVersion,
259259
verifiedCompatibility: verifiedCompatibility,
260260
license: license,
261+
author: nil,
261262
createdAt: version.createdAt)
262263
}
263264
if versions.count != package.versions.count {

Sources/PackageCollections/Providers/PackageMetadataProvider.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2020-2022 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -49,6 +49,7 @@ extension Model {
4949
let version: TSCUtility.Version
5050
let title: String?
5151
let summary: String?
52+
let author: PackageCollectionsModel.Package.Author?
5253
let createdAt: Date?
5354
}
5455
}

Tests/PackageCollectionsTests/GitHubPackageMetadataProviderTests.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2020-2022 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -109,9 +109,11 @@ class GitHubPackageMetadataProviderTests: XCTestCase {
109109
XCTAssertEqual(metadata.versions[0].version, TSCUtility.Version(tag: "v2.0.0"))
110110
XCTAssertEqual(metadata.versions[0].title, "2.0.0")
111111
XCTAssertEqual(metadata.versions[0].summary, "Description of the release")
112+
XCTAssertEqual(metadata.versions[0].author?.username, "octocat")
112113
XCTAssertEqual(metadata.versions[1].version, TSCUtility.Version("1.0.0"))
113114
XCTAssertEqual(metadata.versions[1].title, "1.0.0")
114115
XCTAssertEqual(metadata.versions[1].summary, "Description of the release")
116+
XCTAssertEqual(metadata.versions[1].author?.username, "octocat")
115117
XCTAssertEqual(metadata.authors, [PackageCollectionsModel.Package.Author(username: "octocat",
116118
url: "https://api.github.com/users/octocat",
117119
service: .init(name: "GitHub"))])

Tests/PackageCollectionsTests/PackageCollectionsModelTests.swift

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2020-2022 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -26,11 +26,11 @@ final class PackageCollectionsModelTests: XCTestCase {
2626
toolsVersion: toolsVersion, packageName: "FooBar", targets: targets, products: products, minimumPlatformVersions: nil
2727
)]
2828
let versions: [PackageCollectionsModel.Package.Version] = [
29-
.init(version: .init(stringLiteral: "1.2.0"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, createdAt: nil),
30-
.init(version: .init(stringLiteral: "2.0.1"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, createdAt: nil),
31-
.init(version: .init(stringLiteral: "2.1.0-beta.3"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, createdAt: nil),
32-
.init(version: .init(stringLiteral: "2.1.0"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, createdAt: nil),
33-
.init(version: .init(stringLiteral: "3.0.0-beta.1"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, createdAt: nil),
29+
.init(version: .init(stringLiteral: "1.2.0"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, author: nil, createdAt: nil),
30+
.init(version: .init(stringLiteral: "2.0.1"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, author: nil, createdAt: nil),
31+
.init(version: .init(stringLiteral: "2.1.0-beta.3"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, author: nil, createdAt: nil),
32+
.init(version: .init(stringLiteral: "2.1.0"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, author: nil, createdAt: nil),
33+
.init(version: .init(stringLiteral: "3.0.0-beta.1"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, author: nil, createdAt: nil),
3434
]
3535

3636
XCTAssertEqual("2.1.0", versions.latestRelease?.version.description)
@@ -45,8 +45,8 @@ final class PackageCollectionsModelTests: XCTestCase {
4545
toolsVersion: toolsVersion, packageName: "FooBar", targets: targets, products: products, minimumPlatformVersions: nil
4646
)]
4747
let versions: [PackageCollectionsModel.Package.Version] = [
48-
.init(version: .init(stringLiteral: "2.1.0-beta.3"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, createdAt: nil),
49-
.init(version: .init(stringLiteral: "3.0.0-beta.1"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, createdAt: nil),
48+
.init(version: .init(stringLiteral: "2.1.0-beta.3"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, author: nil, createdAt: nil),
49+
.init(version: .init(stringLiteral: "3.0.0-beta.1"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, author: nil, createdAt: nil),
5050
]
5151

5252
XCTAssertNil(versions.latestRelease)
@@ -61,9 +61,9 @@ final class PackageCollectionsModelTests: XCTestCase {
6161
toolsVersion: toolsVersion, packageName: "FooBar", targets: targets, products: products, minimumPlatformVersions: nil
6262
)]
6363
let versions: [PackageCollectionsModel.Package.Version] = [
64-
.init(version: .init(stringLiteral: "1.2.0"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, createdAt: nil),
65-
.init(version: .init(stringLiteral: "2.0.1"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, createdAt: nil),
66-
.init(version: .init(stringLiteral: "2.1.0"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, createdAt: nil),
64+
.init(version: .init(stringLiteral: "1.2.0"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, author: nil, createdAt: nil),
65+
.init(version: .init(stringLiteral: "2.0.1"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, author: nil, createdAt: nil),
66+
.init(version: .init(stringLiteral: "2.1.0"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, author: nil, createdAt: nil),
6767
]
6868

6969
XCTAssertEqual("2.1.0", versions.latestRelease?.version.description)

Tests/PackageCollectionsTests/PackageCollectionsTests.swift

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2020-2021 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -690,6 +690,7 @@ final class PackageCollectionsTests: XCTestCase {
690690
defaultToolsVersion: toolsVersion,
691691
verifiedCompatibility: nil,
692692
license: nil,
693+
author: nil,
693694
createdAt: nil)
694695

695696
let url = "https://packages.mock/\(UUID().uuidString)"
@@ -857,6 +858,7 @@ final class PackageCollectionsTests: XCTestCase {
857858
defaultToolsVersion: toolsVersion,
858859
verifiedCompatibility: nil,
859860
license: nil,
861+
author: nil,
860862
createdAt: nil)
861863

862864
let mockPackageURL = "https://packages.mock/\(UUID().uuidString)"
@@ -1298,6 +1300,7 @@ final class PackageCollectionsTests: XCTestCase {
12981300
.init(platform: .linux, swiftVersion: SwiftLanguageVersion.knownSwiftLanguageVersions.randomElement()!),
12991301
],
13001302
license: PackageCollectionsModel.License(type: .Apache2_0, url: "http://apache.license"),
1303+
author: .init(username: "\($0)", url: nil, service: nil),
13011304
createdAt: Date())
13021305
}
13031306

@@ -1315,7 +1318,7 @@ final class PackageCollectionsTests: XCTestCase {
13151318

13161319
let mockMetadata = PackageCollectionsModel.PackageBasicMetadata(summary: "\(mockPackage.summary!) 2",
13171320
keywords: mockPackage.keywords.flatMap { $0.map { "\($0)-2" } },
1318-
versions: mockPackage.versions.map { PackageCollectionsModel.PackageBasicVersionMetadata(version: $0.version, title: "\($0.title!) 2", summary: "\($0.summary!) 2", createdAt: Date()) },
1321+
versions: mockPackage.versions.map { PackageCollectionsModel.PackageBasicVersionMetadata(version: $0.version, title: "\($0.title!) 2", summary: "\($0.summary!) 2", author: .init(username: "\(($0.author?.username ?? "") + "2")", url: nil, service: nil), createdAt: Date()) },
13191322
watchersCount: mockPackage.watchersCount! + 1,
13201323
readmeURL: "\(mockPackage.readmeURL!.absoluteString)-2",
13211324
license: PackageCollectionsModel.License(type: .Apache2_0, url: "\(mockPackage.license!.url.absoluteString)-2"),
@@ -1345,6 +1348,7 @@ final class PackageCollectionsTests: XCTestCase {
13451348
XCTAssertEqual(version.verifiedCompatibility, metadataVersion?.verifiedCompatibility, "verifiedCompatibility should match")
13461349
XCTAssertEqual(version.license, metadataVersion?.license, "license should match")
13471350
XCTAssertEqual(mockMetadataVersion?.summary, metadataVersion?.summary, "summary should match")
1351+
XCTAssertEqual(mockMetadataVersion?.author, metadataVersion?.author, "author should match")
13481352
XCTAssertEqual(mockMetadataVersion?.createdAt, metadataVersion?.createdAt, "createdAt should match")
13491353
}
13501354
XCTAssertEqual(metadata.latestVersion, metadata.versions.first, "versions should be sorted")
@@ -1532,6 +1536,7 @@ final class PackageCollectionsTests: XCTestCase {
15321536
defaultToolsVersion: toolsVersion,
15331537
verifiedCompatibility: nil,
15341538
license: nil,
1539+
author: nil,
15351540
createdAt: nil)
15361541

15371542
let mockPackageURL = "https://packages.mock/\(UUID().uuidString)"

0 commit comments

Comments
 (0)