Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
leverage error propagation to avoid error-prone repetitive error mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
joao-paulo-parity committed Mar 25, 2021
1 parent 585f777 commit e9dfc34
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 310 deletions.
15 changes: 11 additions & 4 deletions src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
pub const AUTO_MERGE_REQUEST: &str = "bot merge";
pub const AUTO_MERGE_FORCE: &str = "bot merge force";
pub const AUTO_MERGE_CANCEL: &str = "bot merge cancel";
pub const REBASE: &str = "bot rebase";
pub const BURNIN_REQUEST: &str = "bot burnin";
pub const COMPARE_RELEASE_REQUEST: &str = "bot compare substrate";
pub const BOT_COMMANDS: [&str; 6] = [
AUTO_MERGE_REQUEST,
AUTO_MERGE_FORCE,
AUTO_MERGE_CANCEL,
REBASE,
BURNIN_REQUEST,
COMPARE_RELEASE_REQUEST,
];

pub const AUTO_MERGE_FAILED: &str = "Cannot merge; please ensure the pull request is mergeable and has approval from the project owner or at least {min_reviewers} core devs.";
pub const AUTO_MERGE_CHECKS_FAILED: &str = "Checks failed; cannot auto-merge.";
Expand All @@ -9,10 +20,6 @@ pub const AUTO_MERGE_CHECKS_ERROR: &str =
pub const AUTO_MERGE_INVALIDATED: &str =
"Something has changed since auto-merge was requested; cancelling.";

pub const COMPARE_RELEASE_REQUEST: &str = "bot compare substrate";
pub const REBASE: &str = "bot rebase";
pub const BURNIN_REQUEST: &str = "bot burnin";

pub const FEATURES_KEY: &str = "features";

pub const PROJECT_NEEDS_BACKLOG: &str =
Expand Down
24 changes: 15 additions & 9 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,31 @@ pub enum Error {
field: String,
},

#[snafu(display("Error updating companion: {}", source))]
Companion {
source: Box<Error>,
},

#[snafu(display("Error merging: {}", source))]
Merge {
source: Box<Error>,
commit_sha: String,
},

#[snafu(display("Companion update failed: {}", source))]
CompanionUpdate {
source: Box<Error>,
},

#[snafu(display("Rebase failed: {}", source))]
Rebase {
source: Box<Error>,
},

#[snafu(display("Checks failed for {}", commit_sha))]
ChecksFailed {
commit_sha: String,
},

#[snafu(display("Head SHA changed from {}", commit_sha))]
#[snafu(display("Head SHA changed from {} to {}", expected, actual))]
HeadChanged {
commit_sha: String,
expected: String,
actual: String,
},

#[snafu(display("Error getting organization membership: {}", source))]
Expand All @@ -53,7 +59,7 @@ pub enum Error {
#[snafu(display("Missing approval."))]
Approval {},

#[snafu(display("Error: {}", msg))]
#[snafu(display("{}", msg))]
Message {
msg: String,
},
Expand Down Expand Up @@ -171,7 +177,7 @@ pub enum Error {
},

#[snafu(display(
"Cmd '{}' failed with status {:?}; output: {}",
"Command '{}' failed with status {:?}; output: {}",
cmd,
status_code,
err
Expand Down
6 changes: 4 additions & 2 deletions src/github.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{error::*, Result, PR_HTML_URL_REGEX};
use crate::{constants::BOT_COMMANDS, error::*, Result, PR_HTML_URL_REGEX};
use regex::Regex;
use serde::{Deserialize, Serialize};
use snafu::OptionExt;
Expand Down Expand Up @@ -784,7 +784,9 @@ impl DetectUserCommentPullRequest {
}),
} = self
{
if body.trim().starts_with("bot ") {
let body = body.trim();

if BOT_COMMANDS.iter().find(|cmd| **cmd == body).is_some() {
if let Some(DetectUserCommentPullRequestRepository {
name: Some(name),
owner: Some(User { login, .. }),
Expand Down
Loading

0 comments on commit e9dfc34

Please sign in to comment.