Skip to content

Commit

Permalink
Remove deprecated resolveRedirects
Browse files Browse the repository at this point in the history
  • Loading branch information
finestructure committed Jan 12, 2024
1 parent 5b00aa3 commit 461cb36
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 20 deletions.
5 changes: 3 additions & 2 deletions Sources/ValidatorCore/Commands/CheckDependencies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public struct CheckDependencies: AsyncParsableCommand {
let missing = allDependencies.subtracting(allPackages)
print("Not indexed:", missing.count)

let client = HTTPClient(eventLoopGroupProvider: .singleton)
let client = HTTPClient(eventLoopGroupProvider: .singleton,
configuration: .init(redirectConfiguration: .disallow))
defer { try? client.syncShutdown() }

var newPackages = UniqueCanonicalPackageURLs()
Expand All @@ -69,7 +70,7 @@ public struct CheckDependencies: AsyncParsableCommand {

// resolve redirects
print("Processing:", dep.packageURL, "...")
guard let resolved = try? await Current.resolvePackageRedirects(dep.packageURL).url else {
guard let resolved = try? await Current.resolvePackageRedirects(client, dep.packageURL).url else {
// TODO: consider adding retry for some errors
print(" ... ⛔ redirect resolution returned nil")
continue
Expand Down
6 changes: 3 additions & 3 deletions Sources/ValidatorCore/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct Environment {
var fetchDependencies: (_ api: SwiftPackageIndexAPI) async throws -> [SwiftPackageIndexAPI.PackageRecord]
var fetchRepository: (_ client: HTTPClient, _ url: PackageURL) async throws -> Github.Repository
var githubToken: () -> String?
var resolvePackageRedirects: (PackageURL) async throws -> Redirect
var resolvePackageRedirects: (_ client: HTTPClient, _ url: PackageURL) async throws -> Redirect
var shell: Shell
}

Expand All @@ -38,7 +38,7 @@ extension Environment {
fetchDependencies: { try await $0.fetchDependencies() },
fetchRepository: Github.fetchRepository(client:url:),
githubToken: { ProcessInfo.processInfo.environment["GITHUB_TOKEN"] },
resolvePackageRedirects: resolveRedirects(for:),
resolvePackageRedirects: resolvePackageRedirects(client:for:),
shell: .live
)

Expand All @@ -49,7 +49,7 @@ extension Environment {
fetchDependencies: { _ in [] },
fetchRepository: { _, _ in .init(defaultBranch: "main", owner: "foo", name: "bar") },
githubToken: { nil },
resolvePackageRedirects: { .initial($0) },
resolvePackageRedirects: { _, url in .initial(url) },
shell: .mock
)
}
Expand Down
15 changes: 0 additions & 15 deletions Sources/ValidatorCore/RedirectFollower.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,6 @@ enum Redirect: Equatable {
}


@available(*, deprecated)
func resolveRedirects(for url: PackageURL) async throws -> Redirect {
let client = HTTPClient(eventLoopGroupProvider: .singleton,
configuration: .init(redirectConfiguration: .disallow))
defer { try? client.syncShutdown() }
let res = try await resolveRedirects(client: client, for: url.deletingGitExtension())
switch res {
case .initial, .notFound, .error, .unauthorized, .rateLimited:
return res
case .redirected(to: let newURL):
return .redirected(to: newURL.appendingGitExtension())
}
}


private func resolveRedirects(client: HTTPClient, for url: PackageURL) async throws -> Redirect {
var lastResult = Redirect.initial(url)
var hopCount = 0
Expand Down

0 comments on commit 461cb36

Please sign in to comment.