commit f21292978c6b393913201cd364e9d3394ce8502b Author: Georg Bauer Date: Thu Jul 30 11:41:19 2026 +0200 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3d62c7b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target +.env + diff --git a/API_COVERAGE.md b/API_COVERAGE.md new file mode 100644 index 0000000..697af57 --- /dev/null +++ b/API_COVERAGE.md @@ -0,0 +1,41 @@ +# Gitea API coverage + +Source: the OpenAPI contract served by the configured Gitea 1.25.4 instance. +It contains 299 paths, 467 operations, 243 read/query operations, and 216 schema +definitions. + +`gotcha_gitea` exposes the complete typed Gitea 1.25 client through +`gotcha_gitea::apis` and every generated request/response model through +`gotcha_gitea::models`. `Client::configuration()` supplies the selected base URL +and token to those generated functions. + +| Domain | Queries | Other actions | API crate | CLI queries | CLI writes | Capabilities | +| --- | ---: | ---: | --- | ---: | ---: | --- | +| activitypub | 1 | 1 | Complete | 0 | 0 | Person actors and inbox federation | +| admin | 14 | 18 | Complete | 0 | 0 | Users, organizations, email, hooks, cron, unadopted repositories, Actions runners/jobs/runs | +| issue | 23 | 46 | Complete | 5 | 7 | Issues, comments, attachments, reactions, labels, milestones, dependencies, subscriptions, time tracking, pins | +| miscellaneous | 10 | 3 | Complete | 1 | 0 | Version, templates, licenses, node info, signing keys, Markdown/markup rendering | +| notification | 4 | 3 | Complete | 0 | 0 | Notification threads, unread checks, read state | +| organization | 33 | 33 | Complete | 0 | 0 | Organizations, members, teams, repositories, labels, hooks, blocks, activities, Actions | +| package | 5 | 3 | Complete | 0 | 0 | Packages, versions, files, linking and deletion | +| repository | 105 | 86 | Complete | 6 | 3 | Search, repositories, branches, protections, commits, content, refs, tags, releases, pull requests, reviews, collaborators, hooks, wiki, mirrors, Actions | +| settings | 4 | 0 | Complete | 0 | 0 | Instance API, attachment, repository, and UI settings | +| user | 44 | 31 | Complete | 2 | 0 | Users, profile, following, stars, watches, keys, GPG, email, hooks, OAuth, tokens, blocks, Actions, tracked time | +| **Total** | **243** | **224** | **467/467** | **14/243** | **10/224** | | + +## CLI status + +Typed text commands currently implemented include: + +- `server version` → `getVersion` +- `user show` → `userGetCurrent` +- `repo list` → `userCurrentListRepos` +- `repo show` → `repoGet` +- issue list/show/create/edit/delete/comments/comment +- milestone list/show/create/edit/delete +- pull list/show/create/edit/merge/commits/files/reviews + +The remaining 229 query operations and 214 mutation operations are available to +Rust callers through the typed API modules but do not yet have purpose-built CLI +commands or text/input views. `api request` remains an explicit JSON escape hatch; +it is not counted as typed CLI coverage. diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..bcc4910 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1736 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "aws-lc-rs" +version = "1.17.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00bdb5da18dac48ca2cc7cd4a98e533e8635a58e2361d13a1a4ee3888e0d72f1" +dependencies = [ + "aws-lc-sys", + "zeroize", +] + +[[package]] +name = "aws-lc-sys" +version = "0.43.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43103168cc76fe62678a375e722fc9cb3a0146159ac5828bc4f0dfd755c2224c" +dependencies = [ + "cc", + "cmake", + "dunce", + "fs_extra", + "pkg-config", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b588b76d00fde79687d7646a9b5bdf3cc0f655e0bbd080335a95d7e96f3587da" + +[[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + +[[package]] +name = "bytes" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" + +[[package]] +name = "cc" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5add81bb678e6cb321aff7fa0dc7689ad82b112dbc032cea19f91d6b8e3582b9" +dependencies = [ + "find-msvc-tools", + "jobserver", + "libc", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "cfg_aliases" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" + +[[package]] +name = "chacha20" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d524456ba66e72eb8b115ff89e01e497f8e6d11d78b70b1aa13c0fbd97540a81" +dependencies = [ + "cfg-if", + "cpufeatures", + "rand_core", +] + +[[package]] +name = "cmake" +version = "0.1.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0f78a02292a74a88ac736019ab962ece0bc380e3f977bf72e376c5d78ff0678" +dependencies = [ + "cc", +] + +[[package]] +name = "combine" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" +dependencies = [ + "bytes", + "memchr", +] + +[[package]] +name = "core-foundation" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cpufeatures" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201" +dependencies = [ + "libc", +] + +[[package]] +name = "displaydoc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.3", +] + +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + +[[package]] +name = "futures-channel" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "262590f4fe6afeb0bc83be1daa64e52657fe185690a958af7f3ad0e92085c5ae" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cd50c473c80f6d7c3670a752354b8e569b1a7cbfdc0419ec88e5edad85e0dc7" + +[[package]] +name = "futures-io" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4577ecaa3c4f96589d473f679a71b596316f6641bc350038b962a5daf0085d7a" + +[[package]] +name = "futures-macro" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d6d3cde68c518367be28956066ddfef33813991b77a55005a69dae04bf3b10b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "futures-sink" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e34418ac499d6305c2fb5ad0ed2f6ac998c5f8ca209b4510f7f94242c647e307" + +[[package]] +name = "futures-task" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b231ed28831efb4a61a08580c4bc233ec56bc009f4cd8f52da2c3cb97df0c109" + +[[package]] +name = "futures-util" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a77a90a256fce34da66415271e30f94ee91c57b04b8a2c042d9cf3220179deaa" +dependencies = [ + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi", + "rand_core", + "wasm-bindgen", +] + +[[package]] +name = "gitea-client" +version = "1.25.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8d7ee6af6705c898e79464b74e6f6a6b6271baa6b015e34383b7687d21d8dbb" +dependencies = [ + "reqwest", + "serde", + "serde_json", + "serde_repr", + "tokio", + "tokio-util", + "url", +] + +[[package]] +name = "gotcha-cli" +version = "0.1.0" +dependencies = [ + "gotcha_gitea", + "rpassword", + "serde", + "serde_json", + "serde_yaml", + "tokio", +] + +[[package]] +name = "gotcha_gitea" +version = "0.1.0" +dependencies = [ + "gitea-client", + "reqwest", + "serde", + "serde_json", +] + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + +[[package]] +name = "http" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9f41fd6a08e4d4ec69df65976da761afd5ad5e58a9d4acb46bd1c953a9e3ff2" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "hyper" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d22053281f852e11534f5198498373cbb59295120a20771d90f7ed1897490a72" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ca68d021ef39cf6463ab54c1d0f5daf03377b70561305bb89a8f83aab66e0f" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "tokio", + "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "base64", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "icu_collections" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" +dependencies = [ + "displaydoc", + "potential_utf", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" + +[[package]] +name = "icu_properties" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" + +[[package]] +name = "icu_provider" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "ipnet" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2" + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "jni" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5efd9a482cf3a427f00d6b35f14332adc7902ce91efb778580e180ff90fa3498" +dependencies = [ + "cfg-if", + "combine", + "jni-macros", + "jni-sys", + "log", + "simd_cesu8", + "thiserror", + "walkdir", + "windows-link", +] + +[[package]] +name = "jni-macros" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a00109accc170f0bdb141fed3e393c565b6f5e072365c3bd58f5b062591560a3" +dependencies = [ + "proc-macro2", + "quote", + "rustc_version", + "simd_cesu8", + "syn 2.0.119", +] + +[[package]] +name = "jni-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6377a88cb3910bee9b0fa88d4f42e1d2da8e79915598f65fb0c7ee14c878af2" +dependencies = [ + "jni-sys-macros", +] + +[[package]] +name = "jni-sys-macros" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38c0b942f458fe50cdac086d2f946512305e5631e720728f2a61aabcd47a6264" +dependencies = [ + "quote", + "syn 2.0.119", +] + +[[package]] +name = "jobserver" +version = "0.1.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3" +dependencies = [ + "getrandom 0.4.3", + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53b44bfcdb3f8d5837a46dae1ca9660a837176eee74a28b229bc626816589102" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.189" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" + +[[package]] +name = "litemap" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" + +[[package]] +name = "log" +version = "0.4.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad" + +[[package]] +name = "lru-slab" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "mio" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30d65c71f1ce40ab09135ce117d742b9f8a19ff91a41a8b57ed50bc2de59c427" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "openssl-probe" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "pkg-config" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e" + +[[package]] +name = "potential_utf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0103b1cef7ec0cf76490e969665504990193874ea05c85ff9bab8b911d0a0564" +dependencies = [ + "zerovec", +] + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quinn" +version = "0.11.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c1a41e437b6bbd489372cd4971de128e85c855f56c57f283d20ff016cf7c0a8" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4bfc015262b9df63c8845072ce59068853ff5872180c2ce2f13038b970e560" +dependencies = [ + "aws-lc-rs", + "bytes", + "getrandom 0.4.3", + "lru-slab", + "rand", + "rand_pcg", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35a133f956daabe89a61a685c2649f13d82d5aa4bd5d12d1277e1072a21c0694" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.61.2", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rand" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80" +dependencies = [ + "chacha20", + "getrandom 0.4.3", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + +[[package]] +name = "rand_pcg" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caa0f4137e1c0a72f4c651489402276c8e8e1cf081f3b0ba156d2cbeef09e86a" +dependencies = [ + "rand_core", +] + +[[package]] +name = "reqwest" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "219c5811de6525e5416c7d5d53bb656d3afdbc6c5af816e0802bcfa42dbdc1c3" +dependencies = [ + "base64", + "bytes", + "futures-core", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "mime_guess", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "rustls-platform-verifier", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tokio-util", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-streams", + "web-sys", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rpassword" +version = "7.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2da316a15f47e3d053de9cb2c439650bd8fa4aaeb9365f2e5f27f492ff73c196" +dependencies = [ + "libc", + "rtoolbox", + "windows-sys 0.61.2", +] + +[[package]] +name = "rtoolbox" +version = "0.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50a0e551c1e27e1731aba276dbeaeac73f53c7cd34d1bda485d02bd1e0f36844" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] + +[[package]] +name = "rustc-hash" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustls" +version = "0.23.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0283386ce02abc0151e1761d08802dfe86c173b0b494af5cbc086574e453da06" +dependencies = [ + "aws-lc-rs", + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-native-certs" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dab5152771c58876a2146916e53e35057e1a4dfa2b9df0f0305b07f611fdea4d" +dependencies = [ + "openssl-probe", + "rustls-pki-types", + "schannel", + "security-framework", +] + +[[package]] +name = "rustls-pki-types" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96" +dependencies = [ + "web-time", + "zeroize", +] + +[[package]] +name = "rustls-platform-verifier" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d1e2536ce4f35f4846aa13bff16bd0ff40157cdb14cc056c7b14ba41233ba0" +dependencies = [ + "core-foundation", + "core-foundation-sys", + "jni", + "log", + "once_cell", + "rustls", + "rustls-native-certs", + "rustls-platform-verifier-android", + "rustls-webpki", + "security-framework", + "security-framework-sys", + "webpki-root-certs", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls-platform-verifier-android" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f87165f0995f63a9fbeea62b64d10b4d9d8e78ec6d7d51fb2125fda7bb36788f" + +[[package]] +name = "rustls-webpki" +version = "0.103.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c429a8649f110dddef65e2a5ad240f747e85f7758a6bccc7e5777bd33f756e" +dependencies = [ + "aws-lc-rs", + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "schannel" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91c1b7e4904c873ef0710c1f407dde2e6287de2bebc1bbbf7d430bb7cbffd939" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "security-framework" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.3", +] + +[[package]] +name = "serde_json" +version = "1.0.151" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_repr" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d3b1629de253c70a0508c3899572da79ca359fdab27c7920ff00406df418906" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.3", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_yaml" +version = "0.9.34+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" +dependencies = [ + "indexmap", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "simd_cesu8" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11031e251abf8611c80f460e19dbdeb54a66db918e49c65a7065b46ac7aec520" +dependencies = [ + "rustc_version", + "simdutf8", +] + +[[package]] +name = "simdutf8" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90" + +[[package]] +name = "socket2" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "thiserror" +version = "2.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09a43598840e33d5b0331f38c5e30d13bb11c11210a4b58f0d9b18a5a5eefcd9" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43cbfe0cf76104d42a574802844187e84a305e531ed54455f11fbde0f10541cd" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.3", +] + +[[package]] +name = "tinystr" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8323304221c2a851516f22236c5722a72eaa19749016521d6dff0824447d96d" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb4ebadaa0af04fab11ae01eb5f9fdb5f9c5b875506e210e71c07873528baa7f" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed" +dependencies = [ + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.3", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "494815d09bf52b5548659851081238f0ca39ff638363907596da739561c62c52" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "libc", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-http" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840" +dependencies = [ + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", + "url", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicase" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "unsafe-libyaml" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasm-bindgen" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b067c0c11094aef6b7a801c1e34a26affafdf3d051dba08456b868789aaf9a4" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62df1340f32221cb9c54d6a27b030e3dba64361d4a95bed55f9aacb44da291d" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167ce5e579f6bcf889c4f7175a8a5a585de84e8ff93976ce393efa5f2837aab1" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3997c7839262f4ef12cf90b818d6340c18e80f263f1a94bf157d0ec4420380e" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 2.0.119", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc1b4cb0cc549fcf58d7dfc081778139b3d283a081644e833e84682ad71cea24" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "wasm-streams" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d1ec4f6517c9e11ae630e200b2b65d193279042e28edd4a2cda233e46670bbb" +dependencies = [ + "futures-util", + "js-sys", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "web-sys" +version = "0.3.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8622dcb61c0bcc9fffa6938bed81210af2da9a7e4a1a834b2e37a59b6dfb6141" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-root-certs" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b96554aa2acc8ccdb7e1c9a58a7a68dd5d13bccc69cd124cb09406db612a1c9b" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "writeable" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4" + +[[package]] +name = "yoke" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", + "synstructure", +] + +[[package]] +name = "zerofrom" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" + +[[package]] +name = "zerotrie" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f9152d31db0792fa83f70fb2f83148effb5c1f5b8c7686c3459e361d9bc20bf" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90f911cbc359ab6af17377d242225f4d75119aec87ea711a880987b18cd7b239" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "625dc425cab0dca6dc3c3319506e6593dcb08a9f387ea3b284dbd52a92c40555" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..0167613 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,16 @@ +[workspace] +members = ["crates/gitea", "crates/cli"] +resolver = "3" + +[workspace.package] +edition = "2024" +license = "MIT" +rust-version = "1.85" + +[workspace.dependencies] +reqwest = { version = "0.13", default-features = false, features = ["json", "rustls"] } +serde = { version = "1", features = ["derive"] } +serde_json = "1" +tokio = { version = "1", features = ["macros", "rt-multi-thread"] } +rpassword = "7" +serde_yaml = "0.9" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..806e3c7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) 2026 Gotcha contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..7256f17 --- /dev/null +++ b/README.md @@ -0,0 +1,61 @@ +# Gotcha + +Gotcha is a lightweight Gitea client built in Rust. Development starts with a +reusable API crate and a CLI test bed; the same crate will back the Slint iOS +application. + +## Workspace + +- `gotcha_gitea`: reusable asynchronous Gitea API client with the complete + typed Gitea 1.25 API and model surface +- `gotcha`: CLI for typed common operations and arbitrary API requests +- iOS/Slint app: next crate, bundle identifier `de.rfc1437.gotcha` + +The generated API modules and models cover every Gitea 1.25 operation. The +low-level request API remains available for newer instance-specific endpoints; +purpose-built CLI and app views are added feature-by-feature. + +See [API_COVERAGE.md](API_COVERAGE.md) for the live contract inventory and the +separate API-crate and CLI coverage status. + +## CLI + +Store each server profile in `~/.config/gotcha/config`: + +```sh +cargo run -p gotcha-cli -- auth login gitea.example.com + +cargo run -p gotcha-cli -- server version +cargo run -p gotcha-cli -- user show +cargo run -p gotcha-cli -- repo list +cargo run -p gotcha-cli -- repo show +cargo run -p gotcha-cli -- issue list +cargo run -p gotcha-cli -- milestone list +cargo run -p gotcha-cli -- pull list +cargo run -p gotcha-cli -- api request GET repos/owner/project/issues +cargo run -p gotcha-cli -- api request POST user/repos '{"name":"demo"}' +``` + +`auth login` derives `https://gitea.example.com` from the server name and reads +the token from standard input with echo disabled. The resulting plain YAML file +at `~/.config/gotcha/config` has mode `0600` and one entry per server: + +```yaml +servers: + gitea.example.com: + url: https://gitea.example.com + token: your-token +``` + +Inside a Git repository, Gotcha matches its remotes to these server URLs and +derives the `owner/repository` scope. Use `--server gitea.example.com` when selection is +ambiguous, or `--url`/`GITEA_URL` for an unconfigured server. Tokens are never +accepted as command-line arguments or environment variables. + +## Direction + +1. Exercise and type API areas in the CLI: repositories, issues and pull + requests, Actions, notifications, organizations, packages, administration. +2. Add the Slint shell and move proven read workflows into touch-first screens. +3. Add write workflows and iOS integrations such as secure token storage, + sharing, notifications, and background refresh. diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml new file mode 100644 index 0000000..7bd43dd --- /dev/null +++ b/crates/cli/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "gotcha-cli" +version = "0.1.0" +description = "CLI test bed for the Gotcha Gitea client" +edition.workspace = true +license.workspace = true +rust-version.workspace = true + +[[bin]] +name = "gotcha" +path = "src/main.rs" + +[dependencies] +gotcha_gitea = { path = "../gitea" } +serde_json.workspace = true +tokio.workspace = true +rpassword.workspace = true +serde.workspace = true +serde_yaml.workspace = true diff --git a/crates/cli/src/config.rs b/crates/cli/src/config.rs new file mode 100644 index 0000000..4078563 --- /dev/null +++ b/crates/cli/src/config.rs @@ -0,0 +1,348 @@ +use std::{ + collections::BTreeMap, + env, fs, + io::Write, + path::PathBuf, + process::{self, Command}, + time::{SystemTime, UNIX_EPOCH}, +}; + +#[cfg(unix)] +use std::os::unix::fs::{OpenOptionsExt, PermissionsExt}; + +use gotcha_gitea::{Client, Url}; +use serde::{Deserialize, Serialize}; + +type Result = std::result::Result; + +#[derive(Clone, Default, Deserialize, Serialize)] +pub struct Server { + pub url: String, + pub token: String, +} + +#[derive(Default, Deserialize, Serialize)] +pub struct Config { + #[serde(skip)] + path: PathBuf, + #[serde(default)] + pub servers: BTreeMap, +} + +pub struct Selection { + pub name: Option, + pub url: String, + pub token: Option, + pub repository: Option, +} + +#[derive(Clone)] +pub struct RepositoryScope { + pub owner: String, + pub repository: String, +} + +impl RepositoryScope { + pub fn parse(value: &str) -> Result { + let (owner, repository) = value + .split_once('/') + .ok_or("repository must be OWNER/REPOSITORY")?; + if owner.is_empty() || repository.is_empty() || repository.contains('/') { + return Err("repository must be OWNER/REPOSITORY".into()); + } + Ok(Self { + owner: owner.into(), + repository: repository.into(), + }) + } +} + +impl Config { + pub fn load() -> Result { + let home = env::var_os("HOME").ok_or("HOME is not set")?; + Self::load_from(PathBuf::from(home).join(".config/gotcha/config")) + } + + fn load_from(path: PathBuf) -> Result { + if !path.exists() { + return Ok(Self { + path, + ..Self::default() + }); + } + + let text = fs::read_to_string(&path) + .map_err(|error| format!("cannot read {}: {error}", path.display()))?; + let mut config: Self = serde_yaml::from_str(&text) + .map_err(|error| format!("invalid {}: {error}", path.display()))?; + config.path = path; + for (name, server) in &config.servers { + validate_name(name)?; + Client::new(&server.url, Some(&server.token)) + .map_err(|error| format!("invalid server {name}: {error}"))?; + } + Ok(config) + } + + pub fn login(&mut self, name: &str, token: &str) -> Result<()> { + let url = server_url(name)?; + Client::new(&url, Some(token)).map_err(|error| error.to_string())?; + self.servers.insert( + name.into(), + Server { + url, + token: token.into(), + }, + ); + self.save() + } + + pub fn logout(&mut self, name: &str) -> Result<()> { + if self.servers.remove(name).is_none() { + return Err(format!("server profile {name:?} does not exist")); + } + self.save() + } + + pub fn select(&self, name: Option<&str>, url: Option<&str>) -> Result { + if name.is_some() && url.is_some() { + return Err("use either --server or --url, not both".into()); + } + let remotes = git_remotes().unwrap_or_default(); + + if let Some(name) = name { + let server = self + .servers + .get(name) + .ok_or_else(|| format!("server profile {name:?} does not exist"))?; + return Ok(selection(Some(name), server, &remotes)); + } + + if let Some(url) = url { + let matches: Vec<_> = self + .servers + .iter() + .filter(|(_, server)| same_instance(&server.url, url)) + .collect(); + return match matches.as_slice() { + [] => Ok(selection( + None, + &Server { + url: url.into(), + token: String::new(), + }, + &remotes, + )), + [(name, server)] => Ok(selection(Some(name.as_str()), server, &remotes)), + _ => Err("multiple profiles use that URL; select one with --server".into()), + }; + } + + let mut matches = BTreeMap::new(); + for (name, server) in &self.servers { + if let Some(scope) = remotes + .iter() + .find_map(|remote| repository_scope(&server.url, remote)) + { + matches.insert(name, (server, scope)); + } + } + + match matches.into_iter().collect::>().as_slice() { + [] if self.servers.is_empty() => { + Err("no servers configured; run `gotcha auth login SERVER`".into()) + } + [] => Err("no configured server matches this Git repository; use --server NAME".into()), + [(name, (server, scope))] => Ok(Selection { + name: Some((*name).clone()), + url: server.url.clone(), + token: Some(server.token.clone()), + repository: Some(scope.clone()), + }), + _ => Err("multiple server profiles match this Git repository; use --server".into()), + } + } + + fn save(&self) -> Result<()> { + let parent = self + .path + .parent() + .ok_or_else(|| format!("invalid config path: {}", self.path.display()))?; + fs::create_dir_all(parent) + .map_err(|error| format!("cannot create {}: {error}", parent.display()))?; + + let nonce = SystemTime::now() + .duration_since(UNIX_EPOCH) + .map_err(|error| error.to_string())? + .as_nanos(); + let temporary = parent.join(format!(".config.{}.{nonce}.tmp", process::id())); + let text = serde_yaml::to_string(self).map_err(|error| error.to_string())?; + let result = (|| -> std::io::Result<()> { + let mut options = fs::OpenOptions::new(); + options.write(true).create_new(true); + #[cfg(unix)] + options.mode(0o600); + let mut file = options.open(&temporary)?; + file.write_all(text.as_bytes())?; + file.sync_all()?; + fs::rename(&temporary, &self.path)?; + #[cfg(unix)] + fs::set_permissions(&self.path, fs::Permissions::from_mode(0o600))?; + Ok(()) + })(); + if result.is_err() { + let _ = fs::remove_file(&temporary); + } + result.map_err(|error| format!("cannot write {}: {error}", self.path.display())) + } +} + +fn selection(name: Option<&str>, server: &Server, remotes: &[String]) -> Selection { + Selection { + name: name.map(str::to_owned), + url: server.url.clone(), + token: (!server.token.is_empty()).then(|| server.token.clone()), + repository: remotes + .iter() + .find_map(|remote| repository_scope(&server.url, remote)), + } +} + +fn validate_name(name: &str) -> Result<()> { + server_url(name)?; + Ok(()) +} + +pub fn server_url(name: &str) -> Result { + if name.is_empty() + || name.contains('/') + || name.contains('@') + || name.chars().any(char::is_whitespace) + { + return Err("server name must be a hostname, optionally followed by a port".into()); + } + let url = format!("https://{name}"); + let parsed = Url::parse(&url).map_err(|_| "invalid server name")?; + if parsed.host_str().is_none() || parsed.path() != "/" { + return Err("server name must be a hostname, optionally followed by a port".into()); + } + if parsed.query().is_some() || parsed.fragment().is_some() { + return Err("server name must be a hostname, optionally followed by a port".into()); + } + Ok(url) +} + +fn same_instance(left: &str, right: &str) -> bool { + let api_url = |url| { + Client::new(url, None) + .ok() + .map(|client| client.api_url().clone()) + }; + api_url(left) == api_url(right) +} + +fn git_remotes() -> Result> { + let output = Command::new("git") + .args(["config", "--get-regexp", r"^remote\..*\.url$"]) + .output() + .map_err(|error| format!("cannot inspect Git remotes: {error}"))?; + if !output.status.success() { + return Ok(Vec::new()); + } + + Ok(String::from_utf8_lossy(&output.stdout) + .lines() + .filter_map(|line| line.split_once(char::is_whitespace)) + .map(|(_, url)| url.trim().to_owned()) + .collect()) +} + +fn repository_scope(server_url: &str, remote: &str) -> Option { + let server = Url::parse(server_url).ok()?; + let server_host = server.host_str()?; + let (remote_host, mut remote_path, is_http) = if let Ok(url) = Url::parse(remote) { + ( + url.host_str()?.to_owned(), + url.path().trim_matches('/').to_owned(), + matches!(url.scheme(), "http" | "https"), + ) + } else { + let remote = remote.rsplit_once('@').map_or(remote, |(_, rest)| rest); + let (host, path) = remote.split_once(':')?; + (host.into(), path.trim_matches('/').into(), false) + }; + if !server_host.eq_ignore_ascii_case(&remote_host) { + return None; + } + + let prefix = server.path().trim_matches('/'); + if is_http && !prefix.is_empty() { + remote_path = remote_path + .strip_prefix(prefix)? + .strip_prefix('/')? + .to_owned(); + } + let parts: Vec<_> = remote_path + .split('/') + .filter(|part| !part.is_empty()) + .collect(); + let [.., owner, repository] = parts.as_slice() else { + return None; + }; + let repository = repository.strip_suffix(".git").unwrap_or(repository); + (!owner.is_empty() && !repository.is_empty()).then(|| RepositoryScope { + owner: (*owner).into(), + repository: repository.into(), + }) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn config_round_trip_and_remote_scope() { + let directory = env::temp_dir().join(format!( + "gotcha-config-test-{}-{}", + process::id(), + SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_nanos() + )); + let path = directory.join("config"); + let mut config = Config { + path: path.clone(), + ..Config::default() + }; + assert_eq!( + config.select(None, None).err().unwrap(), + "no servers configured; run `gotcha auth login SERVER`" + ); + config.login("code.example", "secret").unwrap(); + + let loaded = Config::load_from(path).unwrap(); + assert_eq!(loaded.servers["code.example"].token, "secret"); + assert!( + fs::read_to_string(&loaded.path) + .unwrap() + .contains("token: secret") + ); + let scope = repository_scope( + "https://code.example/gitea", + "https://code.example/gitea/alice/project.git", + ) + .unwrap(); + assert_eq!( + (scope.owner.as_str(), scope.repository.as_str()), + ("alice", "project") + ); + #[cfg(unix)] + assert_eq!( + fs::metadata(&loaded.path).unwrap().permissions().mode() & 0o777, + 0o600 + ); + + fs::remove_dir_all(directory).unwrap(); + } +} diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs new file mode 100644 index 0000000..17054d1 --- /dev/null +++ b/crates/cli/src/main.rs @@ -0,0 +1,396 @@ +mod config; +mod work_items; + +use std::{env, error::Error, process}; + +use config::{Config, RepositoryScope, Selection, server_url}; +use gotcha_gitea::{Client, Method, Repository, ServerVersion, User}; +use serde_json::Value; + +const ROOT_HELP: &str = "\ +Gotcha CLI + +Usage: + gotcha [--server SERVER | --url URL] COMMAND + +Commands: + auth Manage server authentication + server Inspect the selected Gitea server + user Work with the authenticated user + repo Work with repositories + issue Work with issues and comments + milestone Work with repository milestones + pull Work with pull requests + api Send a raw Gitea API request + +Run `gotcha COMMAND` to list that command's subcommands. + +Without --server or --url, Gotcha selects a profile from the current Git +repository's remotes. SERVER is a hostname, optionally followed by a port. +GITEA_URL is the environment equivalent of --url."; + +const AUTH_HELP: &str = "\ +Usage: gotcha auth SUBCOMMAND + +Subcommands: + login SERVER Verify and store a token read from standard input + list List configured servers without showing tokens + status Show the selected server and repository scope + logout SERVER Remove a stored server and token"; + +const SERVER_HELP: &str = "\ +Usage: gotcha server SUBCOMMAND + +Subcommands: + version Show the selected Gitea server version"; + +const USER_HELP: &str = "\ +Usage: gotcha user SUBCOMMAND + +Subcommands: + show Show the authenticated user"; + +const REPO_HELP: &str = "\ +Usage: gotcha repo SUBCOMMAND + +Subcommands: + list List repositories belonging to the authenticated user + show [OWNER/REPOSITORY] + Show a repository; defaults to the current Git repository"; + +const API_HELP: &str = "\ +Usage: gotcha api SUBCOMMAND + +Subcommands: + request METHOD ENDPOINT [JSON] + Send an API-relative request"; + +#[tokio::main] +async fn main() { + if let Err(error) = run().await { + eprintln!("gotcha: {error}"); + process::exit(1); + } +} + +async fn run() -> Result<(), Box> { + let arguments: Vec<_> = env::args().skip(1).collect(); + let args = Args::parse(arguments, env::var("GITEA_URL").ok())?; + if let Some(help) = requested_help(&args.command)? { + println!("{help}"); + return Ok(()); + } + + let mut config = Config::load()?; + match args.command.as_slice() { + [domain, command, name] if domain == "auth" && command == "login" => { + let url = server_url(name)?; + let token = rpassword::prompt_password("Token: ")?; + if token.is_empty() { + return Err("token must not be empty".into()); + } + let user = Client::new(&url, Some(&token))?.current_user().await?; + config.login(name, &token)?; + println!( + "Logged in to {url} as {} ({name}).", + user.login.as_deref().unwrap_or("unknown") + ); + return Ok(()); + } + [domain, command] if domain == "auth" && command == "list" => { + for (name, server) in &config.servers { + println!("{name}\t{}", server.url); + } + return Ok(()); + } + [domain, command, name] if domain == "auth" && command == "logout" => { + config.logout(name)?; + println!("Removed server profile {name}."); + return Ok(()); + } + _ => {} + } + + let selection = config.select(args.server.as_deref(), args.url.as_deref())?; + if matches!(args.command.as_slice(), [domain, command] if domain == "auth" && command == "status") + { + print_status(&selection); + return Ok(()); + } + + let client = Client::new(&selection.url, selection.token.as_deref())?; + if work_items::run(&args.command, &selection, &client).await? { + return Ok(()); + } + match args.command.as_slice() { + [domain, command] if domain == "server" && command == "version" => { + print_version(&client.version().await?); + } + [domain, command] if domain == "user" && command == "show" => { + print_user(&client.current_user().await?); + } + [domain, command] if domain == "repo" && command == "list" => { + print_repositories(&client.current_user_repositories().await?); + } + [domain, command] if domain == "repo" && command == "show" => { + let scope = selection + .repository + .as_ref() + .ok_or("cannot infer a repository; run inside one or pass OWNER/REPOSITORY")?; + print_repository(&client.repository(&scope.owner, &scope.repository).await?); + } + [domain, command, repository_name] if domain == "repo" && command == "show" => { + let scope = RepositoryScope::parse(repository_name)?; + print_repository(&client.repository(&scope.owner, &scope.repository).await?); + } + [domain, command, method, endpoint] if domain == "api" && command == "request" => { + print_json(&request(&client, method, endpoint, None).await?)?; + } + [domain, command, method, endpoint, body] if domain == "api" && command == "request" => { + print_json( + &request(&client, method, endpoint, Some(serde_json::from_str(body)?)).await?, + )?; + } + _ => return Err(invalid_subcommand(&args.command).into()), + } + Ok(()) +} + +fn print_version(version: &ServerVersion) { + println!("{}", version.version.as_deref().unwrap_or("unknown")); +} + +fn print_user(user: &User) { + field("login", user.login.as_deref()); + field("name", user.full_name.as_deref()); + field("email", user.email.as_deref()); + field("profile", user.html_url.as_deref()); + field("visibility", user.visibility.as_deref()); +} + +fn print_repositories(repositories: &[Repository]) { + println!("REPOSITORY\tVISIBILITY\tUPDATED\tDESCRIPTION"); + for repository in repositories { + println!( + "{}\t{}\t{}\t{}", + repository.full_name.as_deref().unwrap_or("unknown"), + if repository.private.unwrap_or(false) { + "private" + } else { + "public" + }, + repository.updated_at.as_deref().unwrap_or("-"), + repository.description.as_deref().unwrap_or("") + ); + } +} + +fn print_repository(repository: &Repository) { + field("repository", repository.full_name.as_deref()); + field("description", repository.description.as_deref()); + field("url", repository.html_url.as_deref()); + field("default branch", repository.default_branch.as_deref()); + println!( + "visibility: {}", + if repository.private.unwrap_or(false) { + "private" + } else { + "public" + } + ); + println!("stars: {}", repository.stars_count.unwrap_or_default()); + println!( + "open issues: {}", + repository.open_issues_count.unwrap_or_default() + ); +} + +fn field(name: &str, value: Option<&str>) { + if let Some(value) = value.filter(|value| !value.is_empty()) { + println!("{name}: {value}"); + } +} + +fn print_json(value: &Value) -> Result<(), serde_json::Error> { + println!("{}", serde_json::to_string_pretty(value)?); + Ok(()) +} + +fn requested_help(command: &[String]) -> Result, String> { + match command { + [] => Ok(Some(ROOT_HELP)), + [help] if matches!(help.as_str(), "help" | "-h" | "--help") => Ok(Some(ROOT_HELP)), + [domain] => domain_help(domain) + .map(Some) + .ok_or_else(|| format!("unknown command {domain:?}\n\n{ROOT_HELP}")), + [domain, help] if matches!(help.as_str(), "-h" | "--help") => domain_help(domain) + .map(Some) + .ok_or_else(|| format!("unknown command {domain:?}\n\n{ROOT_HELP}")), + [domain, subcommand, help] if matches!(help.as_str(), "-h" | "--help") => { + subcommand_help(domain, subcommand) + .map(Some) + .ok_or_else(|| { + format!( + "unknown subcommand {domain} {subcommand}\n\n{}", + domain_help(domain).unwrap_or(ROOT_HELP) + ) + }) + } + [domain, ..] if domain_help(domain).is_none() => { + Err(format!("unknown command {domain:?}\n\n{ROOT_HELP}")) + } + _ => Ok(None), + } +} + +fn domain_help(domain: &str) -> Option<&'static str> { + match domain { + "auth" => Some(AUTH_HELP), + "server" => Some(SERVER_HELP), + "user" => Some(USER_HELP), + "repo" => Some(REPO_HELP), + "api" => Some(API_HELP), + _ => work_items::domain_help(domain), + } +} + +fn subcommand_help(domain: &str, subcommand: &str) -> Option<&'static str> { + match (domain, subcommand) { + ("auth", "login") => Some( + "Usage: gotcha auth login SERVER\n\nPrompts for a token, verifies it, and stores the server in the YAML config.", + ), + ("auth", "list") => { + Some("Usage: gotcha auth list\n\nLists configured servers without tokens.") + } + ("auth", "status") => Some( + "Usage: gotcha [--server SERVER] auth status\n\nShows the selected server and inferred repository scope.", + ), + ("auth", "logout") => Some( + "Usage: gotcha auth logout SERVER\n\nRemoves the server and its token from the YAML config.", + ), + ("server", "version") => Some("Usage: gotcha server version\n\nShows the Gitea version."), + ("user", "show") => Some("Usage: gotcha user show\n\nShows the authenticated user."), + ("repo", "list") => Some( + "Usage: gotcha repo list\n\nLists repositories belonging to the authenticated user.", + ), + ("repo", "show") => Some( + "Usage: gotcha repo show [OWNER/REPOSITORY]\n\nShows a repository, inferred from Git when omitted.", + ), + ("api", "request") => Some( + "Usage: gotcha api request METHOD ENDPOINT [JSON]\n\nSends an API-relative request using the selected server and token.", + ), + _ => work_items::subcommand_help(domain, subcommand), + } +} + +fn invalid_subcommand(command: &[String]) -> String { + let domain = command.first().map(String::as_str).unwrap_or_default(); + format!( + "unknown or invalid {domain} subcommand\n\n{}", + domain_help(domain).unwrap_or(ROOT_HELP) + ) +} + +fn print_status(selection: &Selection) { + println!( + "server: {} ({})", + selection.name.as_deref().unwrap_or("custom"), + selection.url + ); + println!( + "authenticated: {}", + if selection.token.is_some() { + "yes" + } else { + "no" + } + ); + if let Some(scope) = &selection.repository { + println!("repository: {}/{}", scope.owner, scope.repository); + } +} + +async fn request( + client: &Client, + method: &str, + endpoint: &str, + body: Option, +) -> Result> { + let mut request = client.request(method.parse::()?, endpoint)?; + if let Some(body) = body { + request = request.json(&body); + } + + let response = client.execute(request).await?; + if response.status() == 204 { + return Ok(Value::Null); + } + Ok(response.json().await?) +} + +#[derive(Debug)] +struct Args { + url: Option, + server: Option, + command: Vec, +} + +impl Args { + fn parse( + args: impl IntoIterator, + environment_url: Option, + ) -> Result { + let mut args = args.into_iter(); + let mut url = environment_url; + let mut server = None; + let mut command = Vec::new(); + + while let Some(argument) = args.next() { + match argument.as_str() { + "--url" if command.is_empty() => { + url = Some(args.next().ok_or("--url requires an instance URL")?); + } + "--server" if command.is_empty() => { + server = Some(args.next().ok_or("--server requires a profile name")?); + } + _ => command.push(argument), + } + } + + Ok(Self { + url, + server, + command, + }) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn parses_server_selection_and_repository_scope() { + let args = Args::parse( + ["--server", "work", "repo", "show"].map(str::to_owned), + None, + ) + .unwrap(); + let repository = RepositoryScope::parse("alice/project").unwrap(); + + assert_eq!(args.server.as_deref(), Some("work")); + assert_eq!(args.command, ["repo", "show"]); + assert_eq!( + (repository.owner.as_str(), repository.repository.as_str()), + ("alice", "project") + ); + assert_eq!(requested_help(&[]).unwrap(), Some(ROOT_HELP)); + assert_eq!(requested_help(&["repo".into()]).unwrap(), Some(REPO_HELP)); + assert!( + requested_help(&["repo".into(), "show".into(), "--help".into()]) + .unwrap() + .unwrap() + .starts_with("Usage: gotcha repo show") + ); + } +} diff --git a/crates/cli/src/work_items.rs b/crates/cli/src/work_items.rs new file mode 100644 index 0000000..fe2f1a3 --- /dev/null +++ b/crates/cli/src/work_items.rs @@ -0,0 +1,853 @@ +use std::{error::Error, io::Read}; + +use gotcha_gitea::{ + Client, apis, + models::{ + ChangedFile, Comment, Commit, CreateIssueCommentOption, CreateIssueOption, + CreateMilestoneOption, CreatePullRequestOption, EditIssueOption, EditMilestoneOption, + EditPullRequestOption, Issue, MergePullRequestOption, Milestone, PullRequest, PullReview, + }, +}; +use serde::de::DeserializeOwned; + +use crate::config::{RepositoryScope, Selection}; + +const ISSUE_HELP: &str = "\ +Usage: gotcha issue SUBCOMMAND + +Subcommands: + list [OWNER/REPOSITORY] List issues + show INDEX [OWNER/REPOSITORY] Show an issue + create [OWNER/REPOSITORY] Create from CreateIssueOption YAML on stdin + edit INDEX [OWNER/REPOSITORY] Edit from EditIssueOption YAML on stdin + delete INDEX [OWNER/REPOSITORY] Delete an issue + comments INDEX [OWNER/REPOSITORY] + List comments + comment INDEX [OWNER/REPOSITORY] Add a comment read as text from stdin"; + +const MILESTONE_HELP: &str = "\ +Usage: gotcha milestone SUBCOMMAND + +Subcommands: + list [OWNER/REPOSITORY] List milestones + show ID [OWNER/REPOSITORY] Show a milestone + create [OWNER/REPOSITORY] Create from CreateMilestoneOption YAML on stdin + edit ID [OWNER/REPOSITORY] Edit from EditMilestoneOption YAML on stdin + delete ID [OWNER/REPOSITORY] Delete a milestone"; + +const PULL_HELP: &str = "\ +Usage: gotcha pull SUBCOMMAND + +Subcommands: + list [OWNER/REPOSITORY] List pull requests + show INDEX [OWNER/REPOSITORY] Show a pull request + create [OWNER/REPOSITORY] Create from CreatePullRequestOption YAML on stdin + edit INDEX [OWNER/REPOSITORY] Edit from EditPullRequestOption YAML on stdin + merge INDEX [OWNER/REPOSITORY] Merge from MergePullRequestOption YAML on stdin + commits INDEX [OWNER/REPOSITORY] List commits + files INDEX [OWNER/REPOSITORY] List changed files + reviews INDEX [OWNER/REPOSITORY] List reviews"; + +pub fn domain_help(domain: &str) -> Option<&'static str> { + match domain { + "issue" => Some(ISSUE_HELP), + "milestone" => Some(MILESTONE_HELP), + "pull" => Some(PULL_HELP), + _ => None, + } +} + +pub fn subcommand_help(domain: &str, command: &str) -> Option<&'static str> { + match (domain, command) { + ("issue", "list") => Some("Usage: gotcha issue list [OWNER/REPOSITORY]"), + ("issue", "show") => Some("Usage: gotcha issue show INDEX [OWNER/REPOSITORY]"), + ("issue", "create") => Some( + "Usage: gotcha issue create [OWNER/REPOSITORY] < issue.yaml\n\nReads CreateIssueOption YAML from stdin, for example:\n title: Fix the bug\n body: Reproduction steps", + ), + ("issue", "edit") => Some( + "Usage: gotcha issue edit INDEX [OWNER/REPOSITORY] < issue.yaml\n\nReads EditIssueOption YAML from stdin.", + ), + ("issue", "delete") => Some("Usage: gotcha issue delete INDEX [OWNER/REPOSITORY]"), + ("issue", "comments") => Some("Usage: gotcha issue comments INDEX [OWNER/REPOSITORY]"), + ("issue", "comment") => Some( + "Usage: gotcha issue comment INDEX [OWNER/REPOSITORY] < comment.txt\n\nReads the comment body as text from stdin.", + ), + ("milestone", "list") => Some("Usage: gotcha milestone list [OWNER/REPOSITORY]"), + ("milestone", "show") => Some("Usage: gotcha milestone show ID [OWNER/REPOSITORY]"), + ("milestone", "create") => Some( + "Usage: gotcha milestone create [OWNER/REPOSITORY] < milestone.yaml\n\nReads CreateMilestoneOption YAML from stdin, for example:\n title: Version 1.0\n due_on: 2026-09-01T00:00:00Z", + ), + ("milestone", "edit") => Some( + "Usage: gotcha milestone edit ID [OWNER/REPOSITORY] < milestone.yaml\n\nReads EditMilestoneOption YAML from stdin.", + ), + ("milestone", "delete") => Some("Usage: gotcha milestone delete ID [OWNER/REPOSITORY]"), + ("pull", "list") => Some("Usage: gotcha pull list [OWNER/REPOSITORY]"), + ("pull", "show") => Some("Usage: gotcha pull show INDEX [OWNER/REPOSITORY]"), + ("pull", "create") => Some( + "Usage: gotcha pull create [OWNER/REPOSITORY] < pull.yaml\n\nReads CreatePullRequestOption YAML from stdin, for example:\n title: Add feature\n head: feature\n base: main", + ), + ("pull", "edit") => Some( + "Usage: gotcha pull edit INDEX [OWNER/REPOSITORY] < pull.yaml\n\nReads EditPullRequestOption YAML from stdin.", + ), + ("pull", "merge") => Some( + "Usage: gotcha pull merge INDEX [OWNER/REPOSITORY] < merge.yaml\n\nReads MergePullRequestOption YAML from stdin, for example:\n Do: squash\n delete_branch_after_merge: true", + ), + ("pull", "commits") => Some("Usage: gotcha pull commits INDEX [OWNER/REPOSITORY]"), + ("pull", "files") => Some("Usage: gotcha pull files INDEX [OWNER/REPOSITORY]"), + ("pull", "reviews") => Some("Usage: gotcha pull reviews INDEX [OWNER/REPOSITORY]"), + _ => None, + } +} + +pub async fn run( + command: &[String], + selection: &Selection, + client: &Client, +) -> Result> { + let configuration = client.configuration(); + match command { + [domain, action] if domain == "issue" && action == "list" => { + let scope = scope(selection, None)?; + let issues = apis::issue_api::issue_list_issues( + &configuration, + &scope.owner, + &scope.repository, + None, + None, + None, + Some("issues"), + None, + None, + None, + Some("issues"), + None, + None, + None, + None, + ) + .await?; + print_issues(&issues); + } + [domain, action, repository] if domain == "issue" && action == "list" => { + let scope = scope(selection, Some(repository))?; + let issues = apis::issue_api::issue_list_issues( + &configuration, + &scope.owner, + &scope.repository, + None, + None, + None, + None, + None, + None, + None, + None, + None, + None, + None, + None, + ) + .await?; + print_issues(&issues); + } + [domain, action, index] if domain == "issue" && action == "show" => { + let scope = scope(selection, None)?; + print_issue( + &apis::issue_api::issue_get_issue( + &configuration, + &scope.owner, + &scope.repository, + number(index)?, + ) + .await?, + ); + } + [domain, action, index, repository] if domain == "issue" && action == "show" => { + let scope = scope(selection, Some(repository))?; + print_issue( + &apis::issue_api::issue_get_issue( + &configuration, + &scope.owner, + &scope.repository, + number(index)?, + ) + .await?, + ); + } + [domain, action] if domain == "issue" && action == "create" => { + create_issue(&configuration, &scope(selection, None)?).await?; + } + [domain, action, repository] if domain == "issue" && action == "create" => { + create_issue(&configuration, &scope(selection, Some(repository))?).await?; + } + [domain, action, index] if domain == "issue" && action == "edit" => { + edit_issue(&configuration, &scope(selection, None)?, number(index)?).await?; + } + [domain, action, index, repository] if domain == "issue" && action == "edit" => { + edit_issue( + &configuration, + &scope(selection, Some(repository))?, + number(index)?, + ) + .await?; + } + [domain, action, index] if domain == "issue" && action == "delete" => { + delete_issue(&configuration, &scope(selection, None)?, number(index)?).await?; + } + [domain, action, index, repository] if domain == "issue" && action == "delete" => { + delete_issue( + &configuration, + &scope(selection, Some(repository))?, + number(index)?, + ) + .await?; + } + [domain, action, index] if domain == "issue" && action == "comments" => { + list_comments(&configuration, &scope(selection, None)?, number(index)?).await?; + } + [domain, action, index, repository] if domain == "issue" && action == "comments" => { + list_comments( + &configuration, + &scope(selection, Some(repository))?, + number(index)?, + ) + .await?; + } + [domain, action, index] if domain == "issue" && action == "comment" => { + create_comment(&configuration, &scope(selection, None)?, number(index)?).await?; + } + [domain, action, index, repository] if domain == "issue" && action == "comment" => { + create_comment( + &configuration, + &scope(selection, Some(repository))?, + number(index)?, + ) + .await?; + } + [domain, action] if domain == "milestone" && action == "list" => { + list_milestones(&configuration, &scope(selection, None)?).await?; + } + [domain, action, repository] if domain == "milestone" && action == "list" => { + list_milestones(&configuration, &scope(selection, Some(repository))?).await?; + } + [domain, action, id] if domain == "milestone" && action == "show" => { + show_milestone(&configuration, &scope(selection, None)?, id).await?; + } + [domain, action, id, repository] if domain == "milestone" && action == "show" => { + show_milestone(&configuration, &scope(selection, Some(repository))?, id).await?; + } + [domain, action] if domain == "milestone" && action == "create" => { + create_milestone(&configuration, &scope(selection, None)?).await?; + } + [domain, action, repository] if domain == "milestone" && action == "create" => { + create_milestone(&configuration, &scope(selection, Some(repository))?).await?; + } + [domain, action, id] if domain == "milestone" && action == "edit" => { + edit_milestone(&configuration, &scope(selection, None)?, id).await?; + } + [domain, action, id, repository] if domain == "milestone" && action == "edit" => { + edit_milestone(&configuration, &scope(selection, Some(repository))?, id).await?; + } + [domain, action, id] if domain == "milestone" && action == "delete" => { + delete_milestone(&configuration, &scope(selection, None)?, id).await?; + } + [domain, action, id, repository] if domain == "milestone" && action == "delete" => { + delete_milestone(&configuration, &scope(selection, Some(repository))?, id).await?; + } + [domain, action] if domain == "pull" && action == "list" => { + list_pulls(&configuration, &scope(selection, None)?).await?; + } + [domain, action, repository] if domain == "pull" && action == "list" => { + list_pulls(&configuration, &scope(selection, Some(repository))?).await?; + } + [domain, action, index] if domain == "pull" && action == "show" => { + show_pull(&configuration, &scope(selection, None)?, number(index)?).await?; + } + [domain, action, index, repository] if domain == "pull" && action == "show" => { + show_pull( + &configuration, + &scope(selection, Some(repository))?, + number(index)?, + ) + .await?; + } + [domain, action] if domain == "pull" && action == "create" => { + create_pull(&configuration, &scope(selection, None)?).await?; + } + [domain, action, repository] if domain == "pull" && action == "create" => { + create_pull(&configuration, &scope(selection, Some(repository))?).await?; + } + [domain, action, index] if domain == "pull" && action == "edit" => { + edit_pull(&configuration, &scope(selection, None)?, number(index)?).await?; + } + [domain, action, index, repository] if domain == "pull" && action == "edit" => { + edit_pull( + &configuration, + &scope(selection, Some(repository))?, + number(index)?, + ) + .await?; + } + [domain, action, index] if domain == "pull" && action == "merge" => { + merge_pull(&configuration, &scope(selection, None)?, number(index)?).await?; + } + [domain, action, index, repository] if domain == "pull" && action == "merge" => { + merge_pull( + &configuration, + &scope(selection, Some(repository))?, + number(index)?, + ) + .await?; + } + [domain, action, index] + if domain == "pull" && matches!(action.as_str(), "commits" | "files" | "reviews") => + { + pull_details( + &configuration, + &scope(selection, None)?, + number(index)?, + action, + ) + .await?; + } + [domain, action, index, repository] + if domain == "pull" && matches!(action.as_str(), "commits" | "files" | "reviews") => + { + pull_details( + &configuration, + &scope(selection, Some(repository))?, + number(index)?, + action, + ) + .await?; + } + [domain, ..] if matches!(domain.as_str(), "issue" | "milestone" | "pull") => { + return Ok(false); + } + _ => return Ok(false), + } + Ok(true) +} + +fn scope(selection: &Selection, value: Option<&str>) -> Result> { + match value { + Some(value) => Ok(RepositoryScope::parse(value)?), + None => selection.repository.clone().ok_or_else(|| { + "cannot infer a repository; run inside one or pass OWNER/REPOSITORY".into() + }), + } +} + +fn number(value: &str) -> Result> { + let number: i64 = value.parse()?; + if number < 1 { + return Err("index must be a positive integer".into()); + } + Ok(number) +} + +fn read_stdin() -> Result> { + let mut input = String::new(); + std::io::stdin().read_to_string(&mut input)?; + if input.trim().is_empty() { + return Err("stdin must not be empty".into()); + } + Ok(input) +} + +fn read_yaml() -> Result> { + parse_yaml(&read_stdin()?) +} + +fn parse_yaml(input: &str) -> Result> { + Ok(serde_yaml::from_str(input)?) +} + +async fn create_issue( + configuration: &apis::configuration::Configuration, + scope: &RepositoryScope, +) -> Result<(), Box> { + let body: CreateIssueOption = read_yaml()?; + if body.title.trim().is_empty() { + return Err("issue title must not be empty".into()); + } + print_issue( + &apis::issue_api::issue_create_issue( + configuration, + &scope.owner, + &scope.repository, + Some(body), + ) + .await?, + ); + Ok(()) +} + +async fn edit_issue( + configuration: &apis::configuration::Configuration, + scope: &RepositoryScope, + index: i64, +) -> Result<(), Box> { + let issue = apis::issue_api::issue_edit_issue( + configuration, + &scope.owner, + &scope.repository, + index, + Some(read_yaml::()?), + ) + .await?; + print_issue(&issue); + Ok(()) +} + +async fn delete_issue( + configuration: &apis::configuration::Configuration, + scope: &RepositoryScope, + index: i64, +) -> Result<(), Box> { + apis::issue_api::issue_delete(configuration, &scope.owner, &scope.repository, index).await?; + println!("Deleted issue #{index}."); + Ok(()) +} + +async fn list_comments( + configuration: &apis::configuration::Configuration, + scope: &RepositoryScope, + index: i64, +) -> Result<(), Box> { + let comments = apis::issue_api::issue_get_comments( + configuration, + &scope.owner, + &scope.repository, + index, + None, + None, + ) + .await?; + print_comments(&comments); + Ok(()) +} + +async fn create_comment( + configuration: &apis::configuration::Configuration, + scope: &RepositoryScope, + index: i64, +) -> Result<(), Box> { + let body = read_stdin()?.trim_end().to_owned(); + let comment = apis::issue_api::issue_create_comment( + configuration, + &scope.owner, + &scope.repository, + index, + Some(CreateIssueCommentOption::new(body)), + ) + .await?; + print_comments(&[comment]); + Ok(()) +} + +async fn list_milestones( + configuration: &apis::configuration::Configuration, + scope: &RepositoryScope, +) -> Result<(), Box> { + let milestones = apis::issue_api::issue_get_milestones_list( + configuration, + &scope.owner, + &scope.repository, + None, + None, + None, + None, + ) + .await?; + print_milestones(&milestones); + Ok(()) +} + +async fn show_milestone( + configuration: &apis::configuration::Configuration, + scope: &RepositoryScope, + id: &str, +) -> Result<(), Box> { + let milestone = + apis::issue_api::issue_get_milestone(configuration, &scope.owner, &scope.repository, id) + .await?; + print_milestone(&milestone); + Ok(()) +} + +async fn create_milestone( + configuration: &apis::configuration::Configuration, + scope: &RepositoryScope, +) -> Result<(), Box> { + let body: CreateMilestoneOption = read_yaml()?; + if body.title.as_deref().unwrap_or_default().trim().is_empty() { + return Err("milestone title must not be empty".into()); + } + let milestone = apis::issue_api::issue_create_milestone( + configuration, + &scope.owner, + &scope.repository, + Some(body), + ) + .await?; + print_milestone(&milestone); + Ok(()) +} + +async fn edit_milestone( + configuration: &apis::configuration::Configuration, + scope: &RepositoryScope, + id: &str, +) -> Result<(), Box> { + let milestone = apis::issue_api::issue_edit_milestone( + configuration, + &scope.owner, + &scope.repository, + id, + Some(read_yaml::()?), + ) + .await?; + print_milestone(&milestone); + Ok(()) +} + +async fn delete_milestone( + configuration: &apis::configuration::Configuration, + scope: &RepositoryScope, + id: &str, +) -> Result<(), Box> { + apis::issue_api::issue_delete_milestone(configuration, &scope.owner, &scope.repository, id) + .await?; + println!("Deleted milestone {id}."); + Ok(()) +} + +async fn list_pulls( + configuration: &apis::configuration::Configuration, + scope: &RepositoryScope, +) -> Result<(), Box> { + let pulls = apis::repository_api::repo_list_pull_requests( + configuration, + &scope.owner, + &scope.repository, + None, + None, + None, + None, + None, + None, + None, + None, + ) + .await?; + print_pulls(&pulls); + Ok(()) +} + +async fn show_pull( + configuration: &apis::configuration::Configuration, + scope: &RepositoryScope, + index: i64, +) -> Result<(), Box> { + let pull = apis::repository_api::repo_get_pull_request( + configuration, + &scope.owner, + &scope.repository, + index, + ) + .await?; + print_pull(&pull); + Ok(()) +} + +async fn create_pull( + configuration: &apis::configuration::Configuration, + scope: &RepositoryScope, +) -> Result<(), Box> { + let body: CreatePullRequestOption = read_yaml()?; + if [ + body.title.as_deref(), + body.head.as_deref(), + body.base.as_deref(), + ] + .into_iter() + .any(|value| value.unwrap_or_default().trim().is_empty()) + { + return Err("pull request title, head, and base must not be empty".into()); + } + let pull = apis::repository_api::repo_create_pull_request( + configuration, + &scope.owner, + &scope.repository, + Some(body), + ) + .await?; + print_pull(&pull); + Ok(()) +} + +async fn edit_pull( + configuration: &apis::configuration::Configuration, + scope: &RepositoryScope, + index: i64, +) -> Result<(), Box> { + let pull = apis::repository_api::repo_edit_pull_request( + configuration, + &scope.owner, + &scope.repository, + index, + Some(read_yaml::()?), + ) + .await?; + print_pull(&pull); + Ok(()) +} + +async fn merge_pull( + configuration: &apis::configuration::Configuration, + scope: &RepositoryScope, + index: i64, +) -> Result<(), Box> { + apis::repository_api::repo_merge_pull_request( + configuration, + &scope.owner, + &scope.repository, + index, + Some(read_yaml::()?), + ) + .await?; + println!("Merged pull request #{index}."); + Ok(()) +} + +async fn pull_details( + configuration: &apis::configuration::Configuration, + scope: &RepositoryScope, + index: i64, + action: &str, +) -> Result<(), Box> { + match action { + "commits" => print_commits( + &apis::repository_api::repo_get_pull_request_commits( + configuration, + &scope.owner, + &scope.repository, + index, + None, + None, + None, + None, + ) + .await?, + ), + "files" => print_files( + &apis::repository_api::repo_get_pull_request_files( + configuration, + &scope.owner, + &scope.repository, + index, + None, + None, + None, + None, + ) + .await?, + ), + "reviews" => print_reviews( + &apis::repository_api::repo_list_pull_reviews( + configuration, + &scope.owner, + &scope.repository, + index, + None, + None, + ) + .await?, + ), + _ => unreachable!(), + } + Ok(()) +} + +fn print_issues(issues: &[Issue]) { + println!("INDEX\tSTATE\tTITLE\tUPDATED"); + for issue in issues { + println!( + "{}\t{}\t{}\t{}", + issue.number.unwrap_or_default(), + issue.state.as_deref().unwrap_or("unknown"), + one_line(issue.title.as_deref().unwrap_or("")), + issue.updated_at.as_deref().unwrap_or("-") + ); + } +} + +fn print_issue(issue: &Issue) { + println!( + "#{} [{}] {}", + issue.number.unwrap_or_default(), + issue.state.as_deref().unwrap_or("unknown"), + issue.title.as_deref().unwrap_or("") + ); + field("url", issue.html_url.as_deref()); + field( + "author", + issue.user.as_deref().and_then(|user| user.login.as_deref()), + ); + field("updated", issue.updated_at.as_deref()); + body(issue.body.as_deref()); +} + +fn print_comments(comments: &[Comment]) { + for comment in comments { + println!( + "{} · {}", + comment + .user + .as_deref() + .and_then(|user| user.login.as_deref()) + .unwrap_or("unknown"), + comment.created_at.as_deref().unwrap_or("-") + ); + body(comment.body.as_deref()); + } +} + +fn print_milestones(milestones: &[Milestone]) { + println!("ID\tSTATE\tTITLE\tDUE\tOPEN/CLOSED"); + for milestone in milestones { + println!( + "{}\t{}\t{}\t{}\t{}/{}", + milestone.id.unwrap_or_default(), + milestone.state.as_deref().unwrap_or("unknown"), + one_line(milestone.title.as_deref().unwrap_or("")), + milestone.due_on.as_deref().unwrap_or("-"), + milestone.open_issues.unwrap_or_default(), + milestone.closed_issues.unwrap_or_default() + ); + } +} + +fn print_milestone(milestone: &Milestone) { + println!( + "{} [{}] {}", + milestone.id.unwrap_or_default(), + milestone.state.as_deref().unwrap_or("unknown"), + milestone.title.as_deref().unwrap_or("") + ); + field("due", milestone.due_on.as_deref()); + println!( + "issues: {} open, {} closed", + milestone.open_issues.unwrap_or_default(), + milestone.closed_issues.unwrap_or_default() + ); + body(milestone.description.as_deref()); +} + +fn print_pulls(pulls: &[PullRequest]) { + println!("INDEX\tSTATE\tTITLE\tUPDATED"); + for pull in pulls { + println!( + "{}\t{}\t{}\t{}", + pull.number.unwrap_or_default(), + pull.state.as_deref().unwrap_or("unknown"), + one_line(pull.title.as_deref().unwrap_or("")), + pull.updated_at.as_deref().unwrap_or("-") + ); + } +} + +fn print_pull(pull: &PullRequest) { + println!( + "#{} [{}] {}", + pull.number.unwrap_or_default(), + pull.state.as_deref().unwrap_or("unknown"), + pull.title.as_deref().unwrap_or("") + ); + field("url", pull.html_url.as_deref()); + field( + "author", + pull.user.as_deref().and_then(|user| user.login.as_deref()), + ); + field("updated", pull.updated_at.as_deref()); + println!("mergeable: {}", pull.mergeable.unwrap_or(false)); + body(pull.body.as_deref()); +} + +fn print_commits(commits: &[Commit]) { + println!("SHA\tMESSAGE"); + for commit in commits { + println!( + "{}\t{}", + commit.sha.as_deref().unwrap_or("unknown"), + one_line( + commit + .commit + .as_deref() + .and_then(|commit| commit.message.as_deref()) + .unwrap_or("") + ) + ); + } +} + +fn print_files(files: &[ChangedFile]) { + println!("STATUS\tCHANGES\tFILE"); + for file in files { + println!( + "{}\t{}\t{}", + file.status.as_deref().unwrap_or("unknown"), + file.changes.unwrap_or_default(), + file.filename.as_deref().unwrap_or("") + ); + } +} + +fn print_reviews(reviews: &[PullReview]) { + println!("ID\tSTATE\tREVIEWER\tSUBMITTED"); + for review in reviews { + println!( + "{}\t{}\t{}\t{}", + review.id.unwrap_or_default(), + review.state.as_deref().unwrap_or("unknown"), + review + .user + .as_deref() + .and_then(|user| user.login.as_deref()) + .unwrap_or("unknown"), + review.submitted_at.as_deref().unwrap_or("-") + ); + } +} + +fn field(name: &str, value: Option<&str>) { + if let Some(value) = value.filter(|value| !value.is_empty()) { + println!("{name}: {value}"); + } +} + +fn body(value: Option<&str>) { + if let Some(value) = value.filter(|value| !value.is_empty()) { + println!("\n{value}"); + } +} + +fn one_line(value: &str) -> &str { + value.lines().next().unwrap_or_default() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn parses_typed_yaml_and_rejects_bad_indexes() { + let issue: CreateIssueOption = parse_yaml("title: Fix it\nbody: Details\n").unwrap(); + + assert_eq!(issue.title, "Fix it"); + assert_eq!(issue.body.as_deref(), Some("Details")); + assert!(number("0").is_err()); + assert!(number("7").is_ok()); + } +} diff --git a/crates/gitea/Cargo.toml b/crates/gitea/Cargo.toml new file mode 100644 index 0000000..3348237 --- /dev/null +++ b/crates/gitea/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "gotcha_gitea" +version = "0.1.0" +description = "A small, reusable Rust client for the Gitea API" +edition.workspace = true +license.workspace = true +rust-version.workspace = true + +[dependencies] +gitea-openapi = { package = "gitea-client", version = "=1.25.2", default-features = false, features = ["rustls"] } +reqwest.workspace = true +serde.workspace = true +serde_json.workspace = true diff --git a/crates/gitea/src/lib.rs b/crates/gitea/src/lib.rs new file mode 100644 index 0000000..349b5e6 --- /dev/null +++ b/crates/gitea/src/lib.rs @@ -0,0 +1,207 @@ +use std::{error, fmt}; + +use reqwest::{ + Client as HttpClient, + header::{ACCEPT, AUTHORIZATION, HeaderMap, HeaderValue}, +}; +pub use reqwest::{Method, RequestBuilder, Response, StatusCode, Url}; +use serde::Deserialize; + +pub use gitea_openapi::{apis, models}; +pub use models::{Repository, ServerVersion, User}; + +pub type Result = std::result::Result; + +#[derive(Debug)] +pub enum Error { + Configuration(String), + Transport(reqwest::Error), + Generated(String), + Api { status: StatusCode, message: String }, +} + +impl fmt::Display for Error { + fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Configuration(message) => formatter.write_str(message), + Self::Transport(error) => error.fmt(formatter), + Self::Generated(message) => formatter.write_str(message), + Self::Api { status, message } => { + write!(formatter, "Gitea returned {status}: {message}") + } + } + } +} + +impl error::Error for Error { + fn source(&self) -> Option<&(dyn error::Error + 'static)> { + match self { + Self::Transport(error) => Some(error), + _ => None, + } + } +} + +impl From for Error { + fn from(error: reqwest::Error) -> Self { + Self::Transport(error) + } +} + +#[derive(Clone, Debug)] +pub struct Client { + api_url: Url, + http: HttpClient, +} + +impl Client { + pub fn new(instance_url: &str, token: Option<&str>) -> Result { + let mut instance_url = Url::parse(instance_url) + .map_err(|error| Error::Configuration(format!("invalid Gitea URL: {error}")))?; + + if !matches!(instance_url.scheme(), "http" | "https") { + return Err(Error::Configuration( + "Gitea URL must use http or https".into(), + )); + } + if !instance_url.username().is_empty() || instance_url.password().is_some() { + return Err(Error::Configuration( + "Gitea URL must not contain credentials".into(), + )); + } + if !instance_url.path().ends_with('/') { + instance_url.set_path(&format!("{}/", instance_url.path())); + } + + let api_url = instance_url + .join("api/v1/") + .map_err(|error| Error::Configuration(format!("invalid Gitea URL: {error}")))?; + let mut headers = HeaderMap::new(); + headers.insert(ACCEPT, HeaderValue::from_static("application/json")); + if let Some(token) = token { + let value = HeaderValue::from_str(&format!("token {token}")) + .map_err(|_| Error::Configuration("invalid Gitea token".into()))?; + headers.insert(AUTHORIZATION, value); + } + + Ok(Self { + api_url, + http: HttpClient::builder().default_headers(headers).build()?, + }) + } + + pub fn api_url(&self) -> &Url { + &self.api_url + } + + /// Returns an authenticated configuration for every generated typed API. + pub fn configuration(&self) -> apis::configuration::Configuration { + apis::configuration::Configuration { + base_path: self.api_url.as_str().trim_end_matches('/').into(), + client: self.http.clone(), + user_agent: Some(format!("gotcha_gitea/{}", env!("CARGO_PKG_VERSION"))), + ..Default::default() + } + } + + /// Builds an authenticated request to an API-relative endpoint. + /// + /// The returned reqwest builder supports JSON, forms, multipart uploads, + /// query parameters, and byte streams without duplicating those APIs here. + pub fn request(&self, method: Method, endpoint: &str) -> Result { + if endpoint.starts_with('/') + || Url::parse(endpoint).is_ok() + || endpoint.split('/').any(|segment| segment == "..") + { + return Err(Error::Configuration( + "endpoint must be a relative path below /api/v1".into(), + )); + } + + let url = self + .api_url + .join(endpoint) + .map_err(|error| Error::Configuration(format!("invalid endpoint: {error}")))?; + Ok(self.http.request(method, url)) + } + + pub async fn execute(&self, request: RequestBuilder) -> Result { + let response = request.send().await?; + let status = response.status(); + if status.is_success() { + return Ok(response); + } + + let body = response.text().await?; + let message = serde_json::from_str::(&body) + .ok() + .map(|error| error.message) + .filter(|message| !message.is_empty()) + .unwrap_or(body); + Err(Error::Api { status, message }) + } + + pub async fn version(&self) -> Result { + apis::miscellaneous_api::get_version(&self.configuration()) + .await + .map_err(|error| Error::Generated(error.to_string())) + } + + pub async fn current_user(&self) -> Result { + apis::user_api::user_get_current(&self.configuration()) + .await + .map_err(|error| Error::Generated(error.to_string())) + } + + pub async fn current_user_repositories(&self) -> Result> { + apis::user_api::user_current_list_repos(&self.configuration(), None, None) + .await + .map_err(|error| Error::Generated(error.to_string())) + } + + pub async fn repository(&self, owner: &str, repository: &str) -> Result { + if owner.is_empty() || repository.is_empty() { + return Err(Error::Configuration( + "repository owner and name must not be empty".into(), + )); + } + + apis::repository_api::repo_get(&self.configuration(), owner, repository) + .await + .map_err(|error| Error::Generated(error.to_string())) + } +} + +#[derive(Debug, Deserialize)] +struct ApiError { + #[serde(default)] + message: String, +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn keeps_instance_subpaths_and_rejects_endpoint_escapes() { + let client = Client::new("https://example.com/gitea", Some("secret")).unwrap(); + + assert_eq!( + client.api_url().as_str(), + "https://example.com/gitea/api/v1/" + ); + assert!(client.request(Method::GET, "repos/octo/demo").is_ok()); + assert!(client.request(Method::GET, "../admin").is_err()); + assert!( + client + .request(Method::GET, "https://example.net/user") + .is_err() + ); + assert_eq!( + client.configuration().base_path, + "https://example.com/gitea/api/v1" + ); + let _typed_query = apis::issue_api::issue_list_issues; + let _typed_model = models::Issue::default(); + } +}