Skip to content

Add author to collection package release metadata #6408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Sources/PackageCollections/Model/PackageTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2020-2021 Apple Inc. and the Swift project authors
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -140,6 +140,9 @@ extension PackageCollectionsModel.Package {

/// The package version's license
public let license: PackageCollectionsModel.License?

/// The package version's author
public let author: PackageCollectionsModel.Package.Author?

/// When the package version was created
public let createdAt: Date?
Expand Down
3 changes: 2 additions & 1 deletion Sources/PackageCollections/PackageCollections.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2020-2022 Apple Inc. and the Swift project authors
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -657,6 +657,7 @@ public struct PackageCollections: PackageCollectionsProtocol, Closable {
defaultToolsVersion: packageVersion.defaultToolsVersion,
verifiedCompatibility: packageVersion.verifiedCompatibility,
license: packageVersion.license,
author: versionMetadata?.author,
createdAt: versionMetadata?.createdAt ?? packageVersion.createdAt)
}
versions.sort(by: >)
Expand Down
3 changes: 2 additions & 1 deletion Sources/PackageCollections/PackageIndex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2022 Apple Inc. and the Swift project authors
// Copyright (c) 2022-2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -262,6 +262,7 @@ extension PackageIndex: PackageMetadataProvider {
version: version.version,
title: version.title,
summary: version.summary,
author: version.author,
createdAt: version.createdAt
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2020-2022 Apple Inc. and the Swift project authors
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand All @@ -24,6 +24,7 @@ import struct TSCUtility.Version

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

let configuration: Configuration
private let observabilityScope: ObservabilityScope
Expand Down Expand Up @@ -152,12 +153,18 @@ struct GitHubPackageMetadataProvider: PackageMetadataProvider, Closable {
guard let version = $0.tagName.flatMap(TSCUtility.Version.init(tag:)) else {
return nil
}
return Model.PackageBasicVersionMetadata(version: version, title: $0.name, summary: $0.body, createdAt: $0.createdAt)
return Model.PackageBasicVersionMetadata(
version: version,
title: $0.name,
summary: $0.body,
author: $0.author.map { .init(username: $0.login, url: $0.url, service: Self.service) },
createdAt: $0.createdAt
)
},
watchersCount: metadata.watchersCount,
readmeURL: readme?.downloadURL,
license: license.flatMap { .init(type: Model.LicenseType(string: $0.license.spdxID), url: $0.downloadURL) },
authors: contributors?.map { .init(username: $0.login, url: $0.url, service: .init(name: "GitHub")) },
authors: contributors?.map { .init(username: $0.login, url: $0.url, service: Self.service) },
languages: languages.flatMap(Set.init) ?? metadata.language.map { [$0] }
)

