Skip to content

Commit d114212

Browse files
authored
Merge pull request #1945 from Urgau/issue_links-parent
Handle issue links in parenthesis
2 parents 6a59b44 + 689bce3 commit d114212

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/handlers/check_commits/issue_links.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use regex::Regex;
55
use crate::{config::IssueLinksConfig, github::GithubCommit};
66

77
static LINKED_RE: LazyLock<Regex> =
8-
LazyLock::new(|| Regex::new(r"( |^)([a-zA-Z-_]+/[a-zA-Z-_]+)?(#[0-9]+)\b").unwrap());
8+
LazyLock::new(|| Regex::new(r"\B([a-zA-Z-_]+/[a-zA-Z-_]+)?(#[0-9]+)\b").unwrap());
99

1010
const MERGE_IGNORE_LIST: [&str; 2] = ["Rollup merge of ", "Auto merge of "];
1111

@@ -76,7 +76,7 @@ fn test_mentions_in_commits() {
7676

7777
commits.push(dummy_commit_from_body(
7878
"891f0916a07c215ae8173f782251422f1fea6acb",
79-
"This is a body with a issue link rust-lang/rust#123.",
79+
"This is a body with a issue link (rust-lang/rust#123).",
8080
));
8181

8282
assert_eq!(

src/handlers/issue_links.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::{
1616
};
1717

1818
static LINKED_RE: LazyLock<Regex> =
19-
LazyLock::new(|| Regex::new(r"(?P<start> |^)(?P<issue>#[0-9]+)\b").unwrap());
19+
LazyLock::new(|| Regex::new(r"\B(?P<issue>#[0-9]+)\b").unwrap());
2020

2121
pub(super) struct IssueLinksInput {}
2222

@@ -63,7 +63,7 @@ pub(super) async fn handle_input(
6363
}
6464

6565
fn fix_linked_issues<'a>(body: &'a str, full_repo_name: &str) -> Cow<'a, str> {
66-
let replace_by = format!("${{start}}{full_repo_name}${{issue}}");
66+
let replace_by = format!("{full_repo_name}${{issue}}");
6767
parser::replace_all_outside_ignore_blocks(&LINKED_RE, body, replace_by)
6868
}
6969

@@ -115,6 +115,10 @@ fn edge_case_body() {
115115
fix_linked_issues("#132", full_repo_name),
116116
"rust-lang/rust#132"
117117
);
118+
assert_eq!(
119+
fix_linked_issues("(#132)", full_repo_name),
120+
"(rust-lang/rust#132)"
121+
);
118122
}
119123

120124
#[test]

0 commit comments

Comments
 (0)