diff --git a/Sources/ActionBar/Models/AppState.swift b/Sources/ActionBar/Models/AppState.swift index 98f7517..b589a09 100644 --- a/Sources/ActionBar/Models/AppState.swift +++ b/Sources/ActionBar/Models/AppState.swift @@ -15,7 +15,6 @@ final class AppState { var isLoggingIn = false var availableRepos: [Repository] = [] var isLoadingRepos = false - var repoListIsCapped = false var repoListError: String? private(set) var showingSettings = false /// The run query from when Settings was opened. Polls keep using it until Settings closes, @@ -133,7 +132,6 @@ final class AppState { hasLoadedOnce = false errorMessage = nil availableRepos = [] - repoListIsCapped = false repoListError = nil showingSettings = false runQueryAtSettingsOpen = nil @@ -364,7 +362,6 @@ final class AppState { let repos = try await apiClient.fetchAllRepos(token: token) guard !Task.isCancelled, sessionID == self.sessionID else { return } availableRepos = repos - repoListIsCapped = repos.count >= GitHubAPIClient.maxRepositories } catch { guard !Task.isCancelled, sessionID == self.sessionID else { return } // Keep whatever list we had before. diff --git a/Sources/ActionBar/Services/GitHubAPIClient.swift b/Sources/ActionBar/Services/GitHubAPIClient.swift index a4a3476..5419731 100644 --- a/Sources/ActionBar/Services/GitHubAPIClient.swift +++ b/Sources/ActionBar/Services/GitHubAPIClient.swift @@ -1,8 +1,8 @@ import Foundation actor GitHubAPIClient { - /// Upper bound on repositories listed for selection (and polled when nothing is selected). - static let maxRepositories = 200 + /// Upper bound on repositories polled when none are explicitly selected. + private static let maxFallbackRepositories = 200 private static let baseURL = "https://api.github.com" private static let pageSize = 100 @@ -50,7 +50,7 @@ actor GitHubAPIClient { if let repoNames { repoFullNames = repoNames } else { - repoFullNames = try await fetchAllRepos(token: token).map(\.fullName) + repoFullNames = try await fetchAllRepos(token: token, limit: Self.maxFallbackRepositories).map(\.fullName) } let (allRuns, errors) = await withTaskGroup(of: (String, Result<[WorkflowRun], Error>).self) { group in @@ -153,21 +153,21 @@ actor GitHubAPIClient { try await !fetchInstallations(token: token).isEmpty } - func fetchAllRepos(token: String) async throws -> [Repository] { + func fetchAllRepos(token: String, limit: Int = .max) async throws -> [Repository] { let installations = try await fetchInstallations(token: token) var allRepos: [Repository] = [] - for installation in installations where allRepos.count < Self.maxRepositories { + for installation in installations where allRepos.count < limit { allRepos += try await fetchAllPages( InstallationRepositoriesResponse.self, path: "/user/installations/\(installation.id)/repositories", token: token, - limit: Self.maxRepositories - allRepos.count + limit: limit - allRepos.count ) } let sorted = allRepos.sorted { $0.fullName.localizedCaseInsensitiveCompare($1.fullName) == .orderedAscending } - return Array(sorted.prefix(Self.maxRepositories)) + return Array(sorted.prefix(limit)) } private func fetchInstallations(token: String) async throws -> [AppInstallation] { diff --git a/Sources/ActionBar/Views/SettingsView.swift b/Sources/ActionBar/Views/SettingsView.swift index acfe405..eb0bd19 100644 --- a/Sources/ActionBar/Views/SettingsView.swift +++ b/Sources/ActionBar/Views/SettingsView.swift @@ -222,13 +222,6 @@ struct SettingsView: View { .disabled(settings.selectedRepoNames == repoSelectionAtOpen) } - if appState.repoListIsCapped { - Text("Only the first \(GitHubAPIClient.maxRepositories) repositories are shown.") - .font(.caption2) - .foregroundStyle(.secondary) - .frame(maxWidth: .infinity, alignment: .leading) - } - if let error = appState.repoListError { Text("Couldn't load repositories: \(error)") .font(.caption2) @@ -250,7 +243,7 @@ struct SettingsView: View { .font(.system(size: 12)) .foregroundStyle(.orange) VStack(alignment: .leading, spacing: 6) { - Text("Each selected repo requires a separate API call on every refresh. Selecting many repos will slow things down.") + Text("This selects \(filteredRepos.count) repos. Each selected repo requires a separate API call on every refresh, so selecting many repos will slow things down and can hit GitHub's rate limit.") .font(.caption2) .fixedSize(horizontal: false, vertical: true) HStack(spacing: 12) {