Skip to content
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
1 change: 1 addition & 0 deletions Sources/App/Commands/Ingest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ func updateRepository(on database: Database,
repository.defaultBranch = repoMetadata.defaultBranch
repository.forks = repoMetadata.forkCount
repository.fundingLinks = repoMetadata.fundingLinks?.compactMap(FundingLink.init(from:)) ?? []
repository.hasSPIBadge = readmeInfo?.containsSPIBadge()
repository.homepageUrl = repoMetadata.homepageUrl?.trimmed
repository.isArchived = repoMetadata.isArchived
repository.isInOrganization = repoMetadata.isInOrganization
Expand Down
4 changes: 4 additions & 0 deletions Sources/App/Core/Github.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ extension Github {
var originalUrl: String
var s3Key: S3Store.Key
}

func containsSPIBadge() -> Bool {
html.contains("https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com")
}
}

struct Metadata: Decodable, Equatable {
Expand Down
29 changes: 29 additions & 0 deletions Sources/App/Migrations/082/UpdateRepositoryAddHasSPIBadge.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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

struct UpdateRepositoryAddHasSPIBadge: AsyncMigration {
func prepare(on database: Database) async throws {
try await database.schema("repositories")
.field("has_spi_badge", .bool)
.update()
}

func revert(on database: Database) async throws {
try await database.schema("repositories")
.deleteField("has_spi_badge")
.update()
}
}
3 changes: 3 additions & 0 deletions Sources/App/Models/Repository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ final class Repository: @unchecked Sendable, Model, Content {
@Field(key: "is_in_organization")
var isInOrganization: Bool

@Field(key: "has_spi_badge")
var hasSPIBadge: Bool?

@Field(key: "keywords")
var keywords: [String]

Expand Down
3 changes: 3 additions & 0 deletions Sources/App/configure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ public func configure(_ app: Application) async throws -> String {
app.migrations.add(CreateCustomCollection())
app.migrations.add(CreateCustomCollectionPackage())
}
do { // Migration 082 - Add `has_spi_badge` to `repositories`
app.migrations.add(UpdateRepositoryAddHasSPIBadge())
}

app.asyncCommands.use(Analyze.Command(), as: "analyze")
app.asyncCommands.use(CreateRestfileCommand(), as: "create-restfile")
Expand Down
17 changes: 17 additions & 0 deletions Tests/AppTests/GithubTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -459,4 +459,21 @@ class GithubTests: AppTestCase {
XCTAssertEqual(originalReadme, readme)
XCTAssertEqual(images, [])
}

func test_Readme_containsSPIBadge() throws {
do {
let html = """
<div id="readme" class="md" data-path="README.md"><article class="markdown-body entry-content container-lg" itemprop="text"><p dir="auto"><a href="https://swiftpackageindex.com/SwiftPackageIndex/SemanticVersion" rel="nofollow"><img src="https://camo.githubusercontent.com/f84b802d1cb9fa24a95e7dedb833a3bba4021eb194ff617d1ad1c8b42e177e04/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d687474707325334125324625324673776966747061636b616765696e6465782e636f6d2532466170692532467061636b6167657325324653776966745061636b616765496e64657825324653656d616e74696356657273696f6e25324662616467652533467479706525334473776966742d76657273696f6e73" alt="" data-canonical-src="https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FSwiftPackageIndex%2FSemanticVersion%2Fbadge%3Ftype%3Dswift-versions" style="max-width: 100%;"></a>
<a href="https://swiftpackageindex.com/SwiftPackageIndex/SemanticVersion" rel="nofollow"><img src="https://camo.githubusercontent.com/8e31075beb5ea5a79a03fa0db50fe102b74e9804f5bcff1f1f0dc698b9255ca3/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d687474707325334125324625324673776966747061636b616765696e6465782e636f6d2532466170692532467061636b6167657325324653776966745061636b616765496e64657825324653656d616e74696356657273696f6e253246626164676525334674797065253344706c6174666f726d73" alt="" data-canonical-src="https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FSwiftPackageIndex%2FSemanticVersion%2Fbadge%3Ftype%3Dplatforms" style="max-width: 100%;"></a></p>
<div class="markdown-heading" dir="auto"><h1 class="heading-element" dir="auto">🏷 SemanticVersion</h1><a id="user-content--semanticversion" class="anchor" aria-label="Permalink: 🏷 SemanticVersion" href="#-semanticversion"><svg class="octicon octicon-link" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg></a></div>
"""
let readme = Github.Readme(html: html, htmlUrl: "url", imagesToCache: [])
XCTAssertTrue(readme.containsSPIBadge())
}
do {
let readme = Github.Readme(html: "some html", htmlUrl: "url", imagesToCache: [])
XCTAssertFalse(readme.containsSPIBadge())
}
}

}
3 changes: 2 additions & 1 deletion Tests/AppTests/IngestorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class IngestorTests: AppTestCase {
metadata: md,
licenseInfo: .init(htmlUrl: "license url"),
readmeInfo: .init(etag: "etag",
html: "readme html",
html: "readme html https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com",
htmlUrl: "readme html url",
imagesToCache: []),
s3Readme: .cached(s3ObjectUrl: "url", githubEtag: "etag"),
Expand All @@ -177,6 +177,7 @@ class IngestorTests: AppTestCase {
.init(platform: .customUrl, url: "https://example.com/username1"),
.init(platform: .customUrl, url: "https://example.com/username2")
])
XCTAssertEqual(repo.hasSPIBadge, true)
XCTAssertEqual(repo.homepageUrl, "https://swiftpackageindex.com/Alamofire/Alamofire")
XCTAssertEqual(repo.isInOrganization, true)
XCTAssertEqual(repo.keywords, ["bar", "baz", "foo"])
Expand Down
Loading