Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Add filtering based on author to `rad patch`
Lars Wirzenius committed 2 years ago
commit df785aa0bf347bf463ecaa6260b8fd393009c4ef
parent 72b00e3d41aff7a09679356b0751360b621a2388
4 files changed +44 -2
modified rad-patch.1.adoc
@@ -73,6 +73,9 @@ List patches in the current repository. The default is *--open*.
*--merged*::               List only merged patches
*--open*::                 List only open patches
*--draft*::                List only draft patches
+
*--authored*::             Show only patches that you have authored
+
*--author <did>*::         Show only patched where the given user is an author
+
                           (may be specified multiple times)

=== ready

modified radicle-cli/examples/rad-patch.md
@@ -71,6 +71,17 @@ index 0000000..e69de29

```

+
We can also list only patches that we've authored.
+

+
```
+
$ rad patch list --authored
+
╭─────────────────────────────────────────────────────────────────────────────────────────╮
+
│ ●  ID       Title                      Author                  Head     +   -   Updated │
+
├─────────────────────────────────────────────────────────────────────────────────────────┤
+
│ ●  6ff4f09  Define power requirements  z6MknSL…StBU8Vi  (you)  3e674d1  +0  -0  now     │
+
╰─────────────────────────────────────────────────────────────────────────────────────────╯
+
```
+

We can also see that it set an upstream for our patch branch:
```
$ git branch -vv
modified radicle-cli/src/commands/patch.rs
@@ -21,6 +21,7 @@ mod show;
#[path = "patch/update.rs"]
mod update;

+
use std::collections::BTreeSet;
use std::ffi::OsString;

use anyhow::anyhow;
@@ -43,7 +44,7 @@ pub const HELP: Help = Help {
Usage

    rad patch [<option>...]
-
    rad patch list [--all|--merged|--open|--archived|--draft] [<option>...]
+
    rad patch list [--all|--merged|--open|--archived|--draft|--authored] [--author <did>]... [<option>...]
    rad patch show <patch-id> [<option>...]
    rad patch archive <patch-id> [<option>...]
    rad patch update <patch-id> [<option>...]
@@ -80,6 +81,9 @@ List options
        --merged               Show only merged patches
        --open                 Show only open patches (default)
        --draft                Show only draft patches
+
        --authored             Show only patches that you have authored
+
        --author <did>         Show only patched where the given user is an author
+
                               (may be specified multiple times)

Ready options

@@ -187,6 +191,8 @@ pub struct Options {
    pub push: bool,
    pub verbose: bool,
    pub quiet: bool,
+
    pub authored: bool,
+
    pub authors: Vec<Did>,
}

impl Args for Options {
@@ -197,6 +203,8 @@ impl Args for Options {
        let mut op: Option<OperationName> = None;
        let mut verbose = false;
        let mut quiet = false;
+
        let mut authored = false;
+
        let mut authors = vec![];
        let mut announce = false;
        let mut patch_id = None;
        let mut revision_id = None;
@@ -293,6 +301,12 @@ impl Args for Options {
                Long("open") => {
                    filter = Filter(|s| matches!(s, patch::State::Open { .. }));
                }
+
                Long("authored") => {
+
                    authored = true;
+
                }
+
                Long("author") if op == Some(OperationName::List) => {
+
                    authors.push(term::args::did(&parser.value()?)?);
+
                }

                // Common.
                Long("verbose") | Short('v') => {
@@ -398,6 +412,8 @@ impl Args for Options {
                verbose,
                quiet,
                announce,
+
                authored,
+
                authors,
            },
            vec![],
        ))
@@ -415,7 +431,11 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {

    match options.op {
        Operation::List { filter: Filter(f) } => {
-
            list::run(f, &repository, &profile)?;
+
            let mut authors: BTreeSet<Did> = options.authors.iter().cloned().collect();
+
            if options.authored {
+
                authors.insert(profile.did());
+
            }
+
            list::run(f, authors, &repository, &profile)?;
        }
        Operation::Show { patch_id, diff } => {
            let patch_id = patch_id.resolve(&repository.backend)?;
modified radicle-cli/src/commands/patch/list.rs
@@ -1,3 +1,5 @@
+
use std::collections::BTreeSet;
+

use radicle::cob::patch;
use radicle::cob::patch::{Patch, PatchId, Patches, Verdict};
use radicle::prelude::*;
@@ -15,6 +17,7 @@ use super::common;
/// List patches.
pub fn run(
    filter: fn(&patch::State) -> bool,
+
    authors: BTreeSet<Did>,
    repository: &Repository,
    profile: &Profile,
) -> anyhow::Result<()> {
@@ -29,6 +32,11 @@ pub fn run(
        if !filter(patch.state()) {
            continue;
        }
+
        if !authors.is_empty() {
+
            if !authors.contains(patch.author().id()) {
+
                continue;
+
            }
+
        }
        all.push((id, patch));
    }