Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
Add flag to "rad issue list" to list issues someone has commented on
Matthias Beyer committed 8 months ago
commit d8fa014fb9910e52c57ec799cfda9ffc952445e5
parent d2b3a36f03ae18415a741c6c05d8888372694597
1 file changed +43 -4
modified crates/radicle-cli/src/commands/issue.rs
@@ -40,7 +40,7 @@ Usage
    rad issue [<option>...]
    rad issue delete <issue-id> [<option>...]
    rad issue edit <issue-id> [--title <title>] [--description <text>] [<option>...]
-
    rad issue list [--assigned <did>] [--all | --closed | --open | --solved] [<option>...]
+
    rad issue list [--assigned <did>] [--commented <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 assign <issue-id> [--add <did>] [--delete <did>] [<option>...]
@@ -102,6 +102,14 @@ pub enum Assigned {
    Peer(Did),
}

+
/// Command line "--commented" argument.
+
#[derive(Default, Debug, PartialEq, Eq)]
+
pub enum Commented {
+
    #[default]
+
    Me,
+
    Peer(Did),
+
}
+

#[derive(Debug, PartialEq, Eq)]
pub enum Operation {
    Edit {
@@ -152,6 +160,7 @@ pub enum Operation {
    },
    List {
        assigned: Option<Assigned>,
+
        commented: Option<Commented>,
        state: Option<State>,
    },
    Cache {
@@ -188,6 +197,7 @@ impl Args for Options {
        let mut op: Option<OperationName> = None;
        let mut id: Option<Rev> = None;
        let mut assigned: Option<Assigned> = None;
+
        let mut commented: Option<Commented> = None;
        let mut title: Option<Title> = None;
        let mut reaction: Option<Reaction> = None;
        let mut comment_id: Option<thread::CommentId> = None;
@@ -337,6 +347,15 @@ impl Args for Options {
                    }
                }

+
                Long("commented") if commented.is_none() => {
+
                    if let Ok(val) = parser.value() {
+
                        let peer = term::args::did(&val)?;
+
                        commented = Some(Commented::Peer(peer));
+
                    } else {
+
                        commented = Some(Commented::Me);
+
                    }
+
                }
+

                // Label options
                Short('a') | Long("add") if matches!(op, Some(OperationName::Label)) => {
                    let val = parser.value()?;
@@ -452,7 +471,11 @@ impl Args for Options {
                id: id.ok_or_else(|| anyhow!("an issue to label must be provided"))?,
                opts: label_opts,
            },
-
            OperationName::List => Operation::List { assigned, state },
+
            OperationName::List => Operation::List {
+
                assigned,
+
                commented,
+
                state,
+
            },
            OperationName::Cache => Operation::Cache {
                id,
                storage: cache_storage,
@@ -676,8 +699,12 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
                .collect::<Vec<_>>();
            issue.label(labels, &signer)?;
        }
-
        Operation::List { assigned, state } => {
-
            list(issues, &assigned, &state, &profile)?;
+
        Operation::List {
+
            assigned,
+
            commented,
+
            state,
+
        } => {
+
            list(issues, &assigned, &commented, &state, &profile)?;
        }
        Operation::Delete { id } => {
            let signer = term::signer(&profile)?;
@@ -717,6 +744,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
fn list<C>(
    cache: C,
    assigned: &Option<Assigned>,
+
    commented: &Option<Commented>,
    state: &Option<State>,
    profile: &profile::Profile,
) -> anyhow::Result<()>
@@ -734,6 +762,11 @@ where
        None => None,
    };

+
    let commented = commented.as_ref().map(|c| match c {
+
        Commented::Me => profile.did(),
+
        Commented::Peer(id) => *id,
+
    });
+

    let mut all = cache
        .list()?
        .filter_map(|result| {
@@ -760,6 +793,12 @@ where

            Some((id, issue))
        })
+
        .filter(|(_id, issue)| {
+
            commented
+
                .as_ref()
+
                .map(|did| issue.is_commented_by(did))
+
                .unwrap_or(true)
+
        })
        .collect::<Vec<_>>();

    all.sort_by(|(id1, i1), (id2, i2)| {