diff options
Diffstat (limited to 'octosentry/GitHubSecurityAPIClient.swift')
| -rw-r--r-- | octosentry/GitHubSecurityAPIClient.swift | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/octosentry/GitHubSecurityAPIClient.swift b/octosentry/GitHubSecurityAPIClient.swift index 629699a..2e480bd 100644 --- a/octosentry/GitHubSecurityAPIClient.swift +++ b/octosentry/GitHubSecurityAPIClient.swift @@ -3,9 +3,9 @@ // octosentry // // Fetches Dependabot, code scanning, and secret scanning alerts for a -// single repo and normalizes them into SecurityEvent. Auth is a PAT read -// by the caller from the GITHUB_TOKEN environment variable — a dev-only -// shortcut ahead of the device authorization flow (spec §6, §13). +// repo and normalizes them into SecurityEvent, plus (with broader scope) +// listing repos the token can see for the repo picker. The token itself +// comes from Keychain via the device authorization flow (spec §6). // import Foundation @@ -89,6 +89,20 @@ actor GitHubSecurityAPIClient { } } + /// Lists repos the token can see (requires the broader repo-access + /// scope granted via AuthStore.requestRepoAccess(), not the default + /// sign-in scope). Used by the repo picker (#15). + func fetchAccessibleRepos() async throws -> [String] { + var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: false)! + components.path = "/user/repos" + components.queryItems = [ + URLQueryItem(name: "per_page", value: "100"), + URLQueryItem(name: "sort", value: "full_name"), + ] + let dtos: [GitHubRepoDTO] = try await fetchAllPages(url: components.url!) + return dtos.map(\.fullName) + } + private func alertsURL(owner: String, repo: String, path: String) -> URL { var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: false)! components.path = "/repos/\(owner)/\(repo)/\(path)" |
