Skip to content

Commit

Permalink
python: bugzilla search: add alias() support for queries
Browse files Browse the repository at this point in the history
  • Loading branch information
radhermit committed Sep 20, 2024
1 parent 12ce0a9 commit cf16fc4
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/lib/src/service/bugzilla/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,7 @@ macro_rules! make_exists_or_values_match_ref {
)+};
}
make_exists_or_values_match_ref!(&[&str], &Vec<&str>, &HashSet<&str>, &IndexSet<&str>);
make_exists_or_values_match_ref!(Vec<&str>, HashSet<&str>, IndexSet<&str>);
make_exists_or_values_match_ref!(
&[&String],
&Vec<&String>,
Expand All @@ -1257,6 +1258,7 @@ macro_rules! make_exists_or_values_match_owned {
)+};
}
make_exists_or_values_match_owned!(&[String], &Vec<String>, &HashSet<String>, &IndexSet<String>);
make_exists_or_values_match_owned!(Vec<String>, HashSet<String>, IndexSet<String>);

macro_rules! make_exists_or_values_i64 {
($($x:ty),+) => {$(
Expand Down
1 change: 1 addition & 0 deletions crates/python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ bugbite = { path = "../lib", version = "0.0.13", features = ["output", "python"]
chrono = "0.4.38"
futures-util = "0.3.30"
indexmap = "2.5.0"
itertools = "0.13.0"
pyo3 = { version = "0.22.3", features = ["extension-module", "indexmap"] }
tokio = { version = "1.40.0", features = ["full"] }
1 change: 1 addition & 0 deletions crates/python/src/bugzilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl Bugzilla {
if let Some(values) = kwds {
for (key, value) in values {
match key.to_str()? {
"alias" => req.alias(value)?,
"created" => req.created(value.to_str()?)?,
"updated" => req.updated(value.to_str()?)?,
"closed" => req.closed(value.to_str()?)?,
Expand Down
28 changes: 26 additions & 2 deletions crates/python/src/bugzilla/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ use bugbite::objects::bugzilla;
use bugbite::service::bugzilla::search;
use bugbite::traits::RequestTemplate;
use futures_util::Stream;
use itertools::Itertools;
use pyo3::exceptions::PyTypeError;
use pyo3::prelude::*;
use pyo3::types::{PyBool, PyIterator};

use crate::macros::stream_iterator;
use crate::traits::ToStr;

use super::Bug;

Expand Down Expand Up @@ -35,8 +39,23 @@ impl SearchRequest {
Ok(())
}

pub(super) fn summary(&mut self, value: &str) -> PyResult<()> {
self.0.summary([value]);
pub(super) fn alias(&mut self, value: Bound<'_, PyAny>) -> PyResult<()> {
if let Ok(value) = value.to_str() {
self.0.alias(value);
} else if let Ok(value) = value.downcast::<PyBool>() {
self.0.alias(value.is_true());
} else if let Ok(values) = value.downcast::<PyIterator>() {
let values: Vec<_> = values
.iter()?
.filter_map(|x| x.ok())
.map(|x| x.to_str_owned())
.try_collect()?;
self.0.alias(values);
} else {
return Err(PyTypeError::new_err(format!(
"invalid alias value: {value:?}"
)));
}
Ok(())
}

Expand All @@ -54,6 +73,11 @@ impl SearchRequest {
self.0.closed(value.parse()?);
Ok(())
}

pub(super) fn summary(&mut self, value: &str) -> PyResult<()> {
self.0.summary([value]);
Ok(())
}
}

#[pyclass(module = "bugbite.bugzilla")]
Expand Down
3 changes: 3 additions & 0 deletions crates/python/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use pyo3::types::PyString;

pub(crate) trait ToStr {
fn to_str(&self) -> PyResult<&str>;
fn to_str_owned(&self) -> PyResult<String> {
self.to_str().map(|x| x.to_string())
}
}

pub(crate) trait ToStrWithBound {
Expand Down

0 comments on commit cf16fc4

Please sign in to comment.