Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Sources/ActionBar/Models/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -133,7 +132,6 @@ final class AppState {
hasLoadedOnce = false
errorMessage = nil
availableRepos = []
repoListIsCapped = false
repoListError = nil
showingSettings = false
runQueryAtSettingsOpen = nil
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions Sources/ActionBar/Services/GitHubAPIClient.swift
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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] {
Expand Down
9 changes: 1 addition & 8 deletions Sources/ActionBar/Views/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down
Loading