Add repository file browser

This commit is contained in:
Georg Bauer
2026-07-31 11:25:46 +02:00
parent 4e4dfb0db9
commit 7b2b431dfd
11 changed files with 669 additions and 21 deletions

View File

@@ -564,6 +564,24 @@ fileprivate struct FfiConverterString: FfiConverter {
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterData: FfiConverterRustBuffer {
typealias SwiftType = Data
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Data {
let len: Int32 = try readInt(&buf)
return Data(try readBytes(&buf, count: Int(len)))
}
public static func write(_ value: Data, into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
writeBytes(&buf, value)
}
}
@@ -599,6 +617,10 @@ public protocol GotchaCoreProtocol: AnyObject, Sendable {
func repositories() async throws -> [RepositoryRow]
func repositoryContents(owner: String, repository: String, path: String) async throws -> [RepositoryContentRow]
func repositoryFile(owner: String, repository: String, path: String) async throws -> Data
func selectServer(index: UInt32) throws
func servers() -> [ServerRow]
@@ -903,6 +925,38 @@ open func repositories()async throws -> [RepositoryRow] {
)
}
open func repositoryContents(owner: String, repository: String, path: String)async throws -> [RepositoryContentRow] {
return
try await uniffiRustCallAsync(
rustFutureFunc: {
uniffi_gotcha_core_fn_method_gotchacore_repository_contents(
self.uniffiCloneHandle(),FfiConverterString.lower(owner),FfiConverterString.lower(repository),FfiConverterString.lower(path)
)
},
pollFunc: ffi_gotcha_core_rust_future_poll_rust_buffer,
completeFunc: ffi_gotcha_core_rust_future_complete_rust_buffer,
freeFunc: ffi_gotcha_core_rust_future_free_rust_buffer,
liftFunc: FfiConverterSequenceTypeRepositoryContentRow.lift,
errorHandler: FfiConverterTypeGotchaError_lift
)
}
open func repositoryFile(owner: String, repository: String, path: String)async throws -> Data {
return
try await uniffiRustCallAsync(
rustFutureFunc: {
uniffi_gotcha_core_fn_method_gotchacore_repository_file(
self.uniffiCloneHandle(),FfiConverterString.lower(owner),FfiConverterString.lower(repository),FfiConverterString.lower(path)
)
},
pollFunc: ffi_gotcha_core_rust_future_poll_rust_buffer,
completeFunc: ffi_gotcha_core_rust_future_complete_rust_buffer,
freeFunc: ffi_gotcha_core_rust_future_free_rust_buffer,
liftFunc: FfiConverterData.lift,
errorHandler: FfiConverterTypeGotchaError_lift
)
}
open func selectServer(index: UInt32)throws {try rustCallWithError(FfiConverterTypeGotchaError_lift) {
uniffiCallStatus in
uniffi_gotcha_core_fn_method_gotchacore_select_server(
@@ -2061,6 +2115,68 @@ public func FfiConverterTypePullRow_lower(_ value: PullRow) -> RustBuffer {
}
public struct RepositoryContentRow: Equatable, Hashable {
public var name: String
public var path: String
public var kind: String
public var size: Int64
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(name: String, path: String, kind: String, size: Int64) {
self.name = name
self.path = path
self.kind = kind
self.size = size
}
}
#if compiler(>=6)
extension RepositoryContentRow: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypeRepositoryContentRow: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> RepositoryContentRow {
return
try RepositoryContentRow(
name: FfiConverterString.read(from: &buf),
path: FfiConverterString.read(from: &buf),
kind: FfiConverterString.read(from: &buf),
size: FfiConverterInt64.read(from: &buf)
)
}
public static func write(_ value: RepositoryContentRow, into buf: inout [UInt8]) {
FfiConverterString.write(value.name, into: &buf)
FfiConverterString.write(value.path, into: &buf)
FfiConverterString.write(value.kind, into: &buf)
FfiConverterInt64.write(value.size, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeRepositoryContentRow_lift(_ buf: RustBuffer) throws -> RepositoryContentRow {
return try FfiConverterTypeRepositoryContentRow.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypeRepositoryContentRow_lower(_ value: RepositoryContentRow) -> RustBuffer {
return FfiConverterTypeRepositoryContentRow.lower(value)
}
public struct RepositoryRow: Equatable, Hashable {
public var name: String
public var owner: String
@@ -2661,6 +2777,31 @@ fileprivate struct FfiConverterSequenceTypePullRow: FfiConverterRustBuffer {
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
fileprivate struct FfiConverterSequenceTypeRepositoryContentRow: FfiConverterRustBuffer {
typealias SwiftType = [RepositoryContentRow]
public static func write(_ value: [RepositoryContentRow], into buf: inout [UInt8]) {
let len = Int32(value.count)
writeInt(&buf, len)
for item in value {
FfiConverterTypeRepositoryContentRow.write(item, into: &buf)
}
}
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [RepositoryContentRow] {
let len: Int32 = try readInt(&buf)
var seq = [RepositoryContentRow]()
seq.reserveCapacity(Int(len))
for _ in 0 ..< len {
seq.append(try FfiConverterTypeRepositoryContentRow.read(from: &buf))
}
return seq
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
@@ -2819,6 +2960,12 @@ private let initializationResult: InitializationResult = {
if (uniffi_gotcha_core_checksum_method_gotchacore_repositories() != 12256) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_gotcha_core_checksum_method_gotchacore_repository_contents() != 8454) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_gotcha_core_checksum_method_gotchacore_repository_file() != 27399) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_gotcha_core_checksum_method_gotchacore_select_server() != 22721) {
return InitializationResult.apiChecksumMismatch
}