Skip to content
This repository was archived by the owner on Oct 11, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/companion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
wait_to_merge, AppState, MergeRequest,
},
MergeAllowedOutcome, Result, COMPANION_LONG_REGEX, COMPANION_PREFIX_REGEX,
COMPANION_SHORT_REGEX, PR_HTML_URL_REGEX,
COMPANION_SHORT_REGEX, OWNER_AND_REPO_SEQUENCE, PR_HTML_URL_REGEX,
};

async fn update_companion_repository(
Expand Down Expand Up @@ -808,4 +808,20 @@ mod tests {
vec![]
);
}

#[test]
fn test_restricted_regex() {
let owner = "paritytech";
let repo = "polkadot";
let pr_number = 1234;
let companion_url = format!("{}/{}#{}", owner, repo, pr_number);
assert_eq!(
parse_all_companions(
&[],
// the companion expression should not be matched because of the " for" part
&format!("companion for {}", &companion_url)
),
vec![]
);
}
}
2 changes: 1 addition & 1 deletion src/github.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
companion::parse_all_companions, error::*,
utils::parse_bot_comment_from_text, webhook::MergeRequestBase,
PlaceholderDeserializationItem, PR_HTML_URL_REGEX,
PlaceholderDeserializationItem, OWNER_AND_REPO_SEQUENCE, PR_HTML_URL_REGEX,
};
use regex::Regex;
use serde::{Deserialize, Serialize};
Expand Down
20 changes: 16 additions & 4 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
#[macro_export]
macro_rules! OWNER_AND_REPO_SEQUENCE {
() => {
r"(?P<owner>[^ \t\n]+)/(?P<repo>[^ \t\n]+)"
};
}

#[macro_export]
macro_rules! PR_HTML_URL_REGEX {
() => {
r"(?P<html_url>https://[^/\n]+/(?P<owner>[^/\n]+)/(?P<repo>[^/\n]+)/pull/(?P<number>[[:digit:]]+))"
};
() => {
concat!(
r"(?P<html_url>https://[^ \t\n]+/",
OWNER_AND_REPO_SEQUENCE!(),
r"/pull/(?P<number>[[:digit:]]+))"
)
};
}

#[macro_export]
Expand All @@ -24,7 +35,8 @@ macro_rules! COMPANION_SHORT_REGEX {
() => {
concat!(
COMPANION_PREFIX_REGEX!(),
r"(?P<owner>[^/\n]+)/(?P<repo>[^/\n]+)#(?P<number>[[:digit:]]+)"
OWNER_AND_REPO_SEQUENCE!(),
r"#(?P<number>[[:digit:]]+)"
)
};
}
Expand Down