Skip to content

but_api macro: Auto export#13712

Draft
estib-vega wants to merge 4 commits into
masterfrom
but-api-auto-export
Draft

but_api macro: Auto export#13712
estib-vega wants to merge 4 commits into
masterfrom
but-api-auto-export

Conversation

@estib-vega
Copy link
Copy Markdown
Contributor

Automagically export the ‘complex types’ referenced in the function
signatures.

  • Introduce but_transport, substituting most of the necessary
    boilerplate.
  • Replace a bunch of boiler-plate code for used for transport

@github-actions github-actions Bot added the rust Pull requests that update Rust code label May 8, 2026
@estib-vega estib-vega requested a review from Copilot May 8, 2026 13:24
@estib-vega estib-vega force-pushed the but-api-auto-export branch from 8f0810f to bb3cdc2 Compare May 8, 2026 13:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new #[but_transport] attribute macro to standardize/auto-generate transport DTO boilerplate (serde + schemars + SDK registration), and updates many Rust DTOs across crates to use it. It also tightens schema export behavior by enforcing transport-marker usage and improving schema collection/duplicate handling for TypeScript generation.

Changes:

  • Added #[but_api_macros::but_transport] and applied it broadly to transport structs/enums to reduce repeated serde/schemars/SDK-registration boilerplate.
  • Updated #[but_api] macro to collect/enforce exported transport types via a new but_schemars::SdkTransportType marker.
  • Improved but-ts schema collection to allow identical duplicate registrations while rejecting incompatible duplicates; updated generated SDK typings accordingly.

Reviewed changes

Copilot reviewed 69 out of 71 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/but-sdk/src/generated/index.d.ts Regenerated SDK typings reflecting new transport macro behavior (notably casing changes).
crates/gitbutler-project/src/project.rs Migrated project DTOs to #[but_transport]; adjusted schema hints for select fields.
crates/gitbutler-project/src/api.rs Migrated API project wrapper DTO to #[but_transport].
crates/gitbutler-project/Cargo.toml Added but-api-macros dependency.
crates/gitbutler-operating-modes/src/lib.rs Converted operating mode DTOs to #[but_transport] and removed manual schema registration boilerplate.
crates/gitbutler-operating-modes/Cargo.toml Added but-api-macros dependency.
crates/gitbutler-edit-mode/src/lib.rs Converted conflict DTO to #[but_transport].
crates/gitbutler-edit-mode/Cargo.toml Added but-api-macros dependency.
crates/gitbutler-branch/src/branch.rs Converted BranchIdentity to #[but_transport] (with serialize/debug disabled due to custom impls).
crates/gitbutler-branch/Cargo.toml Added but-api-macros dependency.
crates/gitbutler-branch-actions/src/upstream_integration.rs Converted multiple upstream integration DTOs to #[but_transport].
crates/gitbutler-branch-actions/src/remote.rs Converted RemoteCommit DTO to #[but_transport].
crates/gitbutler-branch-actions/src/branch.rs Converted branch listing DTOs to #[but_transport].
crates/gitbutler-branch-actions/src/base.rs Converted base-branch DTO to #[but_transport].
crates/gitbutler-branch-actions/Cargo.toml Added but-api-macros dependency; expanded export-schema feature to include but-settings/export-schema.
crates/but-workspace/src/ui/ref_info.rs Converted ref-info UI DTOs to #[but_transport]; adjusted imports.
crates/but-workspace/src/ui/mod.rs Converted several UI DTOs/enums to #[but_transport] and removed manual schema registration.
crates/but-workspace/src/ui/author.rs Converted UI author DTO to #[but_transport].
crates/but-workspace/src/legacy/ui.rs Converted legacy UI DTOs to #[but_transport].
crates/but-workspace/src/legacy/mod.rs Converted StacksFilter to #[but_transport] (not registered).
crates/but-workspace/src/commit/squash_commits.rs Converted message-combination strategy enum to #[but_transport].
crates/but-workspace/Cargo.toml Added but-api-macros dependency.
crates/but-ts/src/main.rs Refactored schema duplicate validation; added tests for duplicate handling.
crates/but-settings/src/app_settings.rs Converted settings DTOs to #[but_transport]; removed manual registration calls.
crates/but-settings/Cargo.toml Added but-api-macros dependency; added export-schema feature flag (empty).
crates/but-schemars/src/lib.rs Added SdkTransportType marker trait for transport DTO enforcement.
crates/but-rebase/src/graph_rebase/mutate.rs Converted InsertSide enum to #[but_transport].
crates/but-rebase/Cargo.toml Added but-api-macros dependency.
crates/but-irc/Cargo.toml Switched but-settings dependency to workspace dependency.
crates/but-hunk-dependency/src/ui.rs Converted hunk dependency UI DTOs to #[but_transport].
crates/but-hunk-dependency/src/ranges/mod.rs Converted calculation error DTO to #[but_transport].
crates/but-hunk-dependency/Cargo.toml Added but-api-macros dependency.
crates/but-hunk-assignment/src/lib.rs Converted multiple hunk assignment DTOs/enums to #[but_transport] with tagging/rename options.
crates/but-hunk-assignment/Cargo.toml Added but-api-macros dependency; reformatted export-schema feature list.
crates/but-gitlab/src/token.rs Converted GitLab account identifier DTO to #[but_transport].
crates/but-gitlab/src/lib.rs Converted sensitive JSON response DTOs to #[but_transport].
crates/but-gitlab/Cargo.toml Added but-api-macros dependency.
crates/but-github/src/token.rs Converted GitHub account identifier DTO to #[but_transport].
crates/but-github/src/lib.rs Converted sensitive JSON response DTOs to #[but_transport].
crates/but-github/Cargo.toml Added but-api-macros dependency; expanded export-schema feature to include but-settings/export-schema.
crates/but-forge/src/review.rs Converted forge review DTOs to #[but_transport]; added schema hints for select chrono fields.
crates/but-forge/src/forge.rs Converted ForgeName/ForgeUser transport enums to #[but_transport].
crates/but-forge/src/ci.rs Converted CI DTOs to #[but_transport]; added schema hints for chrono fields.
crates/but-forge/Cargo.toml Added but-api-macros dependency.
crates/but-error/src/lib.rs Converted error Code enum to #[but_transport]; added serde dependency/import.
crates/but-error/Cargo.toml Added but-api-macros + serde dependencies.
crates/but-core/src/unified_diff.rs Converted DiffHunk to #[but_transport].
crates/but-core/src/ui.rs Converted UI worktree change DTOs/enums to #[but_transport].
crates/but-core/src/tree/mod.rs Converted RejectionReason to #[but_transport].
crates/but-core/src/settings.rs Converted git-config UI DTO to #[but_transport].
crates/but-core/src/ref_metadata.rs Converted metadata DTOs to #[but_transport] with schema rename.
crates/but-core/src/lib.rs Converted UnifiedPatch and ignored-worktree DTOs to #[but_transport].
crates/but-core/src/diff/commit_details.rs Converted LineStats to #[but_transport].
crates/but-core/src/diff_types.rs Converted diff-spec and hunk header DTOs to #[but_transport].
crates/but-core/src/commit/mod.rs Converted ConflictEntries to #[but_transport].
crates/but-core/Cargo.toml Added but-api-macros dependency.
crates/but-api/src/workspace.rs Converted workspace JSON DTOs to #[but_transport].
crates/but-api/src/watcher.rs Converted watcher payload DTOs to #[but_transport]; removed direct schemars derive usage.
crates/but-api/src/platform.rs Converted ServerCapabilities to #[but_transport(register = false)].
crates/but-api/src/legacy/stack.rs Converted legacy push result DTO to #[but_transport].
crates/but-api/src/legacy/projects.rs Converted ProjectForFrontend DTO to #[but_transport].
crates/but-api/src/legacy/modes.rs Converted legacy mode DTOs to #[but_transport].
crates/but-api/src/legacy/forge.rs Converted review template DTO to #[but_transport].
crates/but-api/src/json.rs Converted shared JSON DTOs to #[but_transport].
crates/but-api/src/diff.rs Converted diff JSON DTO to #[but_transport].
crates/but-api/src/commit/json.rs Converted commit JSON DTOs to #[but_transport].
crates/but-api/src/branch.rs Converted branch JSON DTOs to #[but_transport].
crates/but-api/Cargo.toml Made but-schemars optional and tied to export-schema; expanded export-schema feature deps.
crates/but-api-macros/src/lib.rs Implemented #[but_transport]; added schema-export type collection and transport-marker enforcement in #[but_api].
Cargo.lock Updated lockfile for new/adjusted dependencies.
Comments suppressed due to low confidence (1)

crates/gitbutler-project/src/api.rs:18

  • #[but_transport(register = false)] defaults to #[serde(rename_all = "camelCase")], which renames these computed fields from gerrit_mode / forge_review_template_path to gerritMode / forgeReviewTemplatePath in JSON and in the generated SDK typings. The desktop app still expects the original snake_case keys (e.g. projectsService.getProject(...).response?.gerrit_mode). If the legacy API is meant to remain snake_case, pass rename_all = "snake_case" here (and keep #[serde(default)] behavior), or update all consumers in the same change set to use the camelCase keys.

Comment on lines +179 to 185
#[but_api_macros::but_transport]
pub struct ProjectForFrontend {
#[serde(flatten)]
pub inner: gitbutler_project::api::Project,
/// Tell if the project is known to be open in a Window in the frontend.
pub is_open: bool,
}
@estib-vega estib-vega force-pushed the but-api-auto-export branch 2 times, most recently from 9e1ad56 to e44b673 Compare May 8, 2026 14:19
@estib-vega estib-vega force-pushed the but-api-auto-export branch from e44b673 to 591dd4b Compare May 11, 2026 08:11
Automagically export the ‘complex types’ referenced in the function
signatures.

- Introduce `but_transport`, substituting most of the necessary
  boilerplate.
- Allow unexpected cfgs
- Update snapshot to the new lines
@estib-vega estib-vega force-pushed the but-api-auto-export branch from 591dd4b to 769a0a5 Compare May 11, 2026 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

@gitbutler/desktop rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants