feat: kanban: coments
runner nix smoke / nix label and flake smoke (push) Failing after 1m17s

This commit is contained in:
2026-09-29 19:48:14 +00:00
parent c93dee27b3
commit e22dcdda80
6 changed files with 253 additions and 3 deletions
@@ -55,6 +55,37 @@ enum Command {
#[arg(long)]
sorting: Option<u64>,
},
/// Manage comments on an issue in selected project.
Comment {
#[command(subcommand)]
command: CommentCommand,
},
}
#[derive(Debug, Subcommand)]
enum CommentCommand {
/// List comments for an issue.
List { issue: u64 },
/// Add a comment to an issue.
Add {
issue: u64,
#[arg(long)]
body: String,
},
/// Replace a comment body.
Edit {
issue: u64,
comment_id: u64,
#[arg(long)]
body: String,
},
/// Delete a comment.
Delete {
issue: u64,
comment_id: u64,
#[arg(long)]
yes: bool,
},
}
fn main() {
@@ -140,6 +171,81 @@ fn run() -> Result<(), Box<dyn Error>> {
)?;
println!("moved issue {issue_id} to column {column_id}");
}
Command::Comment { command } => match command {
CommentCommand::List { issue } => {
for comment in project_issue_comments(&client, &config, issue)? {
let author = comment
.user
.as_ref()
.map(|user| user.login.as_str())
.unwrap_or("unknown");
println!(
"#{} {}\n{}",
comment.id,
sanitize_terminal_text(author),
sanitize_terminal_text(&comment.body)
);
}
}
CommentCommand::Add { issue, body } => {
project_issue_comments(&client, &config, issue)?;
let comment = operations::create_issue_comment(&client, issue, body)?;
println!("created comment #{} on issue #{}", comment.id, issue);
}
CommentCommand::Edit {
issue,
comment_id,
body,
} => {
ensure_comment(&client, &config, issue, comment_id)?;
operations::edit_issue_comment(&client, comment_id, body)?;
println!("updated comment #{comment_id}");
}
CommentCommand::Delete {
issue,
comment_id,
yes,
} => {
if !yes {
return Err("comment deletion requires --yes".into());
}
ensure_comment(&client, &config, issue, comment_id)?;
operations::delete_issue_comment(&client, comment_id)?;
println!("deleted comment #{comment_id}");
}
},
}
Ok(())
}
fn project_issue_comments(
client: &GiteaClient,
config: &Config,
issue: u64,
) -> Result<Vec<gitea_kanban_tui::model::Comment>, Box<dyn Error>> {
let board = load_project_board(client, config)?;
if !board
.issues_by_column
.iter()
.flatten()
.any(|candidate| candidate.number == issue)
{
return Err(format!("issue #{issue} is not assigned to selected project").into());
}
Ok(operations::list_issue_comments(client, issue)?)
}
fn ensure_comment(
client: &GiteaClient,
config: &Config,
issue: u64,
comment_id: u64,
) -> Result<(), Box<dyn Error>> {
if !project_issue_comments(client, config, issue)?
.iter()
.any(|comment| comment.id == comment_id)
{
return Err(format!("comment #{comment_id} is not attached to issue #{issue}").into());
}
Ok(())
}