Skip to content

Commit

Permalink
Merge branch 'main' into heckj/cfrayRequestLogging
Browse files Browse the repository at this point in the history
  • Loading branch information
heckj authored Jan 20, 2025
2 parents 4278425 + 298a14d commit 7b16243
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 39 deletions.
19 changes: 19 additions & 0 deletions FrontEnd/styles/home.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,22 @@ body.home {
}
}
}

.ccta-availability {
padding: 15px;
font-size: 13px;
background-color: var(--panel-button-background);

p {
margin: 5px 0;
}

.support {
margin: 0 0 5px;
font-weight: bold;
}

.cta {
text-align: right;
}
}
Binary file removed Public/images/sponsors/contextsdk.png
Binary file not shown.
Binary file removed Public/images/sponsors/contextsdk~dark.png
Binary file not shown.
1 change: 1 addition & 0 deletions Sources/App/Controllers/CustomCollectionsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum CustomCollectionsController {
.field(Version.self, \.$packageName)
.filter(CustomCollection.self, \.$key == key)
.sort(Repository.self, \.$name)
.field(\.$scoreDetails)
.page(page, size: pageSize)
}

Expand Down
16 changes: 9 additions & 7 deletions Sources/App/Core/ExternalURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,30 @@
import Plot

enum ExternalURL: URLRepresentable {
case addNewPackage(_ owner: String, _ repository: String)
case contactMailto
case mastodon
case podcast
case projectGitHub
case projectSponsorship
case raiseNewIssue
case podcast
case addNewPackage(_ owner: String, _ repository: String)


var description: String {
switch(self) {
case let .addNewPackage(owner, repository):
return "https://github.com/SwiftPackageIndex/PackageList/issues/new?labels=Add+Package&template=add_package.yml&title=Add+\(repository)&list=https%3A%2F%2Fgithub.com%2F\(owner)%2F\(repository).git"
case .contactMailto:
return "mailto:[email protected]"
case .mastodon:
return "https://mas.to/@SwiftPackageIndex"
case .podcast:
return "https://swiftpackageindexing.transistor.fm"
case .projectGitHub:
return "https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server"
case .projectSponsorship:
return "https://github.com/sponsors/SwiftPackageIndex"
case .raiseNewIssue:
return "https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/new/choose"
case .podcast:
return "https://swiftpackageindexing.transistor.fm"
case let .addNewPackage(owner, repository):
return "https://github.com/SwiftPackageIndex/PackageList/issues/new?labels=Add+Package&template=add_package.yml&title=Add+\(repository)&list=https%3A%2F%2Fgithub.com%2F\(owner)%2F\(repository).git"
}
}
}
5 changes: 0 additions & 5 deletions Sources/App/Core/Supporters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ enum Supporters {
darkModeUrl: "/images/sponsors/emerge~dark.png"),
url: "https://www.emergetools.com/?utm_source=spi2&utm_medium=sponsor&utm_campaign=emerge",
advertisingCopy: "Join the future of mobile development. Trusted by top companies like Duolingo, Square, DoorDash & more…"),
.init(name: "ContextSDK",
logo: .init(lightModeUrl: "/images/sponsors/contextsdk.png",
darkModeUrl: "/images/sponsors/contextsdk~dark.png"),
url: "https://contextsdk.com",
advertisingCopy: "Intent detection with real-world context. Lean, lightweight and GDPR compliant out of the box."),
]

nonisolated(unsafe) static var infrastructure: [Corporate] = [
Expand Down
19 changes: 18 additions & 1 deletion Sources/App/Views/Home/HomeIndex+View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,24 @@ enum HomeIndex {
analyticsEvent: "Home - Supporters CTA"),
.group(
Supporters.corporate.shuffled().map(\.advertisementNode)
)
),
.if(Supporters.corporate.count < 2, .div(
.class("ccta-availability"),
.p(
.class("support"),
.text("Support the Swift Package Index")
),
.p(
.text("We have one homepage sponsorship spot available. Support the project while promoting your company.")
),
.p(
.class("cta"),
.a(
.href(ExternalURL.contactMailto),
.text("Get in touch for details →")
)
)
))
)
}

Expand Down
142 changes: 142 additions & 0 deletions Tests/AppTests/CustomCollectionControllerTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// 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 XCTest

@testable import App

import Dependencies
import Fluent
import Vapor


class CustomCollectionControllerTests: AppTestCase {

func test_query() async throws {
// setup
try await CustomCollection.save(
on: app.db,
key: "list",
name: "List",
url: "https://github.com/foo/bar/list.json",
packages: [( id: .id0, url: "https://github.com/foo/1", owner: "foo", name: "1" )]
)

// MUT
let page = try await CustomCollectionsController.query(on: app.db,
key: "list",
page: 1,
pageSize: 10)

// validation
XCTAssertEqual(page.results.map(\.repository.name), ["1"])
XCTAssertEqual(page.hasMoreResults, false)
}

func test_query_pagination() async throws {
// setup
let pkgInfo = [UUID.id0, .id1, .id2, .id3, .id4].enumerated().shuffled().map { (idx, id) in
(id, URL(string: "https://github.com/foo/\(idx)")!, "foo", "\(idx)")
}
try await CustomCollection.save(
on: app.db,
key: "list",
name: "List",
url: "https://github.com/foo/bar/list.json",
packages: pkgInfo
)

do { // first page
// MUT
let page = try await CustomCollectionsController.query(on: app.db,
key: "list",
page: 1,
pageSize: 2)
// validate
XCTAssertEqual(page.results.map(\.repository.name), ["0", "1"])
XCTAssertEqual(page.hasMoreResults, true)
}

do { // second page
// MUT
let page = try await CustomCollectionsController.query(on: app.db,
key: "list",
page: 2,
pageSize: 2)
// validate
XCTAssertEqual(page.results.map(\.repository.name), ["2", "3"])
XCTAssertEqual(page.hasMoreResults, true)
}

do { // third page
// MUT
let page = try await CustomCollectionsController.query(on: app.db,
key: "list",
page: 3,
pageSize: 2)
// validate
XCTAssertEqual(page.results.map(\.repository.name), ["4"])
XCTAssertEqual(page.hasMoreResults, false)
}
}

func test_show_collection() async throws {
try await withDependencies {
$0.environment.dbId = { nil }
} operation: {
try await CustomCollection.save(
on: app.db,
key: "list",
name: "List",
url: "https://github.com/foo/bar/list.json",
packages: [( id: .id0, url: "https://github.com/foo/1", owner: "foo", name: "1" )]
)

// MUT
try await app.test(.GET, "/collections/list") { req async in
// validate
XCTAssertEqual(req.status, .ok)
}
}
}

func test_not_found() throws {
try withDependencies {
$0.environment.dbId = { nil }
} operation: {
try app.test(.GET, "/collections/list") {
XCTAssertEqual($0.status, .notFound)
}
}
}

}


private extension CustomCollection {
@discardableResult
static func save(on database: Database, key: String, name: String, url: URL, packages: [(id: Package.Id, url: URL, owner: String, name: String)]) async throws -> CustomCollection {
let packages = try await packages.mapAsync {
let pkg = Package(id: $0.id, url: $0.url)
try await pkg.save(on: database)
try await Repository(package: pkg, name: $0.name, owner: $0.owner).save(on: database)
try await Version(package: pkg, latest: .defaultBranch).save(on: database)
return pkg
}
let collection = CustomCollection(id: .id1, .init(key: key, name: name, url: url))
try await collection.save(on: database)
try await collection.$packages.attach(packages, on: database)
return collection
}
}
53 changes: 30 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
"devDependencies": {
"esbuild": "^0.24.2",
"esbuild-sass-plugin": "^3.3.1",
"postcss": "^8.4.49",
"postcss": "^8.5.1",
"prettier": "^3.4.2",
"stylelint": "^16.13.0",
"stylelint": "^16.13.2",
"stylelint-config-standard-scss": "^14.0.0",
"stylelint-order": "^6.0.4",
"stylelint-scss": "^6.10.0"
"stylelint-scss": "^6.10.1"
}
}

0 comments on commit 7b16243

Please sign in to comment.