Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
cli: Move label commands to issue and patch
Browse files Browse the repository at this point in the history
It is more natural for the label and unlabel commands to exist as
subcommands of the object they are labelling, i.e. issues and
patches.

Remove the `rad label` and `rad unlabel` commands, moving their
functionality to the `rad issue` and `rad patch` commands. The
`rad-issue.md` and `rad-patch.md` tests are modified to include a
label test.

The `rad patch show` command did not support showing labels as part of
its output. This was also included to confirm the test above was working.

Signed-off-by: Fintan Halpenny <[email protected]>
X-Clacks-Overhead: GNU Terry Pratchett
  • Loading branch information
FintanH authored and cloudhead committed Nov 30, 2023
1 parent 511165b commit 1af9480
Show file tree
Hide file tree
Showing 14 changed files with 217 additions and 354 deletions.
2 changes: 2 additions & 0 deletions rad-patch.1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ rad-patch - Manage radicle patches.
*rad patch* _edit_ <patch-id> [<option>...] +
*rad patch* _set_ <patch-id> [<option>...] +
*rad patch* _comment_ <revision-id> [<option>...] +
*rad patch* _label_ <patch-id> --label <label> [<option>...] +
*rad patch* _unlabel_ <patch-id> --label <label> [<option>...] +

== Description

Expand Down
34 changes: 19 additions & 15 deletions radicle-cli/examples/rad-issue.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,27 @@ $ rad issue show d185ee1

Great! Now we've documented the issue for ourselves and others.

Just like with other project management systems, the issue can be assigned to
others to work on. This is to ensure work is not duplicated.
Just like with other project management systems, the issue can be
labeled and assigned to others to work on. This is to ensure work is
not duplicated.

Let's assign ourselves to this one.
Let's assign ourselves to this one, this is to ensure work is not
duplicated. While we're at it, let's add a label.

```
$ rad assign d185ee16a00bac874c0bcbc2a8ad80fdce5e1e61 --to did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
$ rad assign d185ee16a00bac874c0bcbc2a8ad80fdce5e1e6 --to did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
$ rad issue label d185ee1 -l good-first-issue
```

It will now show in the list of issues assigned to us.
It will now show in the list of issues assigned to us, along with the new label.

```
$ rad issue list --assigned
╭─────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ● ID Title Author Labels Assignees Opened │
├─────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ● d185ee1 flux capacitor underpowered z6MknSL…StBU8Vi (you) z6MknSL…StBU8Vi now │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ ● ID Title Author Labels Assignees Opened │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ ● d185ee1 flux capacitor underpowered z6MknSL…StBU8Vi (you) good-first-issue z6MknSL…StBU8Vi now │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
```

Note: this can always be undone with the `unassign` subcommand.
Expand All @@ -76,9 +79,9 @@ It will help whoever works on a fix.

```
$ rad issue comment d185ee16a00bac874c0bcbc2a8ad80fdce5e1e61 --message 'The flux capacitor needs 1.21 Gigawatts' -q
14019611935fd1c66458111a5b49f0a7350c226f
$ rad issue comment d185ee16a00bac874c0bcbc2a8ad80fdce5e1e61 --reply-to 14019611935fd1c66458111a5b49f0a7350c226f --message 'More power!' -q
e342e47b7dd93451d47c806a0faeb0b5e957da2c
80ef590710edb64dfa57e8e940d6e4d0b0ae4217
$ rad issue comment d185ee16a00bac874c0bcbc2a8ad80fdce5e1e61 --reply-to 80ef590710edb64dfa57e8e940d6e4d0b0ae4217 --message 'More power!' -q
91009820ca0996d93b9afd5739a4d2158a2ec898
```

We can see our comments by showing the issue:
Expand All @@ -89,14 +92,15 @@ $ rad issue show d185ee16a00bac874c0bcbc2a8ad80fdce5e1e61
│ Title flux capacitor underpowered │
│ Issue d185ee16a00bac874c0bcbc2a8ad80fdce5e1e61 │
│ Author z6MknSL…StBU8Vi (you) │
│ Labels good-first-issue │
│ Status open │
│ │
│ Flux capacitor power requirements exceed current supply │
├─────────────────────────────────────────────────────────┤
│ z6MknSL…StBU8Vi (you) now 1401961
│ z6MknSL…StBU8Vi (you) now 80ef590
│ The flux capacitor needs 1.21 Gigawatts │
├─────────────────────────────────────────────────────────┤
│ z6MknSL…StBU8Vi (you) now e342e47
│ z6MknSL…StBU8Vi (you) now 9100982
│ More power! │
╰─────────────────────────────────────────────────────────╯
```
42 changes: 0 additions & 42 deletions radicle-cli/examples/rad-label.md

This file was deleted.

36 changes: 30 additions & 6 deletions radicle-cli/examples/rad-patch.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,28 @@ $ git branch -vv
master f2de534 [rad/master] Second commit
```

