Skip to content

Commit 7b16243

Browse files
authored
Merge branch 'main' into heckj/cfrayRequestLogging
2 parents 4278425 + 298a14d commit 7b16243

File tree

10 files changed

+222
-39
lines changed

10 files changed

+222
-39
lines changed

FrontEnd/styles/home.scss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,22 @@ body.home {
7171
}
7272
}
7373
}
74+
75+
.ccta-availability {
76+
padding: 15px;
77+
font-size: 13px;
78+
background-color: var(--panel-button-background);
79+
80+
p {
81+
margin: 5px 0;
82+
}
83+
84+
.support {
85+
margin: 0 0 5px;
86+
font-weight: bold;
87+
}
88+
89+
.cta {
90+
text-align: right;
91+
}
92+
}
-3.07 KB
Binary file not shown.
-2.94 KB
Binary file not shown.

Sources/App/Controllers/CustomCollectionsController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ enum CustomCollectionsController {
3232
.field(Version.self, \.$packageName)
3333
.filter(CustomCollection.self, \.$key == key)
3434
.sort(Repository.self, \.$name)
35+
.field(\.$scoreDetails)
3536
.page(page, size: pageSize)
3637
}
3738

Sources/App/Core/ExternalURL.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,30 @@
1515
import Plot
1616

1717
enum ExternalURL: URLRepresentable {
18+
case addNewPackage(_ owner: String, _ repository: String)
19+
case contactMailto
1820
case mastodon
21+
case podcast
1922
case projectGitHub
2023
case projectSponsorship
2124
case raiseNewIssue
22-
case podcast
23-
case addNewPackage(_ owner: String, _ repository: String)
24-
2525

2626
var description: String {
2727
switch(self) {
28+
case let .addNewPackage(owner, repository):
29+
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"
30+
case .contactMailto:
31+
return "mailto:[email protected]"
2832
case .mastodon:
2933
return "https://mas.to/@SwiftPackageIndex"
34+
case .podcast:
35+
return "https://swiftpackageindexing.transistor.fm"
3036
case .projectGitHub:
3137
return "https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server"
3238
case .projectSponsorship:
3339
return "https://github.com/sponsors/SwiftPackageIndex"
3440
case .raiseNewIssue:
3541
return "https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/new/choose"
36-
case .podcast:
37-
return "https://swiftpackageindexing.transistor.fm"
38-
case let .addNewPackage(owner, repository):
39-
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"
4042
}
4143
}
4244
}

Sources/App/Core/Supporters.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ enum Supporters {
2525
darkModeUrl: "/images/sponsors/emerge~dark.png"),
2626
url: "https://www.emergetools.com/?utm_source=spi2&utm_medium=sponsor&utm_campaign=emerge",
2727
advertisingCopy: "Join the future of mobile development. Trusted by top companies like Duolingo, Square, DoorDash & more…"),
28-
.init(name: "ContextSDK",
29-
logo: .init(lightModeUrl: "/images/sponsors/contextsdk.png",
30-
darkModeUrl: "/images/sponsors/contextsdk~dark.png"),
31-
url: "https://contextsdk.com",
32-
advertisingCopy: "Intent detection with real-world context. Lean, lightweight and GDPR compliant out of the box."),
3328
]
3429

