From 54eb69d1c7ee494750e03ed91ba489b43737f6f2 Mon Sep 17 00:00:00 2001 From: yukkop Date: Mon, 28 Sep 2026 00:24:44 +0000 Subject: [PATCH] feat: clear unneccessary backend from kanban --- package/gitea-kanban-tui/Cargo.toml | 2 +- package/gitea-kanban-tui/README.md | 31 +--- package/gitea-kanban-tui/src/api.rs | 56 +------ package/gitea-kanban-tui/src/app.rs | 211 ++++++------------------- package/gitea-kanban-tui/src/config.rs | 85 ++-------- package/gitea-kanban-tui/src/main.rs | 32 ++-- package/gitea-kanban-tui/src/model.rs | 94 ----------- 7 files changed, 84 insertions(+), 427 deletions(-) diff --git a/package/gitea-kanban-tui/Cargo.toml b/package/gitea-kanban-tui/Cargo.toml index bd0bced4..7cb8cb16 100644 --- a/package/gitea-kanban-tui/Cargo.toml +++ b/package/gitea-kanban-tui/Cargo.toml @@ -2,7 +2,7 @@ name = "gitea-kanban-tui" version = "0.1.0" edition = "2021" -description = "Native-project and label-backed Gitea Kanban terminal interface" +description = "Native-project Gitea Kanban terminal interface" license = "MIT" [dependencies] diff --git a/package/gitea-kanban-tui/README.md b/package/gitea-kanban-tui/README.md index a41ded9c..5a742021 100644 --- a/package/gitea-kanban-tui/README.md +++ b/package/gitea-kanban-tui/README.md @@ -1,33 +1,25 @@ # gitea-kanban-tui -Keyboard-driven Kanban board for the custom Gitea fork. Native repository -Projects are supported alongside the legacy repository-label backend. Backend -selection is explicit; API failures never trigger a silent fallback. +Keyboard-driven Kanban board for native repository Projects in custom Gitea fork. ## Configuration -Create repository labels such as `kanban/01 Todo`, `kanban/02 Doing`, and -`kanban/03 Done`. Column suffixes are sorted lexically, so numeric prefixes -provide explicit ordering. - Required configuration can come from flags or environment variables: | Flag | Environment | Meaning | | --- | --- | --- | | `--url` | `GITEA_URL` | Gitea base URL | | `--token-file` | `GITEA_TOKEN_FILE` | File containing API token | -| `--backend` | `GITEA_KANBAN_BACKEND` | Required: `projects` or `labels` | +| — | `GITEA_TOKEN` | API token fallback when no token file is configured | | `--project` | `GITEA_PROJECT` | Exact native project name | | `--project-id` | `GITEA_PROJECT_ID` | Native project ID instead of name | | positional `OWNER` | `GITEA_OWNER` | Repository owner | | positional `REPO` | `GITEA_REPO` | Repository name | -| `--label-prefix` | `GITEA_LABEL_PREFIX` | Column prefix; default `kanban/` | Native mode requires an enabled repository Projects unit, project read/write repository permission, and a token with `read:issue`/`write:issue` scope. Issue creation/editing follows Gitea issue permissions; deletion requires repository -admin permission in this fork. Label mode requires repository issue read/write -permission. Token values are sent +admin permission in this fork. Token values are sent only through Gitea's `Authorization` header and are never printed. Token-file input takes precedence over environment variables. Remote URLs must use HTTPS; plain HTTP is accepted only for loopback development. @@ -36,7 +28,7 @@ accepted only for loopback development. export GITEA_URL=https://gitea.hectic-lab.com export GITEA_TOKEN_FILE="$HOME/.config/gitea/token" cargo run --manifest-path package/gitea-kanban-tui/Cargo.toml -- \ - --backend projects --project Kanban yukkop util.nix + --project Kanban yukkop util.nix ``` Alternatively: @@ -44,14 +36,14 @@ Alternatively: ```sh nix develop .#ratatui cargo run --manifest-path package/gitea-kanban-tui/Cargo.toml -- \ - --backend projects --project-id 1 owner repo + --project-id 1 owner repo ``` ## Keys - Arrow keys or `h`/`j`/`k`/`l`: focus column/card - `H`/`L`: move focused card left/right -- `r`: refresh labels and open issues +- `r`: refresh project columns and issues - `?`: toggle help - `q`: quit @@ -65,17 +57,6 @@ focused issue title/body, and `d` deletes it after confirmation. In the editor, `Esc` cancels. Closed projects, archived repositories, disabled Projects units, unassigned issues, and cross-repository IDs are rejected by the server. -Explicit fallback command: - -```sh -cargo run --manifest-path package/gitea-kanban-tui/Cargo.toml -- \ - --backend labels --label-prefix kanban/ owner repo -``` - -In label mode, moving a card replaces its issue labels: all labels matching the configured -column prefix are removed, the target column label is added, and non-column -labels are preserved. The client uses only repository label and issue REST -endpoints under `/api/v1`. ## Development diff --git a/package/gitea-kanban-tui/src/api.rs b/package/gitea-kanban-tui/src/api.rs index efa278d9..2f02cbd0 100644 --- a/package/gitea-kanban-tui/src/api.rs +++ b/package/gitea-kanban-tui/src/api.rs @@ -9,8 +9,7 @@ use serde::de::DeserializeOwned; use crate::config::Config; use crate::model::{ - CreateIssuePayload, EditIssuePayload, Issue, Label, MoveProjectIssuePayload, Project, - ProjectColumn, ReplaceLabelsPayload, + CreateIssuePayload, EditIssuePayload, Issue, MoveProjectIssuePayload, Project, ProjectColumn, }; use crate::text::sanitize_terminal_text; @@ -28,13 +27,6 @@ pub trait GiteaApi { issue_id: u64, payload: &MoveProjectIssuePayload, ) -> Result<(), ApiError>; - fn list_labels(&self) -> Result, ApiError>; - fn list_open_issues(&self) -> Result, ApiError>; - fn replace_issue_labels( - &self, - issue_number: u64, - payload: &ReplaceLabelsPayload, - ) -> Result<(), ApiError>; fn create_issue(&self, payload: &CreateIssuePayload) -> Result; fn edit_issue(&self, issue_number: u64, payload: &EditIssuePayload) -> Result; fn delete_issue(&self, issue_number: u64) -> Result<(), ApiError>; @@ -227,42 +219,6 @@ impl GiteaApi for GiteaClient { Ok(()) } - fn list_labels(&self) -> Result, ApiError> { - self.get_all("labels", "listing repository labels", &[]) - } - - fn list_open_issues(&self) -> Result, ApiError> { - self.get_all( - "issues", - "listing open repository issues", - &[("state", "open"), ("type", "issues")], - ) - } - - fn replace_issue_labels( - &self, - issue_number: u64, - payload: &ReplaceLabelsPayload, - ) -> Result<(), ApiError> { - let response = self - .client - .put(self.endpoint(&format!("issues/{issue_number}/labels"))?) - .header("Authorization", format!("token {}", self.token)) - .json(payload) - .send() - .map_err(|error| { - ApiError(format!( - "cannot reach Gitea while moving issue #{issue_number}: {error}" - )) - })?; - check_response( - response, - &format!("replacing labels on issue #{issue_number}"), - &self.token, - )?; - Ok(()) - } - fn create_issue(&self, payload: &CreateIssuePayload) -> Result { let response = self .client @@ -331,7 +287,7 @@ fn check_response(response: Response, operation: &str, token: &str) -> Result { - " Check repository owner/name and whether this Gitea version supports repository issue-label APIs." + " Check repository owner/name and whether this Gitea version supports native project APIs." } _ => "", }; @@ -376,10 +332,8 @@ mod tests { token: "secret".to_owned(), owner: "owner name".to_owned(), repo: "repo/name".to_owned(), - backend: crate::config::Backend::Labels, - project: None, + project: Some("Kanban".to_owned()), project_id: None, - label_prefix: "kanban/".to_owned(), } } @@ -433,8 +387,8 @@ mod tests { .expect("client should build"); assert_eq!( - client.endpoint("labels").expect("endpoint").as_str(), - "https://gitea.example/subpath/api/v1/repos/owner%20name/repo%2Fname/labels" + client.endpoint("projects").expect("endpoint").as_str(), + "https://gitea.example/subpath/api/v1/repos/owner%20name/repo%2Fname/projects" ); } diff --git a/package/gitea-kanban-tui/src/app.rs b/package/gitea-kanban-tui/src/app.rs index 22e001b9..fa630895 100644 --- a/package/gitea-kanban-tui/src/app.rs +++ b/package/gitea-kanban-tui/src/app.rs @@ -1,8 +1,7 @@ use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; use crate::model::{ - extract_columns, replacement_payload, ColumnSpec, EditIssuePayload, Issue, Label, - MoveProjectIssuePayload, Project, ProjectColumn, ReplaceLabelsPayload, + ColumnSpec, EditIssuePayload, Issue, MoveProjectIssuePayload, Project, ProjectColumn, }; #[derive(Clone, Debug)] @@ -19,7 +18,7 @@ pub struct App { pub status: String, pub show_help: bool, pub editor: Option, - backend: BoardBackend, + project_id: u64, } #[derive(Clone, Debug, PartialEq, Eq)] @@ -59,12 +58,6 @@ pub enum IssueAction { }, } -#[derive(Clone, Debug)] -enum BoardBackend { - Projects { project_id: u64 }, - Labels { prefix: String }, -} - #[derive(Debug, PartialEq, Eq)] pub enum MoveAction { Project { @@ -72,10 +65,6 @@ pub enum MoveAction { project_id: u64, payload: MoveProjectIssuePayload, }, - Labels { - issue_number: u64, - payload: ReplaceLabelsPayload, - }, } #[derive(Debug, PartialEq, Eq)] @@ -86,59 +75,6 @@ pub struct MoveRequest { } impl App { - pub fn new_labels( - labels: Vec