Skip to content

Commit a8ade6c

Browse files
authored
[Collections] Add summary and creation timestamp to package version (#3266)
Motivation: It seems useful for package version to have a description and creation timestamp. Modifications: - Add `summary` and `createdAt` to the models - Update collection format doc
1 parent 5667965 commit a8ade6c

File tree

13 files changed

+110
-37
lines changed

13 files changed

+110
-37
lines changed

Fixtures/Collections/JSON/good.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"versions": [
2222
{
2323
"version": "0.1.0",
24+
"summary": "Fixed a few bugs",
2425
"manifests": {
2526
"5.1": {
2627
"toolsVersion": "5.1",
@@ -63,7 +64,8 @@
6364
"license": {
6465
"name": "Apache-2.0",
6566
"url": "https://www.example.com/repos/RepoOne/LICENSE"
66-
}
67+
},
68+
"createdAt": "2020-10-21T09:25:36Z"
6769
}
6870
]
6971
},

Fixtures/Collections/JSON/good_signed.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"versions": [
2222
{
2323
"version": "0.1.0",
24+
"summary": "Fixed a few bugs",
2425
"manifests": {
2526
"5.1": {
2627
"toolsVersion": "5.1",
@@ -63,7 +64,8 @@
6364
"license": {
6465
"name": "Apache-2.0",
6566
"url": "https://www.example.com/repos/RepoOne/LICENSE"
66-
}
67+
},
68+
"createdAt": "2020-10-21T09:25:36Z"
6769
}
6870
]
6971
},

Sources/PackageCollections/Model/Package.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11+
import struct Foundation.Date
1112
import struct Foundation.URL
1213

1314
import PackageModel
@@ -112,6 +113,9 @@ extension PackageCollectionsModel.Package {
112113
/// The version
113114
public let version: TSCUtility.Version
114115

116+
/// Package version description
117+
public let summary: String?
118+
115119
// TODO: remove (replaced by manifests)
116120
public var packageName: String { self.defaultManifest!.packageName }
117121

@@ -145,6 +149,9 @@ extension PackageCollectionsModel.Package {
145149
/// The package version's license
146150
public let license: PackageCollectionsModel.License?
147151

152+
/// When the package version was created
153+
public let createdAt: Date?
154+
148155
public struct Manifest: Equatable, Codable {
149156
/// The Swift tools version specified in `Package.swift`.
150157
public let toolsVersion: ToolsVersion

Sources/PackageCollections/PackageCollections.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,12 @@ public struct PackageCollections: PackageCollectionsProtocol {
439439
basicMetadata: Model.PackageBasicMetadata?) -> Model.Package {
440440
var versions = package.versions.map { packageVersion -> Model.Package.Version in
441441
.init(version: packageVersion.version,
442+
summary: packageVersion.summary,
442443
manifests: packageVersion.manifests,
443444
defaultToolsVersion: packageVersion.defaultToolsVersion,
444445
verifiedCompatibility: packageVersion.verifiedCompatibility,
445-
license: packageVersion.license)
446+
license: packageVersion.license,
447+
createdAt: packageVersion.createdAt)
446448
}
447449
versions.sort(by: >)
448450

Sources/PackageCollections/Providers/JSONPackageCollectionProvider.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,12 @@ struct JSONPackageCollectionProvider: PackageCollectionProvider {
179179
let license = version.license.flatMap { Model.License(from: $0) }
180180

181181
return .init(version: parsedVersion,
182+
summary: version.summary,
182183
manifests: manifests,
183184
defaultToolsVersion: defaultToolsVersion,
184185
verifiedCompatibility: verifiedCompatibility,
185-
license: license)
186+
license: license,
187+
createdAt: version.createdAt)
186188
}
187189
if versions.count != package.versions.count {
188190
serializationOkay = false

Sources/PackageCollectionsModel/Formats/v1.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Each item in the `packages` array is a package object with the following propert
4141
A version object has metadata extracted from `Package.swift` and optionally additional metadata from other sources:
4242

4343
* `version`: The semantic version string.
44+
* `summary`: A description of the package version. **Optional.**
4445
* `manifests`: A non-empty map of manifests by Swift tools version. The keys are (semantic) tools version (more on this below), while the values are:
4546
* `toolsVersion`: The Swift tools version specified in the manifest.
4647
* `packageName`: The name of the package.
@@ -98,6 +99,7 @@ A version object has metadata extracted from `Package.swift` and optionally addi
9899
* `license`: The package version's license. **Optional.**
99100
* `url`: The URL of the license file.
100101
* `name`: License name. [SPDX identifier](https://spdx.org/licenses/) (e.g., `Apache-2.0`, `MIT`, etc.) preferred. Omit if unknown. **Optional.**
102+
* `createdAt`: The ISO 8601-formatted datetime string when the package version was created. **Optional.**
101103

102104
##### Version-specific manifests
103105

@@ -134,6 +136,7 @@ supported by package collections.
134136
"versions": [
135137
{
136138
"version": "0.1.0",
139+
"summary": "Fixed a few bugs",
137140
"manifests": {
138141
"5.1": {
139142
"toolsVersion": "5.1",
@@ -173,7 +176,8 @@ supported by package collections.
173176
"license": {
174177
"name": "Apache-2.0",
175178
"url": "https://www.example.com/repos/RepoOne/LICENSE"
176-
}
179+
},
180+
"createdAt": "2020-10-21T09:25:36Z"
177181
}
178182
]
179183
},

Sources/PackageCollectionsModel/PackageCollectionModel+v1.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extension PackageCollectionModel.V1 {
3434
/// The revision number of this package collection.
3535
public let revision: Int?
3636

37-
/// The ISO 8601-formatted datetime string when the package collection was generated.
37+
/// When the package collection was generated.
3838
public let generatedAt: Date
3939

4040
/// The author of this package collection.
@@ -119,6 +119,9 @@ extension PackageCollectionModel.V1.Collection.Package {
119119
/// The semantic version string.
120120
public let version: String
121121

122+
/// A description of the package version.
123+
public let summary: String?
124+
122125
/// Manifests by tools version.
123126
public let manifests: [String: Manifest]
124127

@@ -131,19 +134,26 @@ extension PackageCollectionModel.V1.Collection.Package {
131134
/// The package version's license.
132135
public let license: PackageCollectionModel.V1.License?
133136

137+
/// When the package version was created.
138+
public let createdAt: Date?
139+
134140
/// Creates a `Version`
135141
public init(
136142
version: String,
143+
summary: String?,
137144
manifests: [String: Manifest],
138145
defaultToolsVersion: String,
139146
verifiedCompatibility: [PackageCollectionModel.V1.Compatibility]?,
140-
license: PackageCollectionModel.V1.License?
147+
license: PackageCollectionModel.V1.License?,
148+
createdAt: Date?
141149
) {
142150
self.version = version
151+
self.summary = summary
143152
self.manifests = manifests
144153
self.defaultToolsVersion = defaultToolsVersion
145154
self.verifiedCompatibility = verifiedCompatibility
146155
self.license = license
156+
self.createdAt = createdAt
147157
}
148158

149159
public struct Manifest: Equatable, Codable {

Tests/PackageCollectionsModelTests/PackageCollectionModelTests.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class PackageCollectionModelTests: XCTestCase {
2525
versions: [
2626
Model.Collection.Package.Version(
2727
version: "1.3.2",
28+
summary: "Fix a few bugs",
2829
manifests: [
2930
"5.2": Model.Collection.Package.Version.Manifest(
3031
toolsVersion: "5.2",
@@ -36,7 +37,8 @@ class PackageCollectionModelTests: XCTestCase {
3637
],
3738
defaultToolsVersion: "5.2",
3839
verifiedCompatibility: [Model.Compatibility(platform: Model.Platform(name: "macOS"), swiftVersion: "5.2")],
39-
license: .init(name: "Apache-2.0", url: URL(string: "https://package-collection-tests.com/repos/foobar/LICENSE")!)
40+
license: .init(name: "Apache-2.0", url: URL(string: "https://package-collection-tests.com/repos/foobar/LICENSE")!),
41+
createdAt: Date()
4042
),
4143
],
4244
readmeURL: URL(string: "https://package-collection-tests.com/repos/foobar/README")!,
@@ -68,6 +70,7 @@ class PackageCollectionModelTests: XCTestCase {
6870
versions: [
6971
Model.Collection.Package.Version(
7072
version: "1.3.2",
73+
summary: "Fix a few bugs",
7174
manifests: [
7275
"5.2": Model.Collection.Package.Version.Manifest(
7376
toolsVersion: "5.2",
@@ -79,7 +82,8 @@ class PackageCollectionModelTests: XCTestCase {
7982
],
8083
defaultToolsVersion: "5.2",
8184
verifiedCompatibility: [Model.Compatibility(platform: Model.Platform(name: "macOS"), swiftVersion: "5.2")],
82-
license: .init(name: "Apache-2.0", url: URL(string: "https://package-collection-tests.com/repos/foobar/LICENSE")!)
85+
license: .init(name: "Apache-2.0", url: URL(string: "https://package-collection-tests.com/repos/foobar/LICENSE")!),
86+
createdAt: Date()
8387
),
8488
],
8589
readmeURL: URL(string: "https://package-collection-tests.com/repos/foobar/README")!,

Tests/PackageCollectionsTests/JSONPackageCollectionProviderTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class JSONPackageCollectionProviderTests: XCTestCase {
6161
XCTAssertEqual(package.license, .init(type: .Apache2_0, url: URL(string: "https://www.example.com/repos/RepoOne/LICENSE")!))
6262
XCTAssertEqual(package.versions.count, 1)
6363
let version = package.versions.first!
64+
XCTAssertEqual(version.summary, "Fixed a few bugs")
6465
let manifest = version.manifests.values.first!
6566
XCTAssertEqual(manifest.packageName, "PackageOne")
6667
XCTAssertEqual(manifest.targets, [.init(name: "Foo", moduleName: "Foo")])
@@ -71,6 +72,7 @@ class JSONPackageCollectionProviderTests: XCTestCase {
7172
XCTAssertEqual(version.verifiedCompatibility!.first!.platform, .macOS)
7273
XCTAssertEqual(version.verifiedCompatibility!.first!.swiftVersion, SwiftLanguageVersion(string: "5.1")!)
7374
XCTAssertEqual(version.license, .init(type: .Apache2_0, url: URL(string: "https://www.example.com/repos/RepoOne/LICENSE")!))
75+
XCTAssertNotNil(version.createdAt)
7476
XCTAssertFalse(collection.isSigned)
7577
}
7678
}
@@ -116,6 +118,7 @@ class JSONPackageCollectionProviderTests: XCTestCase {
116118
XCTAssertEqual(package.license, .init(type: .Apache2_0, url: URL(string: "https://www.example.com/repos/RepoOne/LICENSE")!))
117119
XCTAssertEqual(package.versions.count, 1)
118120
let version = package.versions.first!
121+
XCTAssertEqual(version.summary, "Fixed a few bugs")
119122
let manifest = version.manifests.values.first!
120123
XCTAssertEqual(manifest.packageName, "PackageOne")
121124
XCTAssertEqual(manifest.targets, [.init(name: "Foo", moduleName: "Foo")])
@@ -126,6 +129,7 @@ class JSONPackageCollectionProviderTests: XCTestCase {
126129
XCTAssertEqual(version.verifiedCompatibility!.first!.platform, .macOS)
127130
XCTAssertEqual(version.verifiedCompatibility!.first!.swiftVersion, SwiftLanguageVersion(string: "5.1")!)
128131
XCTAssertEqual(version.license, .init(type: .Apache2_0, url: URL(string: "https://www.example.com/repos/RepoOne/LICENSE")!))
132+
XCTAssertNotNil(version.createdAt)
129133
XCTAssertTrue(collection.isSigned)
130134
let signature = collection.signature!
131135
XCTAssertEqual("Sample Subject", signature.certificate.subject.commonName)

0 commit comments

Comments
 (0)