From a0946d7374bc4989edc15a2d560f7c106953ad3e Mon Sep 17 00:00:00 2001 From: Urgau Date: Sun, 4 May 2025 11:35:18 +0200 Subject: [PATCH] Add option to disable checking issue links in commits --- src/config.rs | 23 ++++++++++++++++++----- src/handlers/check_commits/issue_links.rs | 20 ++++++++++++++++++-- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/config.rs b/src/config.rs index 310cc2afe..4ef211e58 100644 --- a/src/config.rs +++ b/src/config.rs @@ -465,7 +465,10 @@ pub(crate) struct RenderedLinkConfig { #[derive(PartialEq, Eq, Debug, serde::Deserialize)] #[serde(rename_all = "kebab-case")] #[serde(deny_unknown_fields)] -pub(crate) struct IssueLinksConfig {} +pub(crate) struct IssueLinksConfig { + #[serde(default = "default_true")] + pub(crate) check_commits: bool, +} #[derive(PartialEq, Eq, Debug, serde::Deserialize)] #[serde(rename_all = "kebab-case")] @@ -482,6 +485,11 @@ pub(crate) struct BehindUpstreamConfig { pub(crate) days_threshold: Option, } +#[inline] +fn default_true() -> bool { + true +} + fn get_cached_config(repo: &str) -> Option, ConfigurationError>> { let cache = CONFIG_CACHE.read().unwrap(); cache.get(repo).and_then(|(config, fetch_time)| { @@ -603,7 +611,7 @@ mod tests { [shortcut] - [canonicalize-issue-links] + [issue-links] [rendered-link] trigger-files = ["posts/"] @@ -674,7 +682,9 @@ mod tests { rendered_link: Some(RenderedLinkConfig { trigger_files: vec!["posts/".to_string()] }), - issue_links: Some(IssueLinksConfig {}), + issue_links: Some(IssueLinksConfig { + check_commits: true, + }), no_mentions: Some(NoMentionsConfig {}), behind_upstream: Some(BehindUpstreamConfig { days_threshold: Some(14), @@ -697,7 +707,8 @@ mod tests { title = "[stable" branch = "stable" - [canonicalize-issue-links] + [issue-links] + check-commits = false [behind-upstream] days-threshold = 7 @@ -747,7 +758,9 @@ mod tests { merge_conflicts: None, bot_pull_requests: None, rendered_link: None, - issue_links: Some(IssueLinksConfig {}), + issue_links: Some(IssueLinksConfig { + check_commits: false, + }), no_mentions: None, behind_upstream: Some(BehindUpstreamConfig { days_threshold: Some(7), diff --git a/src/handlers/check_commits/issue_links.rs b/src/handlers/check_commits/issue_links.rs index 4d2b91a73..70f549787 100644 --- a/src/handlers/check_commits/issue_links.rs +++ b/src/handlers/check_commits/issue_links.rs @@ -10,9 +10,13 @@ static LINKED_RE: LazyLock = const MERGE_IGNORE_LIST: [&str; 3] = ["Rollup merge of ", "Auto merge of ", "Merge pull request "]; pub(super) fn issue_links_in_commits( - _conf: &IssueLinksConfig, + conf: &IssueLinksConfig, commits: &[GithubCommit], ) -> Option { + if !conf.check_commits { + return None; + } + let issue_links_commits = commits .into_iter() .filter(|c| { @@ -39,7 +43,9 @@ pub(super) fn issue_links_in_commits( fn test_mentions_in_commits() { use super::dummy_commit_from_body; - let config = IssueLinksConfig {}; + let config = IssueLinksConfig { + check_commits: true, + }; let mut commits = vec![dummy_commit_from_body( "d1992a392617dfb10518c3e56446b6c9efae38b0", @@ -78,6 +84,16 @@ fn test_mentions_in_commits() { ) ); + assert_eq!( + issue_links_in_commits( + &IssueLinksConfig { + check_commits: false, + }, + &commits + ), + None + ); + commits.push(dummy_commit_from_body( "891f0916a07c215ae8173f782251422f1fea6acb", "This is a body with a issue link (rust-lang/rust#123).",