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
12 changes: 8 additions & 4 deletions Sources/App/Commands/Ingestion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -333,27 +333,31 @@ 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
repository.keywords = Set(repoMetadata.topics.map { $0.lowercased() }).sorted()
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
repository.owner = repoMetadata.repositoryOwner
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)
Expand Down
1 change: 1 addition & 0 deletions Sources/App/Core/Github.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 17 additions & 0 deletions Tests/AppTests/IngestionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}

Expand Down
Loading