Skip to content

Commit 05aa65d

Browse files
authored
Merge pull request #1966 from Urgau/issue_links-allowed-in-commits
Add option to disable checking issue links in commits
2 parents bbdda31 + a0946d7 commit 05aa65d

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

src/config.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,10 @@ pub(crate) struct RenderedLinkConfig {
465465
#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
466466
#[serde(rename_all = "kebab-case")]
467467
#[serde(deny_unknown_fields)]
468-
pub(crate) struct IssueLinksConfig {}
468+
pub(crate) struct IssueLinksConfig {
469+
#[serde(default = "default_true")]
470+
pub(crate) check_commits: bool,
471+
}
469472

470473
#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
471474
#[serde(rename_all = "kebab-case")]
@@ -482,6 +485,11 @@ pub(crate) struct BehindUpstreamConfig {
482485
pub(crate) days_threshold: Option<usize>,
483486
}
484487

488+
#[inline]
489+
fn default_true() -> bool {
490+
true
491+
}
492+
485493
fn get_cached_config(repo: &str) -> Option<Result<Arc<Config>, ConfigurationError>> {
486494
let cache = CONFIG_CACHE.read().unwrap();
487495
cache.get(repo).and_then(|(config, fetch_time)| {
@@ -603,7 +611,7 @@ mod tests {
603611
604612
[shortcut]
605613
606-
[canonicalize-issue-links]
614+
[issue-links]
607615
608616
[rendered-link]
609617
trigger-files = ["posts/"]
@@ -674,7 +682,9 @@ mod tests {
674682
rendered_link: Some(RenderedLinkConfig {
675683
trigger_files: vec!["posts/".to_string()]
676684
}),
677-
issue_links: Some(IssueLinksConfig {}),
685+
issue_links: Some(IssueLinksConfig {
686+
check_commits: true,
687+
}),
678688
no_mentions: Some(NoMentionsConfig {}),
679689
behind_upstream: Some(BehindUpstreamConfig {
680690
days_threshold: Some(14),
@@ -697,7 +707,8 @@ mod tests {
697707
title = "[stable"
698708
branch = "stable"
699709
700-
[canonicalize-issue-links]
710+
[issue-links]
711+
check-commits = false
701712
702713
[behind-upstream]
703714
days-threshold = 7
@@ -747,7 +758,9 @@ mod tests {
747758
merge_conflicts: None,
748759
bot_pull_requests: None,
749760
rendered_link: None,
750-
issue_links: Some(IssueLinksConfig {}),
761+
issue_links: Some(IssueLinksConfig {
762+
check_commits: false,
763+
}),
751764
no_mentions: None,
752765
behind_upstream: Some(BehindUpstreamConfig {
753766
days_threshold: Some(7),

src/handlers/check_commits/issue_links.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ static LINKED_RE: LazyLock<Regex> =
1010
const MERGE_IGNORE_LIST: [&str; 3] = ["Rollup merge of ", "Auto merge of ", "Merge pull request "];
1111

1212
pub(super) fn issue_links_in_commits(
13-
_conf: &IssueLinksConfig,
13+
conf: &IssueLinksConfig,
1414
commits: &[GithubCommit],
1515
) -> Option<String> {
16+
if !conf.check_commits {
17+
return None;
18+
}
19+
1620
let issue_links_commits = commits
1721
.into_iter()
1822
.filter(|c| {
@@ -39,7 +43,9 @@ pub(super) fn issue_links_in_commits(
3943
fn test_mentions_in_commits() {
4044
use super::dummy_commit_from_body;
4145

42-
let config = IssueLinksConfig {};
46+
let config = IssueLinksConfig {
47+
check_commits: true,
48+
};
4349

4450
let mut commits = vec![dummy_commit_from_body(
4551
"d1992a392617dfb10518c3e56446b6c9efae38b0",
@@ -78,6 +84,16 @@ fn test_mentions_in_commits() {
7884
)
7985
);
8086

87+
assert_eq!(
88+
issue_links_in_commits(
89+
&IssueLinksConfig {
90+
check_commits: false,
91+
},
92+
&commits
93+
),
94+
None
95+
);
96+
8197
commits.push(dummy_commit_from_body(
8298
"891f0916a07c215ae8173f782251422f1fea6acb",
8399
"This is a body with a issue link (rust-lang/rust#123).",

0 commit comments

Comments
 (0)