cli: Add filtering based on author to `rad patch`
My use case for this is to have a script that lists my outstanding patches so I can ping people for review or merge if there's no movement for a long time. Signed-off-by: Lars Wirzenius <liw@liw.fi>
This commit is contained in:
parent
72b00e3d41
commit
df785aa0bf
|
|
@ -73,6 +73,9 @@ List patches in the current repository. The default is *--open*.
|
||||||
*--merged*:: List only merged patches
|
*--merged*:: List only merged patches
|
||||||
*--open*:: List only open patches
|
*--open*:: List only open patches
|
||||||
*--draft*:: List only draft 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
|
=== ready
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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:
|
We can also see that it set an upstream for our patch branch:
|
||||||
```
|
```
|
||||||
$ git branch -vv
|
$ git branch -vv
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ mod show;
|
||||||
#[path = "patch/update.rs"]
|
#[path = "patch/update.rs"]
|
||||||
mod update;
|
mod update;
|
||||||
|
|
||||||
|
use std::collections::BTreeSet;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
|
|
@ -43,7 +44,7 @@ pub const HELP: Help = Help {
|
||||||
Usage
|
Usage
|
||||||
|
|
||||||
rad patch [<option>...]
|
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 show <patch-id> [<option>...]
|
||||||
rad patch archive <patch-id> [<option>...]
|
rad patch archive <patch-id> [<option>...]
|
||||||
rad patch update <patch-id> [<option>...]
|
rad patch update <patch-id> [<option>...]
|
||||||
|
|
@ -80,6 +81,9 @@ List options
|
||||||
--merged Show only merged patches
|
--merged Show only merged patches
|
||||||
--open Show only open patches (default)
|
--open Show only open patches (default)
|
||||||
--draft Show only draft patches
|
--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
|
Ready options
|
||||||
|
|
||||||
|
|
@ -187,6 +191,8 @@ pub struct Options {
|
||||||
pub push: bool,
|
pub push: bool,
|
||||||
pub verbose: bool,
|
pub verbose: bool,
|
||||||
pub quiet: bool,
|
pub quiet: bool,
|
||||||
|
pub authored: bool,
|
||||||
|
pub authors: Vec<Did>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Args for Options {
|
impl Args for Options {
|
||||||
|
|
@ -197,6 +203,8 @@ impl Args for Options {
|
||||||
let mut op: Option<OperationName> = None;
|
let mut op: Option<OperationName> = None;
|
||||||
let mut verbose = false;
|
let mut verbose = false;
|
||||||
let mut quiet = false;
|
let mut quiet = false;
|
||||||
|
let mut authored = false;
|
||||||
|
let mut authors = vec![];
|
||||||
let mut announce = false;
|
let mut announce = false;
|
||||||
let mut patch_id = None;
|
let mut patch_id = None;
|
||||||
let mut revision_id = None;
|
let mut revision_id = None;
|
||||||
|
|
@ -293,6 +301,12 @@ impl Args for Options {
|
||||||
Long("open") => {
|
Long("open") => {
|
||||||
filter = Filter(|s| matches!(s, patch::State::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.
|
// Common.
|
||||||
Long("verbose") | Short('v') => {
|
Long("verbose") | Short('v') => {
|
||||||
|
|
@ -398,6 +412,8 @@ impl Args for Options {
|
||||||
verbose,
|
verbose,
|
||||||
quiet,
|
quiet,
|
||||||
announce,
|
announce,
|
||||||
|
authored,
|
||||||
|
authors,
|
||||||
},
|
},
|
||||||
vec![],
|
vec![],
|
||||||
))
|
))
|
||||||
|
|
@ -415,7 +431,11 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
|
|
||||||
match options.op {
|
match options.op {
|
||||||
Operation::List { filter: Filter(f) } => {
|
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 } => {
|
Operation::Show { patch_id, diff } => {
|
||||||
let patch_id = patch_id.resolve(&repository.backend)?;
|
let patch_id = patch_id.resolve(&repository.backend)?;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
use radicle::cob::patch;
|
use radicle::cob::patch;
|
||||||
use radicle::cob::patch::{Patch, PatchId, Patches, Verdict};
|
use radicle::cob::patch::{Patch, PatchId, Patches, Verdict};
|
||||||
use radicle::prelude::*;
|
use radicle::prelude::*;
|
||||||
|
|
@ -15,6 +17,7 @@ use super::common;
|
||||||
/// List patches.
|
/// List patches.
|
||||||
pub fn run(
|
pub fn run(
|
||||||
filter: fn(&patch::State) -> bool,
|
filter: fn(&patch::State) -> bool,
|
||||||
|
authors: BTreeSet<Did>,
|
||||||
repository: &Repository,
|
repository: &Repository,
|
||||||
profile: &Profile,
|
profile: &Profile,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
|
|
@ -29,6 +32,11 @@ pub fn run(
|
||||||
if !filter(patch.state()) {
|
if !filter(patch.state()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if !authors.is_empty() {
|
||||||
|
if !authors.contains(patch.author().id()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
all.push((id, patch));
|
all.push((id, patch));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue