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
2 changes: 1 addition & 1 deletion Sources/App/Commands/Ingest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func getFork(on database: Database, parent: Github.Metadata.Parent?) async -> Fo
if let packageId = try? await Package.query(on: database)
.filter(\.$url, .custom("ilike"), parentUrl)
.first()?.id {
return .parentId(packageId)
return .parentId(id: packageId, fallbackURL: parentUrl)
} else {
return .parentURL(parentUrl)
}
Expand Down
31 changes: 31 additions & 0 deletions Sources/App/Migrations/080/UpdateRepositoryResetForkedFrom.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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


struct UpdateRepositoryResetForkedFrom: AsyncMigration {
func prepare(on database: Database) async throws {
guard let db = database as? SQLDatabase else {
fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)")
}

try await db.raw(#"UPDATE "repositories" SET forked_from = NULL"#).run()
}

func revert(on database: Database) async throws {
// There's nothing we can do to restore the previous state
}
}
2 changes: 1 addition & 1 deletion Sources/App/Models/Repository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,6 @@ enum S3Readme: Codable, Equatable {
}

enum Fork: Codable, Equatable {
case parentId(Package.Id)
case parentId(id: Package.Id, fallbackURL: String)
case parentURL(String)
}
3 changes: 3 additions & 0 deletions Sources/App/configure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ public func configure(_ app: Application) async throws -> String {
do { // Migration 079 - Add `forked_from` to `repositories`
app.migrations.add(UpdateRepositoryAddForkedFrom())
}
do { // Migration 080 - Set`forked_from` to NULL because of Fork model change in Repository
app.migrations.add(UpdateRepositoryResetForkedFrom())
}

app.asyncCommands.use(Analyze.Command(), as: "analyze")
app.asyncCommands.use(CreateRestfileCommand(), as: "create-restfile")
Expand Down
12 changes: 6 additions & 6 deletions Tests/AppTests/IngestorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -606,16 +606,16 @@ class IngestorTests: AppTestCase {

// test lookup when package is in the index
let fork = await getFork(on: app.db, parent: .init(url: "https://github.com/foo/parent.git"))
XCTAssertEqual(fork, .parentId(.id0))
XCTAssertEqual(fork, .parentId(id: .id0, fallbackURL: "https://github.com/foo/parent.git"))

// test lookup when package is in the index but with different case in URL
let fork2 = await getFork(on: app.db, parent: .init(url: "https://github.com/Foo/Parent.git"))
XCTAssertEqual(fork2, .parentId(.id0))
XCTAssertEqual(fork2, .parentId(id: .id0, fallbackURL: "https://github.com/Foo/Parent.git"))

// test whem metadata repo url doesn't have `.git` at end
let fork3 = await getFork(on: app.db, parent: .init(url: "https://github.com/Foo/Parent"))
XCTAssertEqual(fork3, .parentId(.id0))
XCTAssertEqual(fork3, .parentId(id: .id0, fallbackURL: "https://github.com/Foo/Parent.git"))

// test lookup when package is not in the index
let fork4 = await getFork(on: app.db, parent: .init(url: "https://github.com/some/other.git"))
XCTAssertEqual(fork4, .parentURL("https://github.com/some/other.git"))
Expand Down
Loading