-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to fail on error when running with upload-to-github #327
Changes from 1 commit
e7a76b0
fcc2dca
e5de367
daf8c28
c97702f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -14,6 +14,7 @@ pub enum SquawkError { | |||||
GithubPrivateKeyBase64DecodeError(base64::DecodeError), | ||||||
GithubPrivateKeyDecodeError(std::string::FromUtf8Error), | ||||||
GithubPrivateKeyMissing, | ||||||
RulesViolatedError, | ||||||
} | ||||||
|
||||||
impl std::fmt::Display for SquawkError { | ||||||
|
@@ -31,6 +32,7 @@ impl std::fmt::Display for SquawkError { | |||||
write!(f, "Could not decode GitHub private key to string: {err}") | ||||||
} | ||||||
Self::GithubPrivateKeyMissing => write!(f, "Missing GitHub private key"), | ||||||
Self::RulesViolatedError => write!(f, "Rules were violated"), | ||||||
} | ||||||
} | ||||||
} | ||||||
|
@@ -59,6 +61,9 @@ pub enum Command { | |||||
/// --exclude=require-concurrent-index-creation,ban-drop-database | ||||||
#[structopt(short, long, use_delimiter = true)] | ||||||
exclude: Option<Vec<RuleViolationKind>>, | ||||||
/// Exits with an error code when specified | ||||||
#[structopt(long)] | ||||||
exit_on_error: bool, | ||||||
#[structopt(long, env = "SQUAWK_GITHUB_PRIVATE_KEY")] | ||||||
github_private_key: Option<String>, | ||||||
#[structopt(long, env = "SQUAWK_GITHUB_PRIVATE_KEY_BASE64")] | ||||||
|
@@ -115,6 +120,7 @@ pub fn check_and_comment_on_pr( | |||||
let Command::UploadToGithub { | ||||||
paths, | ||||||
exclude, | ||||||
exit_on_error, | ||||||
github_private_key, | ||||||
github_token, | ||||||
github_app_id, | ||||||
|
@@ -133,7 +139,8 @@ pub fn check_and_comment_on_pr( | |||||
pg_version, | ||||||
assume_in_transaction, | ||||||
)?; | ||||||
if file_results.is_empty() { | ||||||
let is_empty = file_results.is_empty(); | ||||||
if is_empty { | ||||||
info!("no files checked, exiting"); | ||||||
return Ok(()); | ||||||
} | ||||||
|
@@ -147,13 +154,13 @@ pub fn check_and_comment_on_pr( | |||||
get_github_private_key(github_private_key, github_private_key_base64)?; | ||||||
let gh = app::GitHub::new(&gh_private_key, github_app_id, github_install_id)?; | ||||||
|
||||||
return Ok(comment_on_pr( | ||||||
comment_on_pr( | ||||||
&gh, | ||||||
&github_repo_owner, | ||||||
&github_repo_name, | ||||||
github_pr_number, | ||||||
&comment_body, | ||||||
)?); | ||||||
)?; | ||||||
} | ||||||
} | ||||||
if let Some(github_token) = github_token { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
so we don't have a case where we could have commont_on_pr run twice There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I missed that, thanks for mentioning. Done in fcc2dca. |
||||||
|
@@ -167,5 +174,10 @@ pub fn check_and_comment_on_pr( | |||||
&comment_body, | ||||||
)?; | ||||||
} | ||||||
|
||||||
if !is_empty && exit_on_error { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're absolutely right! Done in e5de367. |
||||||
return Err(SquawkError::RulesViolatedError); | ||||||
} | ||||||
|
||||||
Ok(()) | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thoughts on calling it something like:
or maybe
since we do exit with an error already, just not when there's violations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which one do you prefer? Another option on the table would be instead of using
exit
using something likefail
:fail_on_violations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I like
fail_on_violations
!!