Skip to content

Commit

Permalink
Merge pull request #106 from DeterminateSystems/hoverbear/fh-196-bloc…
Browse files Browse the repository at this point in the history
…k-new-user-and-organization-creation-on-flakehub-push

Show github annotation on specific errors.
  • Loading branch information
Hoverbear authored Feb 12, 2024
2 parents e38b538 + 261f5c1 commit 6e81dc4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ async fn push_new_release(
StatusCode::UNAUTHORIZED => {
let body = &release_metadata_post_response.bytes().await?;
let message = serde_json::from_slice::<String>(body)?;

return Err(Error::Unauthorized(message))?;
}
_ => {
Expand Down
14 changes: 14 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[derive(Debug, thiserror::Error)]
pub(crate) enum Error {
/// Unauthorized, with a single line message detailing the nature of the problem.
#[error("Unauthorized: {0}")]
Unauthorized(String),
#[error("{upload_name}/{rolling_prefix_or_tag} already exists")]
Expand All @@ -15,4 +16,17 @@ impl Error {
Self::Unauthorized(_) | Self::Conflict { .. } => false,
}
}

/// Output a Github Actions annotation command if desired.
// Note: These may only be one line! Any further lines will not be printed!
pub(crate) fn maybe_github_actions_annotation(&self) {
if std::env::var("GITHUB_ACTIONS").is_ok() {
match self {
Error::Unauthorized(message) => {
println!("::error title=Unauthorized::{message}")
}
Error::Conflict { .. } => println!("::error title=Conflict::{self}"),
}
}
}
}
11 changes: 10 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ async fn main() -> color_eyre::Result<std::process::ExitCode> {

let cli = cli::FlakeHubPushCli::parse();
cli.instrumentation.setup()?;
cli.execute().await

match cli.execute().await {
Ok(exit) => Ok(exit),
Err(error) => {
if let Some(known_error) = error.downcast_ref::<Error>() {
known_error.maybe_github_actions_annotation()
}
Err(error)
}
}
}

#[derive(Debug, Clone, Copy, clap::ValueEnum, serde::Serialize, serde::Deserialize)]
Expand Down

0 comments on commit 6e81dc4

Please sign in to comment.