cli: add comment edit for rad issue
Add the ability to edit an issue comment to the `rad issue` command. This is achieved by adding an `--edit` option to `rad issue comment`. Note that if `--reply-to` and `--edit` are both specified, then this results in an error.
This commit is contained in:
parent
985987468d
commit
ffbdabe432
|
|
@ -104,3 +104,13 @@ $ rad issue show d87dcfe8c2b3200e78b128d9b959cfdf7063fefe
|
||||||
│ More power! │
|
│ More power! │
|
||||||
╰─────────────────────────────────────────────────────────╯
|
╰─────────────────────────────────────────────────────────╯
|
||||||
```
|
```
|
||||||
|
|
||||||
|
We can also edit a comment:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ rad issue comment d87dcfe --edit 880fdcd -m "Even more power!"
|
||||||
|
╭─────────────────────────╮
|
||||||
|
│ alice (you) now 880fdcd │
|
||||||
|
│ Even more power! │
|
||||||
|
╰─────────────────────────╯
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ Usage
|
||||||
rad issue react <issue-id> [--emoji <char>] [--to <comment>] [<option>...]
|
rad issue react <issue-id> [--emoji <char>] [--to <comment>] [<option>...]
|
||||||
rad issue assign <issue-id> [--add <did>] [--delete <did>] [<option>...]
|
rad issue assign <issue-id> [--add <did>] [--delete <did>] [<option>...]
|
||||||
rad issue label <issue-id> [--add <label>] [--delete <label>] [<option>...]
|
rad issue label <issue-id> [--add <label>] [--delete <label>] [<option>...]
|
||||||
rad issue comment <issue-id> [--message <message>] [--reply-to <comment-id>] [<option>...]
|
rad issue comment <issue-id> [--message <message>] [--reply-to <comment-id>] [--edit <comment-id>] [<option>...]
|
||||||
rad issue show <issue-id> [<option>...]
|
rad issue show <issue-id> [<option>...]
|
||||||
rad issue state <issue-id> [--closed | --open | --solved] [<option>...]
|
rad issue state <issue-id> [--closed | --open | --solved] [<option>...]
|
||||||
rad issue cache [<issue-id>] [--storage] [<option>...]
|
rad issue cache [<issue-id>] [--storage] [<option>...]
|
||||||
|
|
@ -118,6 +118,11 @@ pub enum Operation {
|
||||||
format: Format,
|
format: Format,
|
||||||
debug: bool,
|
debug: bool,
|
||||||
},
|
},
|
||||||
|
CommentEdit {
|
||||||
|
id: Rev,
|
||||||
|
comment_id: Rev,
|
||||||
|
message: Message,
|
||||||
|
},
|
||||||
Comment {
|
Comment {
|
||||||
id: Rev,
|
id: Rev,
|
||||||
message: Message,
|
message: Message,
|
||||||
|
|
@ -191,6 +196,7 @@ impl Args for Options {
|
||||||
let mut format = Format::default();
|
let mut format = Format::default();
|
||||||
let mut message = Message::default();
|
let mut message = Message::default();
|
||||||
let mut reply_to = None;
|
let mut reply_to = None;
|
||||||
|
let mut edit_comment = None;
|
||||||
let mut announce = true;
|
let mut announce = true;
|
||||||
let mut quiet = false;
|
let mut quiet = false;
|
||||||
let mut debug = false;
|
let mut debug = false;
|
||||||
|
|
@ -299,6 +305,12 @@ impl Args for Options {
|
||||||
|
|
||||||
reply_to = Some(rev);
|
reply_to = Some(rev);
|
||||||
}
|
}
|
||||||
|
Long("edit") if op == Some(OperationName::Comment) => {
|
||||||
|
let val = parser.value()?;
|
||||||
|
let rev = term::args::rev(&val)?;
|
||||||
|
|
||||||
|
edit_comment = Some(rev);
|
||||||
|
}
|
||||||
|
|
||||||
// Assign options
|
// Assign options
|
||||||
Short('a') | Long("add") if op == Some(OperationName::Assign) => {
|
Short('a') | Long("add") if op == Some(OperationName::Assign) => {
|
||||||
|
|
@ -390,10 +402,23 @@ impl Args for Options {
|
||||||
labels,
|
labels,
|
||||||
assignees,
|
assignees,
|
||||||
},
|
},
|
||||||
OperationName::Comment => Operation::Comment {
|
OperationName::Comment => match (reply_to, edit_comment) {
|
||||||
id: id.ok_or_else(|| anyhow!("an issue must be provided"))?,
|
(None, None) => Operation::Comment {
|
||||||
message,
|
id: id.ok_or_else(|| anyhow!("an issue must be provided"))?,
|
||||||
reply_to,
|
message,
|
||||||
|
reply_to: None,
|
||||||
|
},
|
||||||
|
(None, Some(comment_id)) => Operation::CommentEdit {
|
||||||
|
id: id.ok_or_else(|| anyhow!("an issue must be provided"))?,
|
||||||
|
comment_id,
|
||||||
|
message,
|
||||||
|
},
|
||||||
|
(reply_to @ Some(_), None) => Operation::Comment {
|
||||||
|
id: id.ok_or_else(|| anyhow!("an issue must be provided"))?,
|
||||||
|
message,
|
||||||
|
reply_to,
|
||||||
|
},
|
||||||
|
(Some(_), Some(_)) => anyhow::bail!("you cannot use --reply-to with --edit"),
|
||||||
},
|
},
|
||||||
OperationName::Show => Operation::Show {
|
OperationName::Show => Operation::Show {
|
||||||
id: id.ok_or_else(|| anyhow!("an issue must be provided"))?,
|
id: id.ok_or_else(|| anyhow!("an issue must be provided"))?,
|
||||||
|
|
@ -503,6 +528,25 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
term::comment::widget(&comment_id, comment, &profile).print();
|
term::comment::widget(&comment_id, comment, &profile).print();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Operation::CommentEdit {
|
||||||
|
id,
|
||||||
|
comment_id,
|
||||||
|
message,
|
||||||
|
} => {
|
||||||
|
let signer = term::signer(&profile)?;
|
||||||
|
let issue_id = id.resolve::<cob::ObjectId>(&repo.backend)?;
|
||||||
|
let comment_id = comment_id.resolve(&repo.backend)?;
|
||||||
|
let mut issue = issues.get_mut(&issue_id)?;
|
||||||
|
let (body, _) = prompt_comment(message, None, &issue, &repo)?;
|
||||||
|
issue.edit_comment(comment_id, body, vec![], &signer)?;
|
||||||
|
|
||||||
|
if options.quiet {
|
||||||
|
term::print(comment_id);
|
||||||
|
} else {
|
||||||
|
let comment = issue.thread().comment(&comment_id).unwrap();
|
||||||
|
term::comment::widget(&comment_id, comment, &profile).print();
|
||||||
|
}
|
||||||
|
}
|
||||||
Operation::Show { id, format, debug } => {
|
Operation::Show { id, format, debug } => {
|
||||||
let id = id.resolve(&repo.backend)?;
|
let id = id.resolve(&repo.backend)?;
|
||||||
let issue = issues
|
let issue = issues
|
||||||
|
|
@ -790,7 +834,7 @@ where
|
||||||
let id = id.resolve(&repo.backend)?;
|
let id = id.resolve(&repo.backend)?;
|
||||||
let mut issue = issues.get_mut(&id)?;
|
let mut issue = issues.get_mut(&id)?;
|
||||||
let (root, _) = issue.root();
|
let (root, _) = issue.root();
|
||||||
let root = *root;
|
let comment_id = *root;
|
||||||
|
|
||||||
if title.is_some() || description.is_some() {
|
if title.is_some() || description.is_some() {
|
||||||
// Editing by command line arguments.
|
// Editing by command line arguments.
|
||||||
|
|
@ -799,7 +843,7 @@ where
|
||||||
tx.edit(t)?;
|
tx.edit(t)?;
|
||||||
}
|
}
|
||||||
if let Some(d) = description {
|
if let Some(d) = description {
|
||||||
tx.edit_comment(root, d, vec![])?;
|
tx.edit_comment(comment_id, d, vec![])?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
})?;
|
||||||
|
|
@ -817,7 +861,7 @@ where
|
||||||
|
|
||||||
issue.transaction("Edit", signer, |tx| {
|
issue.transaction("Edit", signer, |tx| {
|
||||||
tx.edit(title)?;
|
tx.edit(title)?;
|
||||||
tx.edit_comment(root, description, vec![])?;
|
tx.edit_comment(comment_id, description, vec![])?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
})?;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue