diff --git a/src/core/engine/pull_request_generator/mod.rs b/src/core/engine/pull_request_generator/mod.rs index 5baf9ea..e3f12bc 100644 --- a/src/core/engine/pull_request_generator/mod.rs +++ b/src/core/engine/pull_request_generator/mod.rs @@ -306,7 +306,7 @@ impl PullRequestGenerator for DefaultPullRequestGenerator { let mut body = String::new(); for section in sections { - if let Ok(Some(content)) = section.generate(&ctx).await { + if let Ok(Some(content)) = section.generate(&ctx, body.len()).await { body.push_str(&content); } } diff --git a/src/core/engine/pull_request_generator/sections/advisories.rs b/src/core/engine/pull_request_generator/sections/advisories.rs index b03f964..5cdbd99 100644 --- a/src/core/engine/pull_request_generator/sections/advisories.rs +++ b/src/core/engine/pull_request_generator/sections/advisories.rs @@ -8,7 +8,11 @@ pub struct AdvisoriesSection; #[async_trait] impl PullRequestSectionGenerator for AdvisoriesSection { - async fn generate(&self, ctx: &PullRequestGenerationContext<'_>) -> Result> { + async fn generate( + &self, + ctx: &PullRequestGenerationContext<'_>, + _current_length: usize, + ) -> Result> { let mut advisories_md = String::new(); let mut seen_advisories = std::collections::HashSet::new(); diff --git a/src/core/engine/pull_request_generator/sections/history.rs b/src/core/engine/pull_request_generator/sections/history.rs index ad8b7e4..d84a136 100644 --- a/src/core/engine/pull_request_generator/sections/history.rs +++ b/src/core/engine/pull_request_generator/sections/history.rs @@ -32,7 +32,11 @@ impl HistorySection { #[async_trait] impl PullRequestSectionGenerator for HistorySection { - async fn generate(&self, ctx: &PullRequestGenerationContext<'_>) -> Result> { + async fn generate( + &self, + ctx: &PullRequestGenerationContext<'_>, + base_length: usize, + ) -> Result> { let targets = ctx.targets; if targets.is_empty() { return Ok(None); @@ -188,8 +192,6 @@ impl PullRequestSectionGenerator for HistorySection { let notes_results = futures::future::join_all(notes_futures).await; - let mut current_length = body.len(); - for (release, notes_res) in history_to_process .into_iter() .zip(notes_results.into_iter()) @@ -244,7 +246,7 @@ impl PullRequestSectionGenerator for HistorySection { body.push_str(&format!("## {}\n{}\n\n", release.version, time_str)); } - if current_length > 60_000 { + if base_length + body.len() > 60_000 { if !repo_url.is_empty() && repo_url.contains("github.com") { let github_url = format!("{}/releases/tag/{}", repo_url, encoded_tag); body.push_str(&format!("> *Changelog truncated due to GitHub PR size limits. [View release notes on GitHub]({})*\n\n", github_url)); @@ -253,13 +255,12 @@ impl PullRequestSectionGenerator for HistorySection { "> *Changelog truncated due to GitHub PR size limits.*\n\n", ); } - continue; + return Ok(Some(body)); } if let Some(md) = fetched_md { body.push_str(&md); body.push_str("\n\n"); - current_length = body.len(); } } } diff --git a/src/core/engine/pull_request_generator/sections/mod.rs b/src/core/engine/pull_request_generator/sections/mod.rs index 0f4bfc4..7347ca9 100644 --- a/src/core/engine/pull_request_generator/sections/mod.rs +++ b/src/core/engine/pull_request_generator/sections/mod.rs @@ -10,5 +10,9 @@ pub mod summary; #[async_trait] pub trait PullRequestSectionGenerator: Send + Sync { - async fn generate(&self, ctx: &PullRequestGenerationContext<'_>) -> Result>; + async fn generate( + &self, + ctx: &PullRequestGenerationContext<'_>, + current_length: usize, + ) -> Result>; } diff --git a/src/core/engine/pull_request_generator/sections/policy.rs b/src/core/engine/pull_request_generator/sections/policy.rs index 275fb3f..5ecb949 100644 --- a/src/core/engine/pull_request_generator/sections/policy.rs +++ b/src/core/engine/pull_request_generator/sections/policy.rs @@ -8,7 +8,11 @@ pub struct PolicySection; #[async_trait] impl PullRequestSectionGenerator for PolicySection { - async fn generate(&self, ctx: &PullRequestGenerationContext<'_>) -> Result> { + async fn generate( + &self, + ctx: &PullRequestGenerationContext<'_>, + _current_length: usize, + ) -> Result> { let targets = ctx.targets; let mut body = String::new(); diff --git a/src/core/engine/pull_request_generator/sections/summary.rs b/src/core/engine/pull_request_generator/sections/summary.rs index 3c9bd68..0620fe9 100644 --- a/src/core/engine/pull_request_generator/sections/summary.rs +++ b/src/core/engine/pull_request_generator/sections/summary.rs @@ -8,7 +8,11 @@ pub struct SummarySection; #[async_trait] impl PullRequestSectionGenerator for SummarySection { - async fn generate(&self, ctx: &PullRequestGenerationContext<'_>) -> Result> { + async fn generate( + &self, + ctx: &PullRequestGenerationContext<'_>, + _current_length: usize, + ) -> Result> { let targets = ctx.targets; let ecosystem = ctx.ecosystem; let package_group = ctx.package_group;