-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add author and signer to package collection models #6415
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import Dispatch | |
import PackageCollections | ||
import PackageModel | ||
import PackageRegistry | ||
import PackageSigning | ||
import SourceControl | ||
|
||
import struct Foundation.Date | ||
|
@@ -72,6 +73,7 @@ public struct Package { | |
public let author: Author? | ||
public let description: String? | ||
public let publishedAt: Date? | ||
public let signingEntity: SigningEntity? | ||
public let latestVersion: Version? | ||
|
||
fileprivate init( | ||
|
@@ -86,6 +88,7 @@ public struct Package { | |
author: Author?, | ||
description: String?, | ||
publishedAt: Date?, | ||
signingEntity: SigningEntity?, | ||
latestVersion: Version? = nil, | ||
source: Source | ||
) { | ||
|
@@ -100,6 +103,7 @@ public struct Package { | |
self.author = author | ||
self.description = description | ||
self.publishedAt = publishedAt | ||
self.signingEntity = signingEntity | ||
self.latestVersion = latestVersion | ||
self.source = source | ||
} | ||
|
@@ -150,6 +154,7 @@ public struct PackageSearchClient { | |
public let author: Package.Author? | ||
public let description: String? | ||
public let publishedAt: Date? | ||
public let signingEntity: SigningEntity? | ||
} | ||
|
||
private func getVersionMetadata( | ||
|
@@ -172,7 +177,8 @@ public struct PackageSearchClient { | |
resources: metadata.resources.map { .init($0) }, | ||
author: metadata.author.map { .init($0) }, | ||
description: metadata.description, | ||
publishedAt: metadata.publishedAt | ||
publishedAt: metadata.publishedAt, | ||
signingEntity: metadata.sourceArchive?.signingEntity | ||
) | ||
}) | ||
} | ||
|
@@ -189,18 +195,22 @@ public struct PackageSearchClient { | |
self.indexAndCollections.findPackages(query) { result in | ||
do { | ||
let packages = try result.get().items.map { | ||
Package( | ||
let versions = $0.package.versions.sorted(by: >) | ||
let latestVersion = versions.first | ||
|
||
return Package( | ||
identity: $0.package.identity, | ||
location: $0.package.location, | ||
versions: $0.package.versions.map(\.version), | ||
licenseURL: nil, | ||
licenseURL: $0.package.license?.url, | ||
readmeURL: $0.package.readmeURL, | ||
repositoryURLs: nil, | ||
resources: [], | ||
author: nil, | ||
description: nil, | ||
publishedAt: nil, | ||
latestVersion: nil, | ||
author: latestVersion?.author.map { .init($0) }, | ||
description: latestVersion?.summary, | ||
publishedAt: latestVersion?.createdAt, | ||
signingEntity: latestVersion?.signer.map { SigningEntity(signer: $0) }, | ||
latestVersion: latestVersion?.version, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can set some of these using the package's latest version listed in the collection/index result. |
||
// this only makes sense in connection with providing versioned metadata | ||
source: .indexAndCollections(collections: $0.collections, indexes: $0.indexes) | ||
) | ||
|
@@ -259,6 +269,7 @@ public struct PackageSearchClient { | |
author: nil, | ||
description: nil, | ||
publishedAt: nil, | ||
signingEntity: nil, | ||
latestVersion: nil, | ||
// this only makes sense in connection with providing versioned metadata | ||
source: .sourceControl(url: url) | ||
|
@@ -298,6 +309,7 @@ public struct PackageSearchClient { | |
let author: Package.Author? | ||
let description: String? | ||
let publishedAt: Date? | ||
let signingEntity: SigningEntity? | ||
if case .success(let metadata) = result { | ||
licenseURL = metadata.licenseURL | ||
readmeURL = metadata.readmeURL | ||
|
@@ -306,6 +318,7 @@ public struct PackageSearchClient { | |
author = metadata.author | ||
description = metadata.description | ||
publishedAt = metadata.publishedAt | ||
signingEntity = metadata.signingEntity | ||
} else { | ||
licenseURL = nil | ||
readmeURL = self.guessReadMeURL(alternateLocations: metadata.alternateLocations) | ||
|
@@ -314,6 +327,7 @@ public struct PackageSearchClient { | |
author = nil | ||
description = nil | ||
publishedAt = nil | ||
signingEntity = nil | ||
} | ||
|
||
return callback(.success([Package( | ||
|
@@ -326,6 +340,7 @@ public struct PackageSearchClient { | |
author: author, | ||
description: description, | ||
publishedAt: publishedAt, | ||
signingEntity: signingEntity, | ||
latestVersion: version, | ||
source: .registry(url: metadata.registry.url) | ||
)])) | ||
|
@@ -342,6 +357,7 @@ public struct PackageSearchClient { | |
author: nil, | ||
description: nil, | ||
publishedAt: nil, | ||
signingEntity: nil, | ||
latestVersion: nil, | ||
// this only makes sense in connection with providing versioned metadata | ||
source: .registry(url: metadata.registry.url) | ||
|
@@ -426,6 +442,16 @@ extension Package.Author { | |
url: author.url | ||
) | ||
} | ||
|
||
fileprivate init(_ author: PackageCollectionsModel.Package.Author) { | ||
self.init( | ||
name: author.username, | ||
email: nil, | ||
description: nil, | ||
organization: nil, | ||
url: author.url | ||
) | ||
} | ||
} | ||
|
||
extension Package.Organization { | ||
|
@@ -438,3 +464,24 @@ extension Package.Organization { | |
) | ||
} | ||
} | ||
|
||
extension SigningEntity { | ||
fileprivate init(signer: PackageCollectionsModel.Signer) { | ||
// All package collection signers are "recognized" | ||
self = .recognized( | ||
type: .init(signer.type), | ||
name: signer.commonName, | ||
organizationalUnit: signer.organizationalUnitName, | ||
organization: signer.organizationName | ||
) | ||
} | ||
} | ||
|
||
extension SigningEntityType { | ||
fileprivate init(_ type: PackageCollectionsModel.SignerType) { | ||
switch type { | ||
case .adp: | ||
self = .adp | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Author info can come from GitHub or package collection