diff --git a/Sources/App/Commands/Ingestion.swift b/Sources/App/Commands/Ingestion.swift index fddf6cf97..9ef819da2 100644 --- a/Sources/App/Commands/Ingestion.swift +++ b/Sources/App/Commands/Ingestion.swift @@ -291,7 +291,7 @@ enum Ingestion { // https://github.com/swiftlang/swift/issues/76169 assert(false, "Unexpected error type: \(type(of: error))") // We need to throw _something_ here (we should never hit this codepath though) - throw Github.Error.requestFailed(.internalServerError) + throw Github.Error.unexpectedError(error) // We could theoretically avoid this whole second catch and just do // error as! GithubError // but let's play it safe and not risk a server crash, unlikely as it may be. @@ -333,7 +333,6 @@ enum Ingestion { 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 @@ -341,7 +340,6 @@ enum Ingestion { repository.lastIssueClosedAt = repoMetadata.lastIssueClosedAt repository.lastPullRequestClosedAt = repoMetadata.lastPullRequestClosedAt repository.license = .init(from: repoMetadata.licenseInfo) - repository.licenseUrl = licenseInfo?.htmlUrl repository.name = repoMetadata.repositoryName repository.openIssues = repoMetadata.openIssues.totalCount repository.openPullRequests = repoMetadata.openPullRequests.totalCount @@ -349,11 +347,17 @@ enum Ingestion { repository.ownerName = repoMetadata.owner.name repository.ownerAvatarUrl = repoMetadata.owner.avatarUrl repository.s3Readme = s3Readme - repository.readmeHtmlUrl = readmeInfo?.htmlUrl repository.releases = repoMetadata.releases.nodes.map(Release.init(from:)) repository.stars = repoMetadata.stargazerCount repository.summary = repoMetadata.description repository.forkedFrom = fork + if let readmeInfo { + repository.hasSPIBadge = readmeInfo.containsSPIBadge() + repository.readmeHtmlUrl = readmeInfo.htmlUrl + } + if let licenseInfo { + repository.licenseUrl = licenseInfo.htmlUrl + } do { try await repository.save(on: database) diff --git a/Sources/App/Core/Github.swift b/Sources/App/Core/Github.swift index be3d4c1e1..e023737b7 100644 --- a/Sources/App/Core/Github.swift +++ b/Sources/App/Core/Github.swift @@ -28,6 +28,7 @@ enum Github { case invalidURL(String) case postRequestFailed(_ url: String, Swift.Error) case requestFailed(HTTPStatus) + case unexpectedError(Swift.Error) } static var decoder: JSONDecoder { diff --git a/Tests/AppTests/IngestionTests.swift b/Tests/AppTests/IngestionTests.swift index fbd98de4d..1043e650e 100644 --- a/Tests/AppTests/IngestionTests.swift +++ b/Tests/AppTests/IngestionTests.swift @@ -213,6 +213,23 @@ extension AllTests.IngestionTests { #expect(repo.stars == 2) #expect(repo.summary == "package desc") } + + // update again but without license and readme info + try await Ingestion.updateRepository(on: app.db, + for: repo, + metadata: md, + licenseInfo: nil, + readmeInfo: nil, + s3Readme: .cached(s3ObjectUrl: "url", githubEtag: "etag"), + fork: .parentURL("https://github.com/foo/bar.git")) + + // validate that license and readme info stays unchanged + do { + #expect(repo.hasSPIBadge == true) + #expect(repo.license == .mit) + #expect(repo.licenseUrl == "license url") + #expect(repo.readmeHtmlUrl == "readme html url") + } } }