Skip to content

Commit

Permalink
Use TagSet for workflow tags
Browse files Browse the repository at this point in the history
  • Loading branch information
msk committed Feb 22, 2024
1 parent 1bf87b2 commit 6f6c803
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ oinq = { git = "https://github.com/petabi/oinq.git", tag = "0.9.1" }
reqwest = { version = "0.11", default-features = false, features = [
"rustls-tls-native-roots",
] }
review-database = { git = "https://github.com/petabi/review-database.git", rev = "e13263aa" }
review-database = { git = "https://github.com/petabi/review-database.git", rev = "5f0cb096" }
roxy = { git = "https://github.com/aicers/roxy.git", tag = "0.2.1" }
rustls = "0.21"
rustls-native-certs = "0.6"
Expand Down
25 changes: 12 additions & 13 deletions src/graphql/tags/workflow_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ impl WorkflowTagQuery {
/// A list of workflow tags.
async fn workflow_tag_list(&self, ctx: &Context<'_>) -> Result<Vec<Tag>> {
let store = crate::graphql::get_store(ctx).await?;
let set = store.workflow_tag_set();
let index = set.index()?;
Ok(index
.iter()
.map(|(id, name)| Tag {
id,
name: String::from_utf8_lossy(name).into_owned(),
let set = store.workflow_tag_set()?;
Ok(set
.tags()
.map(|tag| Tag {
id: tag.id,
name: tag.name.clone(),
})
.collect())
}
Expand All @@ -29,8 +28,8 @@ impl WorkflowTagMutation {
/// Inserts a new workflow tag, returning the ID of the new tag.
async fn insert_workflow_tag(&self, ctx: &Context<'_>, name: String) -> Result<ID> {
let store = crate::graphql::get_store(ctx).await?;
let set = store.workflow_tag_set();
let id = set.insert(name.as_bytes())?;
let mut set = store.workflow_tag_set()?;
let id = set.insert(&name)?;
Ok(ID(id.to_string()))
}

Expand All @@ -40,9 +39,9 @@ impl WorkflowTagMutation {
let store = crate::graphql::get_store(ctx).await?;
// TODO: Delete the tag from workflows when assigning tags to a workflow
// is implemented.
let set = store.workflow_tag_set();
let mut set = store.workflow_tag_set()?;
let name = set.remove(id.0.parse()?)?;
Ok(Some(String::from_utf8_lossy(&name).into_owned()))
Ok(Some(name))
}

/// Updates the name of a workflow tag for the given ID.
Expand All @@ -57,7 +56,7 @@ impl WorkflowTagMutation {
new: String,
) -> Result<bool> {
let store = crate::graphql::get_store(ctx).await?;
let set = store.workflow_tag_set();
Ok(set.update(id.0.parse()?, old.as_bytes(), new.as_bytes())?)
let mut set = store.workflow_tag_set()?;
Ok(set.update(id.0.parse()?, &old, &new)?)
}
}

0 comments on commit 6f6c803

Please sign in to comment.