Add pull request milestone features

This commit is contained in:
Georg Bauer
2026-07-31 14:22:21 +02:00
parent c5ecb8f87d
commit 86200b4668
9 changed files with 474 additions and 52 deletions

View File

@@ -633,6 +633,10 @@ public protocol GotchaCoreProtocol: AnyObject, Sendable {
func pullDiff(owner: String, repository: String, number: Int64, path: String) async throws -> DiffPage
func pullFilters() async throws -> PullFilterOptions
func pullFiltersActive() throws -> Bool
func pulls() async throws -> [PullRow]
func repositories() async throws -> [RepositoryRow]
@@ -651,6 +655,8 @@ public protocol GotchaCoreProtocol: AnyObject, Sendable {
func setIssueStatus(status: String) throws
func setPullFilters(milestone: String) throws
func setPullStatus(status: String) throws
func settings() -> Settings
@@ -942,6 +948,31 @@ open func pullDiff(owner: String, repository: String, number: Int64, path: Strin
)
}
open func pullFilters()async throws -> PullFilterOptions {
return
try await uniffiRustCallAsync(
rustFutureFunc: {
uniffi_gotcha_core_fn_method_gotchacore_pull_filters(
self.uniffiCloneHandle()
)
},
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: FfiConverterTypePullFilterOptions_lift,
errorHandler: FfiConverterTypeGotchaError_lift
)
}
open func pullFiltersActive()throws -> Bool {
return try FfiConverterBool.lift(try rustCallWithError(FfiConverterTypeGotchaError_lift) {
uniffiCallStatus in
uniffi_gotcha_core_fn_method_gotchacore_pull_filters_active(
self.uniffiCloneHandle(),uniffiCallStatus
)
})
}
open func pulls()async throws -> [PullRow] {
return
try await uniffiRustCallAsync(
@@ -1054,6 +1085,15 @@ open func setIssueStatus(status: String)throws {try rustCallWithError(FfiConve
}
}
open func setPullFilters(milestone: String)throws {try rustCallWithError(FfiConverterTypeGotchaError_lift) {
uniffiCallStatus in
uniffi_gotcha_core_fn_method_gotchacore_set_pull_filters(
self.uniffiCloneHandle(),
FfiConverterString.lower(milestone),uniffiCallStatus
)
}
}
open func setPullStatus(status: String)throws {try rustCallWithError(FfiConverterTypeGotchaError_lift) {
uniffiCallStatus in
uniffi_gotcha_core_fn_method_gotchacore_set_pull_status(
@@ -1977,12 +2017,14 @@ public func FfiConverterTypeLabelRow_lower(_ value: LabelRow) -> RustBuffer {
public struct MilestonePage: Equatable, Hashable {
public var milestone: MilestoneRow
public var issues: [IssueRow]
public var pulls: [PullRow]
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(milestone: MilestoneRow, issues: [IssueRow]) {
public init(milestone: MilestoneRow, issues: [IssueRow], pulls: [PullRow]) {
self.milestone = milestone
self.issues = issues
self.pulls = pulls
}
@@ -2002,13 +2044,15 @@ public struct FfiConverterTypeMilestonePage: FfiConverterRustBuffer {
return
try MilestonePage(
milestone: FfiConverterTypeMilestoneRow.read(from: &buf),
issues: FfiConverterSequenceTypeIssueRow.read(from: &buf)
issues: FfiConverterSequenceTypeIssueRow.read(from: &buf),
pulls: FfiConverterSequenceTypePullRow.read(from: &buf)
)
}
public static func write(_ value: MilestonePage, into buf: inout [UInt8]) {
FfiConverterTypeMilestoneRow.write(value.milestone, into: &buf)
FfiConverterSequenceTypeIssueRow.write(value.issues, into: &buf)
FfiConverterSequenceTypePullRow.write(value.pulls, into: &buf)
}
}
@@ -2102,6 +2146,60 @@ public func FfiConverterTypeMilestoneRow_lower(_ value: MilestoneRow) -> RustBuf
}
public struct PullFilterOptions: Equatable, Hashable {
public var milestones: [String]
public var selectedMilestone: String
// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(milestones: [String], selectedMilestone: String) {
self.milestones = milestones
self.selectedMilestone = selectedMilestone
}
}
#if compiler(>=6)
extension PullFilterOptions: Sendable {}
#endif
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public struct FfiConverterTypePullFilterOptions: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PullFilterOptions {
return
try PullFilterOptions(
milestones: FfiConverterSequenceString.read(from: &buf),
selectedMilestone: FfiConverterString.read(from: &buf)
)
}
public static func write(_ value: PullFilterOptions, into buf: inout [UInt8]) {
FfiConverterSequenceString.write(value.milestones, into: &buf)
FfiConverterString.write(value.selectedMilestone, into: &buf)
}
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypePullFilterOptions_lift(_ buf: RustBuffer) throws -> PullFilterOptions {
return try FfiConverterTypePullFilterOptions.lift(buf)
}
#if swift(>=5.8)
@_documentation(visibility: private)
#endif
public func FfiConverterTypePullFilterOptions_lower(_ value: PullFilterOptions) -> RustBuffer {
return FfiConverterTypePullFilterOptions.lower(value)
}
public struct PullPage: Equatable, Hashable {
public var title: String
public var meta: String
@@ -3153,6 +3251,12 @@ private let initializationResult: InitializationResult = {
if (uniffi_gotcha_core_checksum_method_gotchacore_pull_diff() != 61384) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_gotcha_core_checksum_method_gotchacore_pull_filters() != 10064) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_gotcha_core_checksum_method_gotchacore_pull_filters_active() != 20260) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_gotcha_core_checksum_method_gotchacore_pulls() != 13092) {
return InitializationResult.apiChecksumMismatch
}
@@ -3180,6 +3284,9 @@ private let initializationResult: InitializationResult = {
if (uniffi_gotcha_core_checksum_method_gotchacore_set_issue_status() != 44445) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_gotcha_core_checksum_method_gotchacore_set_pull_filters() != 39023) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_gotcha_core_checksum_method_gotchacore_set_pull_status() != 1356) {
return InitializationResult.apiChecksumMismatch
}

View File

@@ -334,6 +334,16 @@ uint64_t uniffi_gotcha_core_fn_method_gotchacore_pull(uint64_t ptr, RustBuffer o
uint64_t uniffi_gotcha_core_fn_method_gotchacore_pull_diff(uint64_t ptr, RustBuffer owner, RustBuffer repository, int64_t number, RustBuffer path
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_GOTCHA_CORE_FN_METHOD_GOTCHACORE_PULL_FILTERS
#define UNIFFI_FFIDEF_UNIFFI_GOTCHA_CORE_FN_METHOD_GOTCHACORE_PULL_FILTERS
uint64_t uniffi_gotcha_core_fn_method_gotchacore_pull_filters(uint64_t ptr
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_GOTCHA_CORE_FN_METHOD_GOTCHACORE_PULL_FILTERS_ACTIVE
#define UNIFFI_FFIDEF_UNIFFI_GOTCHA_CORE_FN_METHOD_GOTCHACORE_PULL_FILTERS_ACTIVE
int8_t uniffi_gotcha_core_fn_method_gotchacore_pull_filters_active(uint64_t ptr, RustCallStatus *_Nonnull out_status
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_GOTCHA_CORE_FN_METHOD_GOTCHACORE_PULLS
#define UNIFFI_FFIDEF_UNIFFI_GOTCHA_CORE_FN_METHOD_GOTCHACORE_PULLS
uint64_t uniffi_gotcha_core_fn_method_gotchacore_pulls(uint64_t ptr
@@ -379,6 +389,11 @@ void uniffi_gotcha_core_fn_method_gotchacore_set_issue_filters(uint64_t ptr, Rus
void uniffi_gotcha_core_fn_method_gotchacore_set_issue_status(uint64_t ptr, RustBuffer status, RustCallStatus *_Nonnull out_status
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_GOTCHA_CORE_FN_METHOD_GOTCHACORE_SET_PULL_FILTERS
#define UNIFFI_FFIDEF_UNIFFI_GOTCHA_CORE_FN_METHOD_GOTCHACORE_SET_PULL_FILTERS
void uniffi_gotcha_core_fn_method_gotchacore_set_pull_filters(uint64_t ptr, RustBuffer milestone, RustCallStatus *_Nonnull out_status
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_GOTCHA_CORE_FN_METHOD_GOTCHACORE_SET_PULL_STATUS
#define UNIFFI_FFIDEF_UNIFFI_GOTCHA_CORE_FN_METHOD_GOTCHACORE_SET_PULL_STATUS
void uniffi_gotcha_core_fn_method_gotchacore_set_pull_status(uint64_t ptr, RustBuffer status, RustCallStatus *_Nonnull out_status
@@ -747,6 +762,18 @@ uint16_t uniffi_gotcha_core_checksum_method_gotchacore_pull(void
#define UNIFFI_FFIDEF_UNIFFI_GOTCHA_CORE_CHECKSUM_METHOD_GOTCHACORE_PULL_DIFF
uint16_t uniffi_gotcha_core_checksum_method_gotchacore_pull_diff(void
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_GOTCHA_CORE_CHECKSUM_METHOD_GOTCHACORE_PULL_FILTERS
#define UNIFFI_FFIDEF_UNIFFI_GOTCHA_CORE_CHECKSUM_METHOD_GOTCHACORE_PULL_FILTERS
uint16_t uniffi_gotcha_core_checksum_method_gotchacore_pull_filters(void
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_GOTCHA_CORE_CHECKSUM_METHOD_GOTCHACORE_PULL_FILTERS_ACTIVE
#define UNIFFI_FFIDEF_UNIFFI_GOTCHA_CORE_CHECKSUM_METHOD_GOTCHACORE_PULL_FILTERS_ACTIVE
uint16_t uniffi_gotcha_core_checksum_method_gotchacore_pull_filters_active(void
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_GOTCHA_CORE_CHECKSUM_METHOD_GOTCHACORE_PULLS
@@ -801,6 +828,12 @@ uint16_t uniffi_gotcha_core_checksum_method_gotchacore_set_issue_filters(void
#define UNIFFI_FFIDEF_UNIFFI_GOTCHA_CORE_CHECKSUM_METHOD_GOTCHACORE_SET_ISSUE_STATUS
uint16_t uniffi_gotcha_core_checksum_method_gotchacore_set_issue_status(void
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_GOTCHA_CORE_CHECKSUM_METHOD_GOTCHACORE_SET_PULL_FILTERS
#define UNIFFI_FFIDEF_UNIFFI_GOTCHA_CORE_CHECKSUM_METHOD_GOTCHACORE_SET_PULL_FILTERS
uint16_t uniffi_gotcha_core_checksum_method_gotchacore_set_pull_filters(void
);
#endif
#ifndef UNIFFI_FFIDEF_UNIFFI_GOTCHA_CORE_CHECKSUM_METHOD_GOTCHACORE_SET_PULL_STATUS

View File

@@ -426,18 +426,32 @@ final class MilestoneViewController: RefreshingTableViewController {
}
}
override func numberOfSections(in tableView: UITableView) -> Int { page == nil ? 0 : 2 }
override func numberOfSections(in tableView: UITableView) -> Int { page == nil ? 0 : 3 }
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
section == 0 ? 1 : page?.issues.count ?? 0
switch section {
case 0: 1
case 1: page?.issues.count ?? 0
default: page?.pulls.count ?? 0
}
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
section == 1 ? "Issues" : nil
switch section {
case 1: "Issues"
case 2: "Pull Requests"
default: nil
}
}
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
section == 1 && page?.issues.isEmpty == true ? "No issues are assigned to this milestone." : nil
if section == 1, page?.issues.isEmpty == true {
return "No issues are assigned to this milestone."
}
if section == 2, page?.pulls.isEmpty == true {
return "No pull requests are assigned to this milestone."
}
return nil
}
override func tableView(
@@ -453,23 +467,42 @@ final class MilestoneViewController: RefreshingTableViewController {
cell.configure(page.milestone, disclosure: false)
return cell
}
let cell = tableView.dequeueReusableCell(withIdentifier: "issue", for: indexPath) as! IssueCell
cell.configure(page.issues[indexPath.row])
if indexPath.section == 1 {
let cell = tableView.dequeueReusableCell(withIdentifier: "issue", for: indexPath) as! IssueCell
cell.configure(page.issues[indexPath.row])
return cell
}
let cell = tableView.dequeueReusableCell(withIdentifier: "pull")
?? UITableViewCell(style: .subtitle, reuseIdentifier: "pull")
let pull = page.pulls[indexPath.row]
configureTextCell(cell, title: pull.title, detail: "\(pull.summary)\n\(pull.meta)")
cell.accessoryType = .disclosureIndicator
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard indexPath.section == 1, let issue = page?.issues[indexPath.row] else { return }
tableView.deselectRow(at: indexPath, animated: true)
navigationController?.pushViewController(
IssueViewController(
context: context,
owner: owner,
repository: repository,
number: issue.number
),
animated: true
)
if indexPath.section == 1, let issue = page?.issues[indexPath.row] {
navigationController?.pushViewController(
IssueViewController(
context: context,
owner: owner,
repository: repository,
number: issue.number
),
animated: true
)
} else if indexPath.section == 2, let pull = page?.pulls[indexPath.row] {
navigationController?.pushViewController(
PullViewController(
context: context,
owner: pull.owner,
repository: pull.repository,
number: pull.number
),
animated: true
)
}
}
}
@@ -522,6 +555,8 @@ final class MilestoneCell: UITableViewCell {
final class PullsViewController: RefreshingTableViewController {
private let context: AppContext
private var rows: [PullRow] = []
private var filterOptions: PullFilterOptions?
private var filterTask: Task<Void, Never>?
init(context: AppContext) {
self.context = context
@@ -532,6 +567,8 @@ final class PullsViewController: RefreshingTableViewController {
@available(*, unavailable)
required init?(coder: NSCoder) { fatalError("init(coder:) is not supported") }
deinit { filterTask?.cancel() }
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.leftBarButtonItem = UIBarButtonItem(
@@ -557,6 +594,11 @@ final class PullsViewController: RefreshingTableViewController {
refreshControl?.endRefreshing()
return
}
loadFilterOptions()
loadPulls(refreshing: refreshing)
}
private func loadPulls(refreshing: Bool) {
beginLoading(refreshing: refreshing)
loadingTask?.cancel()
loadingTask = Task {
@@ -567,7 +609,9 @@ final class PullsViewController: RefreshingTableViewController {
tableView.backgroundView = rows.isEmpty
? EmptyBackgroundView(
title: "No \(status) pull requests",
detail: "No pull requests match the selected status."
detail: filtersActive
? "No pull requests match the selected filters."
: "No pull requests match the selected status."
)
: nil
} catch {
@@ -577,6 +621,19 @@ final class PullsViewController: RefreshingTableViewController {
}
}
private func loadFilterOptions() {
filterTask?.cancel()
filterTask = Task {
do {
filterOptions = try await context.core.pullFilters()
guard !Task.isCancelled else { return }
updateFilterMenu()
} catch {
if !Task.isCancelled { show(error: error) }
}
}
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
rows.count
}
@@ -617,22 +674,74 @@ final class PullsViewController: RefreshingTableViewController {
private func updateFilterMenu() {
let current = context.core.settings().pullStatus
navigationItem.rightBarButtonItem = UIBarButtonItem(
image: context.symbol("line.3.horizontal.decrease.circle"),
menu: UIMenu(children: ["open", "closed"].map { status in
let status = UIMenu(
title: "Status",
image: context.symbol("circle.lefthalf.filled"),
options: .singleSelection,
children: ["open", "closed"].map { status in
UIAction(title: status.capitalized, state: current == status ? .on : .off) {
[weak self] _ in
guard let self else { return }
do {
try self.context.core.setPullStatus(status: status)
self.updateFilterMenu()
self.loadContent(refreshing: false)
self.loadPulls(refreshing: false)
} catch {
self.show(error: error)
}
}
})
}
)
let milestone: UIMenuElement = filterOptions.map(milestoneMenu)
?? UIAction(title: "Loading milestones…", attributes: .disabled) { _ in }
let item = navigationItem.rightBarButtonItem ?? UIBarButtonItem(
image: context.symbol("line.3.horizontal.decrease.circle")
)
item.menu = UIMenu(children: [status, milestone])
item.accessibilityLabel = "Filter pull requests"
navigationItem.rightBarButtonItem = item
updateFilterTint()
}
private func milestoneMenu(_ options: PullFilterOptions) -> UIMenu {
let selected = options.selectedMilestone
let all = UIAction(title: "All Milestones", state: selected.isEmpty ? .on : .off) {
[weak self] _ in self?.selectMilestone("")
}
let milestones = options.milestones.map { milestone in
UIAction(title: milestone, state: selected == milestone ? .on : .off) {
[weak self] _ in self?.selectMilestone(milestone)
}
}
return UIMenu(
title: "Milestone",
image: context.symbol("flag"),
options: .singleSelection,
children: [all] + milestones
)
}
private func selectMilestone(_ milestone: String) {
filterTask?.cancel()
do {
try context.core.setPullFilters(milestone: milestone)
filterOptions?.selectedMilestone = milestone
updateFilterMenu()
loadPulls(refreshing: false)
} catch {
show(error: error)
}
}
private var filtersActive: Bool {
(try? context.core.pullFiltersActive()) ?? false
}
private func updateFilterTint() {
navigationItem.rightBarButtonItem?.tintColor = filtersActive ? .tintColor : .secondaryLabel
navigationItem.rightBarButtonItem?.accessibilityValue = filtersActive
? "Filters active"
: "Default filters"
}
}