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

Commit

Permalink
ignore comments from bots & improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
joao-paulo-parity committed Mar 25, 2021
1 parent efe78da commit 585f777
Show file tree
Hide file tree
Showing 8 changed files with 486 additions and 453 deletions.
2 changes: 1 addition & 1 deletion kubernetes/processbot/templates/processbot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -50,11 +50,11 @@ impl GithubUserAuthenticator {
),
}),
}
.map_issue(Some((
.map_issue((
self.org.clone(),
self.repo_name.clone(),
self.pr_number,
))))?;
)))?;
}
Ok(())
}
Expand Down
16 changes: 7 additions & 9 deletions src/companion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]*(?P<html_url>https://github.com/(?P<owner>[^/\n]+)/(?P<repo>[^/\n]+)/pull/(?P<number>[[: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();
Expand All @@ -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<owner>[^/\n]+)/(?P<repo>[^/\n]+)#(?P<number>[[: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();
Expand Down
16 changes: 12 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use snafu::Snafu;

type IssueDetails = Option<(String, String, i64)>;
type IssueDetails = (String, String, i64);

#[derive(Debug, Snafu)]
#[snafu(visibility = "pub")]
Expand All @@ -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<Error>,
Expand Down Expand Up @@ -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,
},
}
}
}
Expand Down
Loading

0 comments on commit 585f777

Please sign in to comment.