mirror of
https://github.com/block/buzz.git
synced 2026-11-01 23:11:58 +00:00
Signed-off-by: Tyler Longwell <tlongwell@block.xyz> Co-authored-by: npub1qyvc0c5kl4gqv2fd97fsk46tu378sqgy35vc83rvgfwne90sel7s0ed67d <011987e296fd5006292d2f930b574be47c7801048d1983c46c425d3c95f0cffd@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Max <d8473ee32b973aa31a21a65adddcc4b69cc2a8a4dee8121ecd51926e0cddbc02@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Mari <95cae996907d7cab9f5dbf43c0f53edeac6ab0b032a6feae4abfd784e467b3f5@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Quinn <96f056ad5f2305c8ddf637dc65d048aa4c12d7daeb8867690e34fca46b0ef64c@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Sami <f4a42a97e594b77bdbd8ee35191c8b28a94a4cb871d96f32921558275421fb68@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Perci <5a968df9a7494b4e019b9ecf739e088ba61097b4312124e9a88ae5b42e3f5f3e@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Tyler Longwell <tlongwell@block.xyz>
199 lines
5.2 KiB
Rust
199 lines
5.2 KiB
Rust
use crate::client::BuzzClient;
|
|
use crate::error::CliError;
|
|
use crate::validate::{read_or_stdin, sdk_err, validate_hex64, validate_repo_id};
|
|
use buzz_sdk::{GitIssueMeta, GitRepoCoord, GitStatusMeta};
|
|
|
|
pub async fn cmd_create_issue(
|
|
client: &BuzzClient,
|
|
repo_owner: &str,
|
|
repo_id: &str,
|
|
subject: &str,
|
|
content: &str,
|
|
labels: &[String],
|
|
to: &[String],
|
|
) -> Result<(), CliError> {
|
|
validate_hex64(repo_owner)?;
|
|
validate_repo_id(repo_id)?;
|
|
let body = read_or_stdin(content)?;
|
|
|
|
let meta = GitIssueMeta {
|
|
labels: labels.to_vec(),
|
|
recipients: to.to_vec(),
|
|
};
|
|
|
|
let repo = GitRepoCoord {
|
|
owner: repo_owner.to_string(),
|
|
id: repo_id.to_string(),
|
|
};
|
|
|
|
let builder = buzz_sdk::build_git_issue(&repo, subject, &body, &meta).map_err(sdk_err)?;
|
|
let event = client.sign_event(builder)?;
|
|
let resp = client.submit_event(event).await?;
|
|
println!("{resp}");
|
|
Ok(())
|
|
}
|
|
|
|
pub async fn cmd_get_issue(client: &BuzzClient, event: &str) -> Result<(), CliError> {
|
|
validate_hex64(event)?;
|
|
let filter = serde_json::json!({
|
|
"kinds": [1621],
|
|
"ids": [event]
|
|
});
|
|
let resp = client.query(&filter).await?;
|
|
println!("{resp}");
|
|
Ok(())
|
|
}
|
|
|
|
pub async fn cmd_list_issues(
|
|
client: &BuzzClient,
|
|
repo_owner: &str,
|
|
repo_id: &str,
|
|
author: Option<&str>,
|
|
label: Option<&str>,
|
|
limit: Option<u32>,
|
|
) -> Result<(), CliError> {
|
|
validate_hex64(repo_owner)?;
|
|
validate_repo_id(repo_id)?;
|
|
|
|
let a_value = format!("30617:{repo_owner}:{repo_id}");
|
|
let mut filter = serde_json::json!({
|
|
"kinds": [1621],
|
|
"#a": [a_value]
|
|
});
|
|
|
|
if let Some(pk) = author {
|
|
validate_hex64(pk)?;
|
|
filter["authors"] = serde_json::json!([pk]);
|
|
}
|
|
if let Some(l) = label {
|
|
filter["#t"] = serde_json::json!([l]);
|
|
}
|
|
if let Some(n) = limit {
|
|
filter["limit"] = serde_json::json!(n);
|
|
}
|
|
|
|
let resp = client.query(&filter).await?;
|
|
println!("{resp}");
|
|
Ok(())
|
|
}
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
pub async fn cmd_issue_status(
|
|
client: &BuzzClient,
|
|
issue: &str,
|
|
status: &str,
|
|
content: Option<&str>,
|
|
repo_owner: Option<&str>,
|
|
repo_id: Option<&str>,
|
|
euc: Option<&str>,
|
|
to: &[String],
|
|
) -> Result<(), CliError> {
|
|
validate_hex64(issue)?;
|
|
let status = crate::commands::patches::parse_status(status)?;
|
|
let body = match content {
|
|
Some(c) => read_or_stdin(c)?,
|
|
None => String::new(),
|
|
};
|
|
|
|
let repo = match (repo_owner, repo_id) {
|
|
(Some(owner), Some(id)) => {
|
|
validate_hex64(owner)?;
|
|
validate_repo_id(id)?;
|
|
Some(GitRepoCoord {
|
|
owner: owner.to_string(),
|
|
id: id.to_string(),
|
|
})
|
|
}
|
|
(None, None) => None,
|
|
_ => {
|
|
return Err(CliError::Usage(
|
|
"--repo-owner and --repo-id must be given together".into(),
|
|
))
|
|
}
|
|
};
|
|
|
|
// Mirrors `buzz patches status`: default a `p` tag to the repo owner
|
|
// for discoverability, plus a `--to` escape hatch for the issue author
|
|
// or anyone else who should be notified of the status change.
|
|
let mut recipients = Vec::new();
|
|
if let Some(ref repo) = repo {
|
|
recipients.push(repo.owner.clone());
|
|
}
|
|
for recipient in to {
|
|
validate_hex64(recipient)?;
|
|
if !recipients.contains(recipient) {
|
|
recipients.push(recipient.clone());
|
|
}
|
|
}
|
|
|
|
let meta = GitStatusMeta {
|
|
root_event: issue.to_string(),
|
|
accepted_revision_root: None,
|
|
repo,
|
|
euc: euc.map(str::to_string),
|
|
recipients,
|
|
applied_patches: vec![],
|
|
merge_commit: None,
|
|
applied_as_commits: vec![],
|
|
};
|
|
|
|
let builder = buzz_sdk::build_git_status(status, &body, &meta).map_err(sdk_err)?;
|
|
let event = client.sign_event(builder)?;
|
|
let resp = client.submit_event(event).await?;
|
|
println!("{resp}");
|
|
Ok(())
|
|
}
|
|
|
|
pub async fn dispatch(cmd: crate::IssuesCmd, client: &BuzzClient) -> Result<(), CliError> {
|
|
use crate::IssuesCmd;
|
|
match cmd {
|
|
IssuesCmd::Create {
|
|
repo_owner,
|
|
repo_id,
|
|
title,
|
|
content,
|
|
label,
|
|
to,
|
|
} => cmd_create_issue(client, &repo_owner, &repo_id, &title, &content, &label, &to).await,
|
|
IssuesCmd::Get { event } => cmd_get_issue(client, &event).await,
|
|
IssuesCmd::List {
|
|
repo_owner,
|
|
repo_id,
|
|
author,
|
|
label,
|
|
limit,
|
|
} => {
|
|
cmd_list_issues(
|
|
client,
|
|
&repo_owner,
|
|
&repo_id,
|
|
author.as_deref(),
|
|
label.as_deref(),
|
|
limit,
|
|
)
|
|
.await
|
|
}
|
|
IssuesCmd::Status {
|
|
issue,
|
|
status,
|
|
content,
|
|
repo_owner,
|
|
repo_id,
|
|
euc,
|
|
to,
|
|
} => {
|
|
cmd_issue_status(
|
|
client,
|
|
&issue,
|
|
&status,
|
|
content.as_deref(),
|
|
repo_owner.as_deref(),
|
|
repo_id.as_deref(),
|
|
euc.as_deref(),
|
|
&to,
|
|
)
|
|
.await
|
|
}
|
|
}
|
|
}
|