3530
nonisolated(unsafe) static var infrastructure: [Corporate] = [

Sources/App/Views/Home/HomeIndex+View.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,24 @@ enum HomeIndex {
109109
analyticsEvent: "Home - Supporters CTA"),
110110
.group(
111111
Supporters.corporate.shuffled().map(\.advertisementNode)
112-
)
112+
),
113+
.if(Supporters.corporate.count < 2, .div(
114+
.class("ccta-availability"),
115+
.p(
116+
.class("support"),
117+
.text("Support the Swift Package Index")
118+
),
119+
.p(
120+
.text("We have one homepage sponsorship spot available. Support the project while promoting your company.")
121+
),
122+
.p(
123+
.class("cta"),
124+
.a(
125+
.href(ExternalURL.contactMailto),
126+
.text("Get in touch for details →")
127+
)
128+
)
129+
))
113130
)
114131
}
115132

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// Copyright Dave Verwer, Sven A. Schmidt, and other contributors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import XCTest
16+
17+
@testable import App
18+
19+
import Dependencies
20+
import Fluent
21+
import Vapor
22+
23+
24+
class CustomCollectionControllerTests: AppTestCase {
25+
26+
func test_query() async throws {
27+
// setup
28+
try await CustomCollection.save(
29+
on: app.db,
30+
key: "list",
31+
name: "List",
32+
url: "https://github.com/foo/bar/list.json",
33+
packages: [( id: .id0, url: "https://github.com/foo/1", owner: "foo", name: "1" )]
34+
)
35+
36+
// MUT
37+
let page = try await CustomCollectionsController.query(on: app.db,
38+
key: "list",
39+
page: 1,
40+
pageSize: 10)
41+
42+
// validation
43+
XCTAssertEqual(page.results.map(\.repository.name), ["1"])
44+
XCTAssertEqual(page.hasMoreResults, false)
45+
}
46+
47+
func test_query_pagination() async throws {
48+
// setup
49+
let pkgInfo = [UUID.id0, .id1, .id2, .id3, .id4].enumerated().shuffled().map { (idx, id) in
50+
(id, URL(string: "https://github.com/foo/\(idx)")!, "foo", "\(idx)")
51+
}
52+
try await CustomCollection.save(
53+
on: app.db,
54+
key: "list",
55+
name: "List",
56+
url: "https://github.com/foo/bar/list.json",
57+
packages: pkgInfo
58+
)
59+
60+
do { // first page
61+
// MUT
62+
let page = try await CustomCollectionsController.query(on: app.db,
63+
key: "list",
64+
page: 1,
65+
pageSize: 2)
66+
// validate
67+
XCTAssertEqual(page.results.map(\.repository.name), ["0", "1"])
68+
XCTAssertEqual(page.hasMoreResults, true)
69+
}
70+
71+
do { // second page
72+
// MUT
73+
let page = try await CustomCollectionsController.query(on: app.db,
74+
key: "list",
75+
page: 2,
76+
pageSize: 2)
77+
// validate
78+
XCTAssertEqual(page.results.map(\.repository.name), ["2", "3"])
79+
XCTAssertEqual(page.hasMoreResults, true)
80+
}
81+
82+
do { // third page
83+
// MUT
84+
let page = try await CustomCollectionsController.query(on: app.db,
85+
key: "list",
86+
page: 3,
87+
pageSize: 2)
88+
// validate
89+
XCTAssertEqual(page.results.map(\.repository.name), ["4"])
90+
XCTAssertEqual(page.hasMoreResults, false)
91+
}
92+
}
93+
94+
func test_show_collection() async throws {
95+
try await withDependencies {
96+
$0.environment.dbId = { nil }
97+
} operation: {
98+
try await CustomCollection.save(
99+
on: app.db,
100+
key: "list",
101+
name: "List",
102+
url: "https://github.com/foo/bar/list.json",
103+
packages: [( id: .id0, url: "https://github.com/foo/1", owner: "foo", name: "1" )]
104+
)
105+
106+
// MUT
107+
try await app.test(.GET, "/collections/list") { req async in
108+
// validate
109+
XCTAssertEqual(req.status, .ok)
110+
}
111+
}
112+
}
113+
114+
func test_not_found() throws {
115+
try withDependencies {
116+
$0.environment.dbId = { nil }
117+
} operation: {
118+
try app.test(.GET, "/collections/list") {
119+
XCTAssertEqual($0.status, .notFound)
120+
}
121+
}
122+
}
123+
124+
}
125+
126+
127+
private extension CustomCollection {
128+
@discardableResult
129+
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 {
130+
let packages = try await packages.mapAsync {
131+
let pkg = Package(id: $0.id, url: $0.url)
132+
try await pkg.save(on: database)
133+
try await Repository(package: pkg, name: $0.name, owner: $0.owner).save(on: database)
134+
try await Version(package: pkg, latest: .defaultBranch).save(on: database)
135+
return pkg
136+
}
137+
let collection = CustomCollection(id: .id1, .init(key: key, name: name, url: url))
138+
try await collection.save(on: database)
139+
try await collection.$packages.attach(packages, on: database)
140+
return collection
141+
}
142+
}

package-lock.json

Lines changed: 30 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
"devDependencies": {
2020
"esbuild": "^0.24.2",
2121
"esbuild-sass-plugin": "^3.3.1",
22-
"postcss": "^8.4.49",
22+
"postcss": "^8.5.1",
2323
"prettier": "^3.4.2",
24-
"stylelint": "^16.13.0",
24+
"stylelint": "^16.13.2",
2525
"stylelint-config-standard-scss": "^14.0.0",
2626
"stylelint-order": "^6.0.4",
27-
"stylelint-scss": "^6.10.0"
27+
"stylelint-scss": "^6.10.1"
2828
}
2929
}

0 commit comments

Comments
 (0)