Expand Down Expand Up @@ -394,13 +401,20 @@ extension GitHubPackageMetadataProvider {
let body: String?
let createdAt: Date
let publishedAt: Date?
let author: Author?

private enum CodingKeys: String, CodingKey {
case name
case tagName = "tag_name"
case body
case createdAt = "created_at"
case publishedAt = "published_at"
case author
}

fileprivate struct Author: Codable {
let login: String
let url: URL?
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ struct JSONPackageCollectionProvider: PackageCollectionProvider {
defaultToolsVersion: defaultToolsVersion,
verifiedCompatibility: verifiedCompatibility,
license: license,
author: nil,
createdAt: version.createdAt)
}
if versions.count != package.versions.count {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2020-2022 Apple Inc. and the Swift project authors
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -49,6 +49,7 @@ extension Model {
let version: TSCUtility.Version
let title: String?
let summary: String?
let author: PackageCollectionsModel.Package.Author?
let createdAt: Date?
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2020-2022 Apple Inc. and the Swift project authors
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -109,9 +109,11 @@ class GitHubPackageMetadataProviderTests: XCTestCase {
XCTAssertEqual(metadata.versions[0].version, TSCUtility.Version(tag: "v2.0.0"))
XCTAssertEqual(metadata.versions[0].title, "2.0.0")
XCTAssertEqual(metadata.versions[0].summary, "Description of the release")
XCTAssertEqual(metadata.versions[0].author?.username, "octocat")
XCTAssertEqual(metadata.versions[1].version, TSCUtility.Version("1.0.0"))
XCTAssertEqual(metadata.versions[1].title, "1.0.0")
XCTAssertEqual(metadata.versions[1].summary, "Description of the release")
XCTAssertEqual(metadata.versions[1].author?.username, "octocat")
XCTAssertEqual(metadata.authors, [PackageCollectionsModel.Package.Author(username: "octocat",
url: "https://api.github.com/users/octocat",
service: .init(name: "GitHub"))])
Expand Down
22 changes: 11 additions & 11 deletions Tests/PackageCollectionsTests/PackageCollectionsModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2020-2022 Apple Inc. and the Swift project authors
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand All @@ -26,11 +26,11 @@ final class PackageCollectionsModelTests: XCTestCase {
toolsVersion: toolsVersion, packageName: "FooBar", targets: targets, products: products, minimumPlatformVersions: nil
)]
let versions: [PackageCollectionsModel.Package.Version] = [
.init(version: .init(stringLiteral: "1.2.0"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, createdAt: nil),
.init(version: .init(stringLiteral: "2.0.1"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, createdAt: nil),
.init(version: .init(stringLiteral: "2.1.0-beta.3"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, createdAt: nil),
.init(version: .init(stringLiteral: "2.1.0"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, createdAt: nil),
.init(version: .init(stringLiteral: "3.0.0-beta.1"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, createdAt: nil),
.init(version: .init(stringLiteral: "1.2.0"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, author: nil, createdAt: nil),
.init(version: .init(stringLiteral: "2.0.1"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, author: nil, createdAt: nil),
.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),
.init(version: .init(stringLiteral: "2.1.0"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, author: nil, createdAt: nil),
.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),
]

XCTAssertEqual("2.1.0", versions.latestRelease?.version.description)
Expand All @@ -45,8 +45,8 @@ final class PackageCollectionsModelTests: XCTestCase {
toolsVersion: toolsVersion, packageName: "FooBar", targets: targets, products: products, minimumPlatformVersions: nil
)]
let versions: [PackageCollectionsModel.Package.Version] = [
.init(version: .init(stringLiteral: "2.1.0-beta.3"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, createdAt: nil),
.init(version: .init(stringLiteral: "3.0.0-beta.1"), title: nil, summary: nil, manifests: manifests, defaultToolsVersion: toolsVersion, verifiedCompatibility: nil, license: nil, createdAt: nil),
.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),
.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),
]

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

XCTAssertEqual("2.1.0", versions.latestRelease?.version.description)
Expand Down
9 changes: 7 additions & 2 deletions Tests/PackageCollectionsTests/PackageCollectionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2020-2021 Apple Inc. and the Swift project authors
// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -690,6 +690,7 @@ final class PackageCollectionsTests: XCTestCase {
defaultToolsVersion: toolsVersion,
verifiedCompatibility: nil,
license: nil,
author: nil,
createdAt: nil)

let url = "https://packages.mock/\(UUID().uuidString)"
Expand Down Expand Up @@ -857,6 +858,7 @@ final class PackageCollectionsTests: XCTestCase {
defaultToolsVersion: toolsVersion,
verifiedCompatibility: nil,
license: nil,
author: nil,
createdAt: nil)

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

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

let mockMetadata = PackageCollectionsModel.PackageBasicMetadata(summary: "\(mockPackage.summary!) 2",
keywords: mockPackage.keywords.flatMap { $0.map { "\($0)-2" } },
versions: mockPackage.versions.map { PackageCollectionsModel.PackageBasicVersionMetadata(version: $0.version, title: "\($0.title!) 2", summary: "\($0.summary!) 2", createdAt: Date()) },
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()) },
watchersCount: mockPackage.watchersCount! + 1,
readmeURL: "\(mockPackage.readmeURL!.absoluteString)-2",
license: PackageCollectionsModel.License(type: .Apache2_0, url: "\(mockPackage.license!.url.absoluteString)-2"),
Expand Down Expand Up @@ -1345,6 +1348,7 @@ final class PackageCollectionsTests: XCTestCase {
XCTAssertEqual(version.verifiedCompatibility, metadataVersion?.verifiedCompatibility, "verifiedCompatibility should match")
XCTAssertEqual(version.license, metadataVersion?.license, "license should match")
XCTAssertEqual(mockMetadataVersion?.summary, metadataVersion?.summary, "summary should match")
XCTAssertEqual(mockMetadataVersion?.author, metadataVersion?.author, "author should match")
XCTAssertEqual(mockMetadataVersion?.createdAt, metadataVersion?.createdAt, "createdAt should match")
}
XCTAssertEqual(metadata.latestVersion, metadata.versions.first, "versions should be sorted")
Expand Down Expand Up @@ -1532,6 +1536,7 @@ final class PackageCollectionsTests: XCTestCase {
defaultToolsVersion: toolsVersion,
verifiedCompatibility: nil,
license: nil,
author: nil,
createdAt: nil)

let mockPackageURL = "https://packages.mock/\(UUID().uuidString)"
Expand Down
Loading