We also want to label the patch after we've created it:
```
$ rad patch label 6ff4f09c1b5a81347981f59b02ef43a31a07cdae -l fun
$ rad patch show 6ff4f09c1b5a81347981f59b02ef43a31a07cdae
╭────────────────────────────────────────────────────╮
│ Title Define power requirements │
│ Patch 6ff4f09c1b5a81347981f59b02ef43a31a07cdae │
│ Author z6MknSL…StBU8Vi (you) │
│ Labels fun │
│ Head 3e674d1a1df90807e934f9ae5da2591dd6848a33 │
│ Branches flux-capacitor-power │
│ Commits ahead 1, behind 0 │
│ Status open │
│ │
│ See details. │
├────────────────────────────────────────────────────┤
│ 3e674d1 Define power requirements │
├────────────────────────────────────────────────────┤
│ ● opened by z6MknSL…StBU8Vi (you) now │
╰────────────────────────────────────────────────────╯
```

Wait, let's add a README too! Just for fun.

```
Expand All @@ -101,7 +123,7 @@ $ git commit --message "Add README, just for the fun"
```
``` (stderr)
$ git push rad -o patch.message="Add README, just for the fun"
✓ Patch 6ff4f09 updated to 0c0942e2ff2488617d950ede15567ca39a29972e
✓ Patch 6ff4f09 updated to 873e637a66be511c45f4ef7b04fddc9def8f072c
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
3e674d1..27857ec flux-capacitor-power -> patches/6ff4f09c1b5a81347981f59b02ef43a31a07cdae
```
Expand All @@ -111,11 +133,11 @@ And let's leave a quick comment for our team:
```
$ rad patch comment 6ff4f09c1b5a81347981f59b02ef43a31a07cdae --message 'I cannot wait to get back to the 90s!'
╭───────────────────────────────────────╮
│ z6MknSL…StBU8Vi (you) now cd811db
│ z6MknSL…StBU8Vi (you) now efaf6fb
│ I cannot wait to get back to the 90s! │
╰───────────────────────────────────────╯
$ rad patch comment 6ff4f09c1b5a81347981f59b02ef43a31a07cdae --message 'My favorite decade!' --reply-to cd811db -q
b6a76fe394de87eb34cbc3823a0edc80ff98cb97
$ rad patch comment 6ff4f09c1b5a81347981f59b02ef43a31a07cdae --message 'My favorite decade!' --reply-to efaf6fb -q
2cb22a1c87af86c25368c7be9fc385720fd6086f
```

