diff options
| author | Christian Cleberg <[email protected]> | 2026-04-13 20:07:53 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-04-13 20:07:53 -0500 |
| commit | 312e535f400f31714b3750de5222a1f6a8e5bcda (patch) | |
| tree | dfa0d9dfcfd08187befa79cf5d8afc4da9fef860 /Hutch/Networking | |
| parent | fe1ccc69661603d419a642a450e4ac9e1258adb0 (diff) | |
| download | hutch-3.1.4.tar.gz hutch-3.1.4.tar.bz2 hutch-3.1.4.zip | |
fix: sonarqube code smell fixesv3.1.4
Diffstat (limited to 'Hutch/Networking')
| -rw-r--r-- | Hutch/Networking/ProjectService.swift | 10 | ||||
| -rw-r--r-- | Hutch/Networking/SRHTClient.swift | 48 |
2 files changed, 24 insertions, 34 deletions
diff --git a/Hutch/Networking/ProjectService.swift b/Hutch/Networking/ProjectService.swift index bd8ccdc..5e0e061 100644 --- a/Hutch/Networking/ProjectService.swift +++ b/Hutch/Networking/ProjectService.swift @@ -49,7 +49,7 @@ private struct ProjectSummaryPayload: Decodable, Sendable { name = try container.decodeIfPresent(String.self, forKey: .name) ?? "" description = try container.decodeIfPresent(String.self, forKey: .description) website = try container.decodeIfPresent(String.self, forKey: .website) - visibility = try container.decodeIfPresent(Visibility.self, forKey: .visibility) ?? .public + visibility = try container.decodeIfPresent(Visibility.self, forKey: .visibility) ?? .publicVisibility tags = try container.decodeIfPresent([String].self, forKey: .tags) ?? [] updated = try container.decodeIfPresent(Date.self, forKey: .updated) ?? .distantPast } @@ -90,7 +90,7 @@ private struct ProjectDetailPayload: Decodable, Sendable { name = try container.decodeIfPresent(String.self, forKey: .name) ?? "" description = try container.decodeIfPresent(String.self, forKey: .description) website = try container.decodeIfPresent(String.self, forKey: .website) - visibility = try container.decodeIfPresent(Visibility.self, forKey: .visibility) ?? .public + visibility = try container.decodeIfPresent(Visibility.self, forKey: .visibility) ?? .publicVisibility tags = try container.decodeIfPresent([String].self, forKey: .tags) ?? [] updated = try container.decodeIfPresent(Date.self, forKey: .updated) ?? .distantPast mailingLists = try container.decodeIfPresent(ProjectMailingListPage.self, forKey: .mailingLists) ?? .empty @@ -126,7 +126,7 @@ private struct ProjectMailingListPayload: Decodable, Sendable { rid = try container.decode(String.self, forKey: .rid) name = try container.decodeIfPresent(String.self, forKey: .name) ?? "" description = try container.decodeIfPresent(String.self, forKey: .description) - visibility = try container.decodeIfPresent(Visibility.self, forKey: .visibility) ?? .public + visibility = try container.decodeIfPresent(Visibility.self, forKey: .visibility) ?? .publicVisibility owner = try container.decodeIfPresent(Entity.self, forKey: .owner) ?? Entity(canonicalName: "~unknown") } } @@ -160,7 +160,7 @@ private struct ProjectSourcePayload: Decodable, Sendable { rid = try container.decode(String.self, forKey: .rid) name = try container.decodeIfPresent(String.self, forKey: .name) ?? "" description = try container.decodeIfPresent(String.self, forKey: .description) - visibility = try container.decodeIfPresent(Visibility.self, forKey: .visibility) ?? .public + visibility = try container.decodeIfPresent(Visibility.self, forKey: .visibility) ?? .publicVisibility owner = try container.decodeIfPresent(Entity.self, forKey: .owner) ?? Entity(canonicalName: "~unknown") repoType = try container.decodeIfPresent(Project.SourceRepo.RepoType.self, forKey: .repoType) ?? .git } @@ -193,7 +193,7 @@ private struct ProjectTrackerPayload: Decodable, Sendable { rid = try container.decode(String.self, forKey: .rid) name = try container.decodeIfPresent(String.self, forKey: .name) ?? "" description = try container.decodeIfPresent(String.self, forKey: .description) - visibility = try container.decodeIfPresent(Visibility.self, forKey: .visibility) ?? .public + visibility = try container.decodeIfPresent(Visibility.self, forKey: .visibility) ?? .publicVisibility owner = try container.decodeIfPresent(Entity.self, forKey: .owner) ?? Entity(canonicalName: "~unknown") } } diff --git a/Hutch/Networking/SRHTClient.swift b/Hutch/Networking/SRHTClient.swift index 7e1f619..fa7b26b 100644 --- a/Hutch/Networking/SRHTClient.swift +++ b/Hutch/Networking/SRHTClient.swift @@ -57,7 +57,7 @@ final class SRHTClient: Sendable { service: SRHTService, query: String, variables: [String: any Sendable]? = nil, - responseType: T.Type + responseType _: T.Type ) async throws -> T { guard let token = _token.withLock({ $0 }), !token.isEmpty else { throw SRHTError.unauthorized @@ -164,20 +164,14 @@ final class SRHTClient: Sendable { /// - service: The target SourceHut service. /// - query: The GraphQL mutation string. /// - variables: Variables dict; the file variable should be set to `nil`. - /// - fileVariablePath: The dot-separated path to the file variable (e.g. "input.avatar"). - /// - fileData: The raw file data (e.g. JPEG). - /// - fileName: The file name to send (e.g. "avatar.jpg"). - /// - mimeType: The MIME type (e.g. "image/jpeg"). + /// - file: Multipart file payload (`variablePath` is the dot-separated GraphQL variable, e.g. `input.avatar`). /// - responseType: The expected `Decodable` type nested under `data`. func executeMultipart<T: Decodable>( service: SRHTService, query: String, variables: [String: any Sendable], - fileVariablePath: String, - fileData: Data, - fileName: String, - mimeType: String, - responseType: T.Type + file: MultipartUploadFile, + responseType _: T.Type ) async throws -> T { guard let token = _token.withLock({ $0 }), !token.isEmpty else { throw SRHTError.unauthorized @@ -197,8 +191,8 @@ final class SRHTClient: Sendable { ) let operationsData = try encoder.encode(operationsBody) - // Build the map JSON: { "0": ["variables.<fileVariablePath>"] } - let mapDict = ["0": ["variables.\(fileVariablePath)"]] + // Build the map JSON: { "0": ["variables.<variablePath>"] } + let mapDict = ["0": ["variables.\(file.variablePath)"]] let mapData = try encoder.encode(mapDict) // Assemble multipart body @@ -220,9 +214,9 @@ final class SRHTClient: Sendable { // Part: file body.append("--\(boundary)\r\n") - body.append("Content-Disposition: form-data; name=\"0\"; filename=\"\(fileName)\"\r\n") - body.append("Content-Type: \(mimeType)\r\n\r\n") - body.append(fileData) + body.append("Content-Disposition: form-data; name=\"0\"; filename=\"\(file.fileName)\"\r\n") + body.append("Content-Type: \(file.mimeType)\r\n\r\n") + body.append(file.fileData) body.append("\r\n") // Closing boundary @@ -311,7 +305,7 @@ final class SRHTClient: Sendable { query: String, variables: [String: any Sendable], files: [MultipartUploadFile], - responseType: T.Type + responseType _: T.Type ) async throws -> T { guard let token = _token.withLock({ $0 }), !token.isEmpty else { throw SRHTError.unauthorized @@ -408,15 +402,14 @@ final class SRHTClient: Sendable { service: SRHTService, query: String, variables: [String: any Sendable]? = nil, - responseType: T.Type, + responseType _: T.Type, cacheKey: String ) async throws -> T { // Try cache first - if let cachedData = responseCache.get(forKey: cacheKey) { - if let cached = try? decoder.decode(GraphQLResponse<T>.self, from: cachedData), - let data = cached.data { - return data - } + if let cachedData = responseCache.get(forKey: cacheKey), + let cached = try? decoder.decode(GraphQLResponse<T>.self, from: cachedData), + let data = cached.data { + return data } // No cache hit — fetch normally @@ -434,7 +427,7 @@ final class SRHTClient: Sendable { service: SRHTService, query: String, variables: [String: any Sendable]? = nil, - responseType: T.Type, + responseType _: T.Type, cacheKey: String ) async throws -> T { guard let token = _token.withLock({ $0 }), !token.isEmpty else { @@ -580,8 +573,7 @@ final class SRHTClient: Sendable { service: SRHTService, query: String, variables: [String: any Sendable]? = nil, - resultKeyPath: String, - type: T.Type + resultKeyPath: String ) -> SRHTPaginatedSequence<T> { SRHTPaginatedSequence( client: self, @@ -598,16 +590,14 @@ final class SRHTClient: Sendable { service: SRHTService, query: String, variables: [String: any Sendable]? = nil, - resultKeyPath: String, - type: T.Type + resultKeyPath: String ) async throws -> [T] { var all: [T] = [] for try await element in paginated( service: service, query: query, variables: variables, - resultKeyPath: resultKeyPath, - type: type + resultKeyPath: resultKeyPath ) { all.append(element) } |
