Skip to content

Commit 29fc6c3

Browse files
Merge pull request #3809 from SwiftPackageIndex/issue-3585-bad-badge-counts
Issue 3585 bad badge counts
2 parents 458a472 + d7e78b5 commit 29fc6c3

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

Sources/App/Commands/Ingestion.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ enum Ingestion {
291291
// https://github.com/swiftlang/swift/issues/76169
292292
assert(false, "Unexpected error type: \(type(of: error))")
293293
// We need to throw _something_ here (we should never hit this codepath though)
294-
throw Github.Error.requestFailed(.internalServerError)
294+
throw Github.Error.unexpectedError(error)
295295
// We could theoretically avoid this whole second catch and just do
296296
// error as! GithubError
297297
// but let's play it safe and not risk a server crash, unlikely as it may be.
@@ -333,27 +333,31 @@ enum Ingestion {
333333
repository.defaultBranch = repoMetadata.defaultBranch
334334
repository.forks = repoMetadata.forkCount
335335
repository.fundingLinks = repoMetadata.fundingLinks?.compactMap(FundingLink.init(from:)) ?? []
336-
repository.hasSPIBadge = readmeInfo?.containsSPIBadge()
337336
repository.homepageUrl = repoMetadata.homepageUrl?.trimmed
338337
repository.isArchived = repoMetadata.isArchived
339338
repository.isInOrganization = repoMetadata.isInOrganization
340339
repository.keywords = Set(repoMetadata.topics.map { $0.lowercased() }).sorted()
341340
repository.lastIssueClosedAt = repoMetadata.lastIssueClosedAt
342341
repository.lastPullRequestClosedAt = repoMetadata.lastPullRequestClosedAt
343342
repository.license = .init(from: repoMetadata.licenseInfo)
344-
repository.licenseUrl = licenseInfo?.htmlUrl
345343
repository.name = repoMetadata.repositoryName
346344
repository.openIssues = repoMetadata.openIssues.totalCount
347345
repository.openPullRequests = repoMetadata.openPullRequests.totalCount
348346
repository.owner = repoMetadata.repositoryOwner
349347
repository.ownerName = repoMetadata.owner.name
350348
repository.ownerAvatarUrl = repoMetadata.owner.avatarUrl
351349
repository.s3Readme = s3Readme
352-
repository.readmeHtmlUrl = readmeInfo?.htmlUrl
353350
repository.releases = repoMetadata.releases.nodes.map(Release.init(from:))
354351
repository.stars = repoMetadata.stargazerCount
355352
repository.summary = repoMetadata.description
356353
repository.forkedFrom = fork
354+
if let readmeInfo {
355+
repository.hasSPIBadge = readmeInfo.containsSPIBadge()
356+
repository.readmeHtmlUrl = readmeInfo.htmlUrl
357+
}
358+
if let licenseInfo {
359+
repository.licenseUrl = licenseInfo.htmlUrl
360+
}
357361

358362
do {
359363
try await repository.save(on: database)

Sources/App/Core/Github.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ enum Github {
2828
case invalidURL(String)
2929
case postRequestFailed(_ url: String, Swift.Error)
3030
case requestFailed(HTTPStatus)
31+
case unexpectedError(Swift.Error)
3132
}
3233

3334
static var decoder: JSONDecoder {

Tests/AppTests/IngestionTests.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,23 @@ extension AllTests.IngestionTests {
213213
#expect(repo.stars == 2)
214214
#expect(repo.summary == "package desc")
215215
}
216+
217+
// update again but without license and readme info
218+
try await Ingestion.updateRepository(on: app.db,
219+
for: repo,
220+
metadata: md,
221+
licenseInfo: nil,
222+
readmeInfo: nil,
223+
s3Readme: .cached(s3ObjectUrl: "url", githubEtag: "etag"),
224+
fork: .parentURL("https://github.com/foo/bar.git"))
225+
226+
// validate that license and readme info stays unchanged
227+
do {
228+
#expect(repo.hasSPIBadge == true)
229+
#expect(repo.license == .mit)
230+
#expect(repo.licenseUrl == "license url")
231+
#expect(repo.readmeHtmlUrl == "readme html url")
232+
}
216233
}
217234
}
218235

0 commit comments

Comments
 (0)