Skip to content

Commit 6a9010d

Browse files
committed
Add author to collection package release metadata
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 5d83b59 commit 6a9010d

8 files changed

+39
-9
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/Utility.swift

+8-1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func makeMockPackage(id: String) -> PackageCollectionsModel.Package {
102102
defaultToolsVersion: toolsVersion,
103103
verifiedCompatibility: verifiedCompatibility,
104104
license: license,
105+
author: nil,
105106
createdAt: Date())
106107
}
107108

@@ -120,7 +121,13 @@ func makeMockPackage(id: String) -> PackageCollectionsModel.Package {
120121
func makeMockPackageBasicMetadata() -> PackageCollectionsModel.PackageBasicMetadata {
121122
return .init(summary: UUID().uuidString,
122123
keywords: (0 ..< Int.random(in: 1 ... 3)).map { "keyword \($0)" },
123-
versions: (0 ..< Int.random(in: 1 ... 10)).map { .init(version: TSCUtility.Version($0, 0, 0), title: "title \($0)", summary: "description \($0)", createdAt: Date()) },
124+
versions: (0 ..< Int.random(in: 1 ... 10)).map { .init(
125+
version: TSCUtility.Version($0, 0, 0),
126+
title: "title \($0)",
127+
summary: "description \($0)",
128+
author: nil,
129+
createdAt: Date()
130+
)},
124131
watchersCount: Int.random(in: 0 ... 50),
125132
readmeURL: "https://package-readme",
126133
license: PackageCollectionsModel.License(type: .Apache2_0, url: "https://package-license"),

0 commit comments

Comments
 (0)