diff --git a/kubernetes/processbot/templates/processbot.yaml b/kubernetes/processbot/templates/processbot.yaml index 3643d927..68c3f365 100644 --- a/kubernetes/processbot/templates/processbot.yaml +++ b/kubernetes/processbot/templates/processbot.yaml @@ -78,7 +78,7 @@ spec: - name: RUST_BACKTRACE value: full - name: RUST_LOG - value: debug + value: info - name: INSTALLATION_LOGIN value: {{ .Values.orgName }} - name: PRIVATE_KEY_PATH diff --git a/src/auth.rs b/src/auth.rs index 4c16f573..cda35b38 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -34,11 +34,11 @@ impl GithubUserAuthenticator { Error::OrganizationMembership { source: Box::new(e), } - .map_issue(Some(( + .map_issue(( self.org.clone(), self.repo_name.clone(), self.pr_number, - ))) + )) })?; if !is_member { @@ -50,11 +50,11 @@ impl GithubUserAuthenticator { ), }), } - .map_issue(Some(( + .map_issue(( self.org.clone(), self.repo_name.clone(), self.pr_number, - ))))?; + )))?; } Ok(()) } diff --git a/src/companion.rs b/src/companion.rs index 16748b70..4db36401 100644 --- a/src/companion.rs +++ b/src/companion.rs @@ -2,7 +2,11 @@ use regex::Regex; use snafu::ResultExt; use std::path::Path; -use crate::{cmd::*, error::*, github_bot::GithubBot, Result}; +use crate::{ + cmd::*, error::*, github_bot::GithubBot, Result, COMPANION_LONG_REGEX, + COMPANION_PREFIX_REGEX, COMPANION_SHORT_REGEX, + COMPANION_SHORT_SUFFIX_REGEX, PR_HTML_URL_REGEX, +}; pub async fn companion_update( github_bot: &GithubBot, @@ -236,10 +240,7 @@ pub fn companion_parse(body: &str) -> Option<(String, String, String, i64)> { } fn companion_parse_long(body: &str) -> Option<(String, String, String, i64)> { - let re = Regex::new( - r"companion[^[[:alpha:]]\n]*(?Phttps://github.com/(?P[^/\n]+)/(?P[^/\n]+)/pull/(?P[[:digit:]]+))" - ) - .unwrap(); + let re = Regex::new(COMPANION_LONG_REGEX!()).unwrap(); let caps = re.captures(&body)?; let html_url = caps.name("html_url")?.as_str().to_owned(); let owner = caps.name("owner")?.as_str().to_owned(); @@ -254,10 +255,7 @@ fn companion_parse_long(body: &str) -> Option<(String, String, String, i64)> { } fn companion_parse_short(body: &str) -> Option<(String, String, String, i64)> { - let re = Regex::new( - r"companion[^[[:alpha:]]\n]*(?P[^/\n]+)/(?P[^/\n]+)#(?P[[:digit:]]+)", - ) - .unwrap(); + let re = Regex::new(COMPANION_SHORT_REGEX!()).unwrap(); let caps = re.captures(&body)?; let owner = caps.name("owner")?.as_str().to_owned(); let repo = caps.name("repo")?.as_str().to_owned(); diff --git a/src/error.rs b/src/error.rs index 7911327b..b420aee3 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,6 +1,6 @@ use snafu::Snafu; -type IssueDetails = Option<(String, String, i64)>; +type IssueDetails = (String, String, i64); #[derive(Debug, Snafu)] #[snafu(visibility = "pub")] @@ -11,6 +11,11 @@ pub enum Error { issue: IssueDetails, }, + #[snafu(display("Field is missing: {}", field))] + MissingField { + field: String, + }, + #[snafu(display("Error updating companion: {}", source))] Companion { source: Box, @@ -180,9 +185,12 @@ pub enum Error { impl Error { pub fn map_issue(self, issue: IssueDetails) -> Self { - Self::WithIssue { - source: Box::new(self), - issue: issue, + match self { + Self::WithIssue { source, .. } => Self::WithIssue { source, issue }, + _ => Self::WithIssue { + source: Box::new(self), + issue, + }, } } } diff --git a/src/github.rs b/src/github.rs index c6f2e294..81d4deea 100644 --- a/src/github.rs +++ b/src/github.rs @@ -1,19 +1,7 @@ +use crate::{error::*, Result, PR_HTML_URL_REGEX}; +use regex::Regex; use serde::{Deserialize, Serialize}; - -pub trait GithubIssue { - fn number(&self) -> i64; - fn id(&self) -> i64; - fn html_url(&self) -> &String; - fn user(&self) -> &User; - fn body(&self) -> Option<&String>; - fn title(&self) -> Option<&String>; - fn repository(&self) -> Option<&Repository>; - fn assignee(&self) -> Option<&User>; - fn is_assignee(&self, login: &str) -> bool { - self.assignee() - .map_or(false, |assignee| assignee.login == login) - } -} +use snafu::OptionExt; #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct PullRequest { @@ -33,7 +21,7 @@ pub struct PullRequest { pub state: Option, pub locked: Option, pub title: Option, - pub user: User, + pub user: Option, pub body: Option, pub labels: Vec