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
56 changes: 56 additions & 0 deletions OctoKit/Repositories.swift
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,56 @@ public extension Octokit {
}
#endif

@discardableResult
func organizationRepositories(org: String,
page: String = "1",
perPage: String = "100",
completion: @escaping (_ response: Result<[Repository], Error>) -> Void) -> URLSessionDataTaskProtocol? {
let router = RepositoryRouter.readOrganizationRepositories(configuration, org, page, perPage)
return router.load(session, decoder: configuration.decoder, expectedResultType: [Repository].self) { repos, error in
if let error = error {
completion(.failure(error))
}

if let repos = repos {
completion(.success(repos))
}
}
}

#if compiler(>=5.5.2) && canImport(_Concurrency)
@available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOS 8.0, *)
func organizationRepositories(org: String, page: String = "1", perPage: String = "100") async throws -> [Repository] {
let router = RepositoryRouter.readOrganizationRepositories(configuration, org, page, perPage)
return try await router.load(session, decoder: configuration.decoder, expectedResultType: [Repository].self)
}
#endif

@discardableResult
func organizationRepositoriesPaginated(org: String,
page: String = "1",
perPage: String = "100",
completion: @escaping (_ response: Result<PaginatedResponse<[Repository]>, Error>) -> Void) -> URLSessionDataTaskProtocol? {
let router = RepositoryRouter.readOrganizationRepositories(configuration, org, page, perPage)
return router.loadPaginated(session, decoder: configuration.decoder, expectedResultType: [Repository].self) { response, error in
if let error = error {
completion(.failure(error))
} else if let response = response {
completion(.success(response))
}
}
}

#if compiler(>=5.5.2) && canImport(_Concurrency)
@available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOS 8.0, *)
func organizationRepositoriesPaginated(org: String,
page: String = "1",
perPage: String = "100") async throws -> PaginatedResponse<[Repository]> {
let router = RepositoryRouter.readOrganizationRepositories(configuration, org, page, perPage)
return try await router.loadPaginated(session, decoder: configuration.decoder, expectedResultType: [Repository].self)
}
#endif

/**
Fetches a repository for a user or organization
- parameter owner: The user or organization that owns the repositories.
Expand Down Expand Up @@ -482,6 +532,7 @@ public extension Octokit {

enum RepositoryRouter: Router {
case readRepositories(Configuration, String, String, String)
case readOrganizationRepositories(Configuration, String, String, String)
case readAuthenticatedRepositories(Configuration, String, String)
case readRepository(Configuration, String, String)
case getRepositoryContent(Configuration, String, String, String?, String?)
Expand All @@ -491,6 +542,7 @@ enum RepositoryRouter: Router {
var configuration: Configuration {
switch self {
case let .readRepositories(config, _, _, _): return config
case let .readOrganizationRepositories(config, _, _, _): return config
case let .readAuthenticatedRepositories(config, _, _): return config
case let .readRepository(config, _, _): return config
case let .getRepositoryContent(config, _, _, _, _): return config
Expand All @@ -511,6 +563,8 @@ enum RepositoryRouter: Router {
switch self {
case let .readRepositories(_, _, page, perPage):
return ["per_page": perPage, "page": page]
case let .readOrganizationRepositories(_, _, page, perPage):
return ["per_page": perPage, "page": page]
case let .readAuthenticatedRepositories(_, page, perPage):
return ["per_page": perPage, "page": page]
case .readRepository:
Expand All @@ -531,6 +585,8 @@ enum RepositoryRouter: Router {
switch self {
case let .readRepositories(_, owner, _, _):
return "users/\(owner)/repos"
case let .readOrganizationRepositories(_, org, _, _):
return "orgs/\(org)/repos"
case .readAuthenticatedRepositories:
return "user/repos"
case let .readRepository(_, owner, name):
Expand Down
22 changes: 22 additions & 0 deletions OctoKitCLI/Sources/OctoKitCLI/Modules/Repository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct Repository: AsyncParsableCommand {
subcommands: [
Get.self,
GetList.self,
GetOrgList.self,
GetTopics.self,
GetContent.self,
GetTags.self
Expand Down Expand Up @@ -71,6 +72,27 @@ extension Repository {
}
}

struct GetOrgList: AsyncParsableCommand {
@Argument(help: "The organization name")
var org: String

@Argument(help: "The path to put the file in")
var filePath: String?

@Flag(help: "Verbose output flag")
var verbose: Bool = false

init() {}

mutating func run() async throws {
let session = JSONInterceptingURLSession()
let octokit = makeOctokit(session: session)
_ = try await octokit.organizationRepositories(org: org)
session.verbosePrint(verbose: verbose)
try session.printResponseToFileOrConsole(filePath: filePath)
}
}

struct GetTopics: AsyncParsableCommand {
@Argument(help: "The owner of the repository")
var owner: String
Expand Down
Loading
Loading