-
-
Notifications
You must be signed in to change notification settings - Fork 50
Add forked from feature UI #3371
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
Changes from 8 commits
a8a2166
287172f
489b423
2e2cac4
3cebb09
c60f68f
5f360f2
e286cae
358e8cb
99d167e
e63f8c4
53e70ed
a6c7883
0ec21b3
c2bab32
a5c5bb2
e2d3a69
ee4032d
3a5172a
0b40fce
57a0b21
6e064b0
5e26cd4
6a627d1
ce07502
c9fa38c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright Dave Verwer, Sven A. Schmidt, and other contributors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import Fluent | ||
import SQLKit | ||
import Vapor | ||
|
||
extension API.PackageController { | ||
enum ForkedFromResult { | ||
|
||
case fromSPI(repository: String, owner: String, ownerName: String, packageName: String) | ||
case fromGitHub(url: String) | ||
|
||
static func query(on database: Database, packageId: Package.Id) async throws -> ForkedFromResult? { | ||
let model = try await Joined3<Package, Repository, Version>.query(on: database, packageId: packageId).first() | ||
|
||
guard let repoName = model?.repository.name, | ||
let ownerName = model?.repository.ownerName, | ||
let owner = model?.repository.owner, | ||
let packageName = model?.version.packageName else { | ||
return nil | ||
|
||
} | ||
|
||
return ForkedFromResult.fromSPI( | ||
repository: repoName, | ||
owner: owner, | ||
ownerName: ownerName, | ||
packageName: packageName | ||
) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -40,4 +40,12 @@ extension Joined3 where M == Package, R1 == Repository, R2 == Version { | |||||||||||||||
.filter(Repository.self, \.$owner, .custom("ilike"), owner) | ||||||||||||||||
.filter(Repository.self, \.$name, .custom("ilike"), repository) | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
static func query(on database: Database, packageId: Package.Id) -> JoinedQueryBuilder<Self> { | ||||||||||||||||
|
static func query(on database: Database, packageId: Package.Id) -> JoinedQueryBuilder<Self> { | |
static func query(on database: Database, | |
packageId: Package.Id, | |
version: Version.Kind) -> JoinedQueryBuilder<Self> { | |
query(on: database, version: version) | |
.filter(Package.self, \Package.$id == packageId) | |
} |
Call site:
let model = try await Joined3<Package, Repository, Version>
.query(on: database, packageId: packageId, version: .defaultBranch)
.first()
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.
Nit: Let's not add whitespace like this. The easiest way to fix this is to set these two options in Xcode's Editing settings.