Now, let's checkout the patch that we just created:
Expand All @@ -141,6 +163,7 @@ $ rad patch show 6ff4f09
│ Title Define power requirements │
│ Patch 6ff4f09c1b5a81347981f59b02ef43a31a07cdae │
│ Author z6MknSL…StBU8Vi (you) │
│ Labels fun │
│ Head 27857ec9eb04c69cacab516e8bf4b5fd36090f66 │
│ Branches flux-capacitor-power, patch/6ff4f09 │
│ Commits ahead 2, behind 0 │
Expand All @@ -152,7 +175,7 @@ $ rad patch show 6ff4f09
│ 3e674d1 Define power requirements │
├─────────────────────────────────────────────────────────────────────┤
│ ● opened by z6MknSL…StBU8Vi (you) now │
│ ↑ updated to 0c0942e2ff2488617d950ede15567ca39a29972e (27857ec) now │
│ ↑ updated to 873e637a66be511c45f4ef7b04fddc9def8f072c (27857ec) now │
│ ✓ accepted by z6MknSL…StBU8Vi (you) now │
╰─────────────────────────────────────────────────────────────────────╯
```
Expand All @@ -166,6 +189,7 @@ $ rad patch show 6ff4f09
│ Title Define power requirements │
│ Patch 6ff4f09c1b5a81347981f59b02ef43a31a07cdae │
│ Author z6MknSL…StBU8Vi (you) │
│ Labels fun │
│ Head 27857ec9eb04c69cacab516e8bf4b5fd36090f66 │
│ Branches flux-capacitor-power, patch/6ff4f09 │
│ Commits ahead 2, behind 0 │
Expand All @@ -177,7 +201,7 @@ $ rad patch show 6ff4f09
│ 3e674d1 Define power requirements │
├─────────────────────────────────────────────────────────────────────┤
│ ● opened by z6MknSL…StBU8Vi (you) now │
│ ↑ updated to 0c0942e2ff2488617d950ede15567ca39a29972e (27857ec) now │
│ ↑ updated to 873e637a66be511c45f4ef7b04fddc9def8f072c (27857ec) now │
│ ✓ accepted by z6MknSL…StBU8Vi (you) now │
╰─────────────────────────────────────────────────────────────────────╯
```
4 changes: 0 additions & 4 deletions radicle-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ pub mod rad_init;
pub mod rad_inspect;
#[path = "commands/issue.rs"]
pub mod rad_issue;
#[path = "commands/label.rs"]
pub mod rad_label;
#[path = "commands/ls.rs"]
pub mod rad_ls;
#[path = "commands/node.rs"]
Expand All @@ -50,7 +48,5 @@ pub mod rad_sync;
pub mod rad_track;
#[path = "commands/unassign.rs"]
pub mod rad_unassign;
#[path = "commands/unlabel.rs"]
pub mod rad_unlabel;
#[path = "commands/untrack.rs"]
pub mod rad_untrack;
2 changes: 0 additions & 2 deletions radicle-cli/src/commands/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ const COMMANDS: &[Help] = &[
rad_review::HELP,
rad_clean::HELP,
rad_self::HELP,
rad_label::HELP,
rad_track::HELP,
rad_unassign::HELP,
rad_unlabel::HELP,
rad_untrack::HELP,
rad_remote::HELP,
rad_sync::HELP,
Expand Down
60 changes: 59 additions & 1 deletion radicle-cli/src/commands/issue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::str::FromStr;

use anyhow::{anyhow, Context as _};

use nonempty::NonEmpty;
use radicle::cob::common::{Label, Reaction};
use radicle::cob::issue;
use radicle::cob::issue::{CloseReason, Issues, State};
Expand Down Expand Up @@ -38,10 +39,20 @@ Usage
rad issue list [--assigned <did>] [--all | --closed | --open | --solved] [<option>...]
rad issue open [--title <title>] [--description <text>] [--label <label>] [<option>...]
rad issue react <issue-id> [--emoji <char>] [--to <comment>] [<option>...]
rad issue label <issue-id> --label <label> [<option>...]
rad issue unlabel <issue-id> --label <label> [<option>...]
rad issue comment <issue-id> [--message <message>] [--reply-to <comment-id>] [<option>...]
rad issue show <issue-id> [<option>...]
rad issue state <issue-id> [--closed | --open | --solved] [<option>...]
Label options
-l, --label Label the issue with the provided label (may be specified multiple times)
Unlabel options
-l, --label Remove the provided label from the issue (may be specified multiple times)
Options
--no-announce Don't announce issue to peers
Expand All @@ -57,11 +68,13 @@ pub enum OperationName {
Open,
Comment,
Delete,
Label,
#[default]
List,
React,
Show,
State,
Unlabel,
}

/// Command line Peer argument.
Expand Down Expand Up @@ -106,6 +119,14 @@ pub enum Operation {
reaction: Reaction,
comment_id: Option<thread::CommentId>,
},
Label {
id: Rev,
labels: NonEmpty<Label>,
},
Unlabel {
id: Rev,
labels: NonEmpty<Label>,
},
List {
assigned: Option<Assigned>,
state: Option<State>,
Expand Down Expand Up @@ -164,7 +185,12 @@ impl Args for Options {
Long("title") if op == Some(OperationName::Open) => {
title = Some(parser.value()?.to_string_lossy().into());
}
Long("label") if op == Some(OperationName::Open) => {
Short('l') | Long("label")
if matches!(
op,
Some(OperationName::Open | OperationName::Label | OperationName::Unlabel)
) =>
{
let val = parser.value()?;
let name = term::args::string(&val);
let label = Label::new(name)?;
Expand Down Expand Up @@ -248,6 +274,8 @@ impl Args for Options {
"o" | "open" => op = Some(OperationName::Open),
"r" | "react" => op = Some(OperationName::React),
"s" | "state" => op = Some(OperationName::State),
"label" => op = Some(OperationName::Label),
"unlabel" => op = Some(OperationName::Unlabel),

unknown => anyhow::bail!("unknown operation '{}'", unknown),
},
Expand Down Expand Up @@ -294,6 +322,16 @@ impl Args for Options {
OperationName::Delete => Operation::Delete {
id: id.ok_or_else(|| anyhow!("an issue to remove must be provided"))?,
},
OperationName::Label => Operation::Label {
id: id.ok_or_else(|| anyhow!("an issue to label must be provided"))?,
labels: NonEmpty::from_vec(labels)
.ok_or_else(|| anyhow!("at least one label must be specified"))?,
},
OperationName::Unlabel => Operation::Unlabel {
id: id.ok_or_else(|| anyhow!("an issue to label must be provided"))?,
labels: NonEmpty::from_vec(labels)
.ok_or_else(|| anyhow!("at least one label must be specified"))?,
},
OperationName::List => Operation::List { assigned, state },
};

Expand Down Expand Up @@ -407,6 +445,26 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
&profile,
)?;
}
Operation::Label { id, labels } => {
let id = id.resolve(&repo.backend)?;
let Ok(mut issue) = issues.get_mut(&id) else {
anyhow::bail!("Issue `{id}` not found");
};
let labels = issue.labels().cloned().chain(labels).collect::<Vec<_>>();
issue.label(labels, &signer)?;
}
Operation::Unlabel { id, labels } => {
let id = id.resolve(&repo.backend)?;
let Ok(mut issue) = issues.get_mut(&id) else {
anyhow::bail!("Issue `{id}` not found");
};
let labels = issue
.labels()
.filter(|&l| !labels.contains(l))
.cloned()
.collect::<Vec<_>>();
issue.label(labels, &signer)?;
}
Operation::List { assigned, state } => {
list(&issues, &assigned, &state, &profile)?;
}
Expand Down
Loading

0 comments on commit 1af9480

Please sign in to comment.