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/Views/Repositories | |
| parent | fe1ccc69661603d419a642a450e4ac9e1258adb0 (diff) | |
| download | hutch-312e535f400f31714b3750de5222a1f6a8e5bcda.tar.gz hutch-312e535f400f31714b3750de5222a1f6a8e5bcda.tar.bz2 hutch-312e535f400f31714b3750de5222a1f6a8e5bcda.zip | |
fix: sonarqube code smell fixesv3.1.4
Diffstat (limited to 'Hutch/Views/Repositories')
9 files changed, 67 insertions, 85 deletions
diff --git a/Hutch/Views/Repositories/FileTreeViewModel.swift b/Hutch/Views/Repositories/FileTreeViewModel.swift index c6fecbe..98211bf 100644 --- a/Hutch/Views/Repositories/FileTreeViewModel.swift +++ b/Hutch/Views/Repositories/FileTreeViewModel.swift @@ -327,14 +327,11 @@ final class FileTreeViewModel { } case .binaryBlob(let blob): - if blob.content != nil { + if blob.content != nil || blob.id == nil { viewingEntry = entry viewingObject = object } else if let blobId = blob.id { await loadBlob(entry: entry, blobId: blobId) - } else { - viewingEntry = entry - viewingObject = object } case .unknown: diff --git a/Hutch/Views/Repositories/HgRepositorySettingsView.swift b/Hutch/Views/Repositories/HgRepositorySettingsView.swift index e3c97e0..7b57505 100644 --- a/Hutch/Views/Repositories/HgRepositorySettingsView.swift +++ b/Hutch/Views/Repositories/HgRepositorySettingsView.swift @@ -121,9 +121,9 @@ struct HgRepositorySettingsView: View { .themedRow() Picker("Visibility", selection: Bindable(viewModel).editedVisibility) { - Text("Public").tag(Visibility.public) + Text("Public").tag(Visibility.publicVisibility) Text("Unlisted").tag(Visibility.unlisted) - Text("Private").tag(Visibility.private) + Text("Private").tag(Visibility.privateVisibility) } .themedRow() diff --git a/Hutch/Views/Repositories/ReadmeView.swift b/Hutch/Views/Repositories/ReadmeView.swift index 21d7a74..1a72b70 100644 --- a/Hutch/Views/Repositories/ReadmeView.swift +++ b/Hutch/Views/Repositories/ReadmeView.swift @@ -1828,7 +1828,7 @@ private final class HTMLWebViewCoordinator: NSObject, WKNavigationDelegate, @unc } func webView( - _ webView: WKWebView, + _: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping @MainActor (WKNavigationActionPolicy) -> Void ) { diff --git a/Hutch/Views/Repositories/RepositoryListView.swift b/Hutch/Views/Repositories/RepositoryListView.swift index 08ebb5c..04a7084 100644 --- a/Hutch/Views/Repositories/RepositoryListView.swift +++ b/Hutch/Views/Repositories/RepositoryListView.swift @@ -214,7 +214,7 @@ private struct CreateRepositorySheet: View { @State private var name = "" @State private var description = "" @State private var cloneURL = "" - @State private var visibility: Visibility = .public + @State private var visibility: Visibility = .publicVisibility @State private var service: RepositoryCreationService = .git var body: some View { @@ -235,9 +235,9 @@ private struct CreateRepositorySheet: View { .lineLimit(2...4) .themedRow() Picker("Visibility", selection: $visibility) { - Text("Public").tag(Visibility.public) + Text("Public").tag(Visibility.publicVisibility) Text("Unlisted").tag(Visibility.unlisted) - Text("Private").tag(Visibility.private) + Text("Private").tag(Visibility.privateVisibility) } .themedRow() } diff --git a/Hutch/Views/Repositories/RepositoryListViewModel.swift b/Hutch/Views/Repositories/RepositoryListViewModel.swift index 1e830bb..61053a0 100644 --- a/Hutch/Views/Repositories/RepositoryListViewModel.swift +++ b/Hutch/Views/Repositories/RepositoryListViewModel.swift @@ -397,15 +397,17 @@ final class RepositoryListViewModel { func repositorySummary(service: SRHTService) -> RepositorySummary { RepositorySummary( - id: id, - rid: rid, - service: service, - name: name, - description: description, - visibility: visibility, - updated: updated, - owner: owner, - head: head + fields: .init( + id: id, + rid: rid, + service: service, + name: name, + description: description, + visibility: visibility, + updated: updated, + owner: owner, + head: head + ) ) } } @@ -422,15 +424,17 @@ final class RepositoryListViewModel { func repositorySummary(service: SRHTService) -> RepositorySummary { RepositorySummary( - id: id, - rid: rid, - service: service, - name: name, - description: description, - visibility: visibility, - updated: updated, - owner: owner, - head: tip.map { Reference(name: $0.branch, target: nil) } + fields: .init( + id: id, + rid: rid, + service: service, + name: name, + description: description, + visibility: visibility, + updated: updated, + owner: owner, + head: tip.map { Reference(name: $0.branch, target: nil) } + ) ) } } @@ -463,17 +467,7 @@ final class RepositoryListViewModel { } if useCache && cursor == nil { - switch service { - case .git: - let result = try await client.executeAndCache( - service: service, - query: Self.gitQuery, - variables: variables.isEmpty ? nil : variables, - responseType: RepositoriesResponse.self, - cacheKey: cacheKey(for: service) - ) - return result.repositories ?? Self.emptyPage - case .hg: + if service == .hg { let hgVariables = cursor.map { ["cursor": $0 as any Sendable] } let result = try await client.executeAndCache( service: service, @@ -497,27 +491,17 @@ final class RepositoryListViewModel { } ?? [], cursor: result.repositories?.cursor ) - default: - let result = try await client.executeAndCache( - service: service, - query: Self.gitQuery, - variables: variables.isEmpty ? nil : variables, - responseType: RepositoriesResponse.self, - cacheKey: cacheKey(for: service) - ) - return result.repositories ?? Self.emptyPage } + let result = try await client.executeAndCache( + service: service, + query: Self.gitQuery, + variables: variables.isEmpty ? nil : variables, + responseType: RepositoriesResponse.self, + cacheKey: cacheKey(for: service) + ) + return result.repositories ?? Self.emptyPage } else { - switch service { - case .git: - let result = try await client.execute( - service: service, - query: Self.gitQuery, - variables: variables.isEmpty ? nil : variables, - responseType: RepositoriesResponse.self - ) - return result.repositories ?? Self.emptyPage - case .hg: + if service == .hg { let hgVariables = cursor.map { ["cursor": $0 as any Sendable] } let result = try await client.execute( service: service, @@ -540,15 +524,14 @@ final class RepositoryListViewModel { } ?? [], cursor: result.repositories?.cursor ) - default: - let result = try await client.execute( - service: service, - query: Self.gitQuery, - variables: variables.isEmpty ? nil : variables, - responseType: RepositoriesResponse.self - ) - return result.repositories ?? Self.emptyPage } + let result = try await client.execute( + service: service, + query: Self.gitQuery, + variables: variables.isEmpty ? nil : variables, + responseType: RepositoriesResponse.self + ) + return result.repositories ?? Self.emptyPage } } diff --git a/Hutch/Views/Repositories/RepositoryRowView.swift b/Hutch/Views/Repositories/RepositoryRowView.swift index a2d120b..86c8889 100644 --- a/Hutch/Views/Repositories/RepositoryRowView.swift +++ b/Hutch/Views/Repositories/RepositoryRowView.swift @@ -154,17 +154,17 @@ struct VisibilityBadge: View { private var label: String { switch visibility { - case .public: "PUBLIC" + case .publicVisibility: "PUBLIC" case .unlisted: "UNLISTED" - case .private: "PRIVATE" + case .privateVisibility: "PRIVATE" } } private var color: Color { switch visibility { - case .public: .green + case .publicVisibility: .green case .unlisted: .orange - case .private: .red + case .privateVisibility: .red } } } diff --git a/Hutch/Views/Repositories/RepositorySettingsView.swift b/Hutch/Views/Repositories/RepositorySettingsView.swift index 44b50ae..9f172a8 100644 --- a/Hutch/Views/Repositories/RepositorySettingsView.swift +++ b/Hutch/Views/Repositories/RepositorySettingsView.swift @@ -227,9 +227,9 @@ struct RepositorySettingsView: View { private func visibilitySection(_ viewModel: RepositorySettingsViewModel) -> some View { Section { Picker("Visibility", selection: Bindable(viewModel).editedVisibility) { - Text("Public").tag(Visibility.public) + Text("Public").tag(Visibility.publicVisibility) Text("Unlisted").tag(Visibility.unlisted) - Text("Private").tag(Visibility.private) + Text("Private").tag(Visibility.privateVisibility) } .themedRow() @@ -283,11 +283,11 @@ struct RepositorySettingsView: View { private func visibilityConfirmationMessage(for viewModel: RepositorySettingsViewModel) -> String { switch viewModel.editedVisibility { - case .public: + case .publicVisibility: "Anyone will be able to find and view this repository." case .unlisted: "People with the link can view this repository, but it won't appear in public listings." - case .private: + case .privateVisibility: "Only people with explicit access will be able to view this repository." } } diff --git a/Hutch/Views/Repositories/RepositorySettingsViewModel.swift b/Hutch/Views/Repositories/RepositorySettingsViewModel.swift index 8bd80a1..6233bec 100644 --- a/Hutch/Views/Repositories/RepositorySettingsViewModel.swift +++ b/Hutch/Views/Repositories/RepositorySettingsViewModel.swift @@ -20,15 +20,17 @@ private struct UpdatedRepositoryPayload: Decodable, Sendable { func repositorySummary(using owner: Entity, service: SRHTService) -> RepositorySummary { RepositorySummary( - id: id, - rid: rid, - service: service, - name: name, - description: description, - visibility: visibility, - updated: updated, - owner: owner, - head: head + fields: .init( + id: id, + rid: rid, + service: service, + name: name, + description: description, + visibility: visibility, + updated: updated, + owner: owner, + head: head + ) ) } } diff --git a/Hutch/Views/Repositories/RepositorySummarySupport.swift b/Hutch/Views/Repositories/RepositorySummarySupport.swift index 741ff39..393e3ff 100644 --- a/Hutch/Views/Repositories/RepositorySummarySupport.swift +++ b/Hutch/Views/Repositories/RepositorySummarySupport.swift @@ -37,11 +37,11 @@ func repositoryCloneURLs(for repository: RepositorySummary) -> RepositoryCloneUR func repositoryVisibilityLabel(_ visibility: Visibility) -> String { switch visibility { - case .public: + case .publicVisibility: return "Public" case .unlisted: return "Unlisted" - case .private: + case .privateVisibility: return "Private" } } |
