sampo-github-action 0.15.4

GitHub Action runner for Sampo CLI (release/publish orchestrator)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
use crate::error::{ActionError, Result};
use sampo_core::format_markdown_list_item;
use sampo_core::types::{
    ChangelogCategory, PackageSpecifier, SpecResolution, format_ambiguity_options,
};
use sampo_core::{
    Config, PublishExtraArgs, PublishOutput, detect_all_dependency_explanations,
    detect_github_repo_slug_with_config, discover_workspace, enrich_changeset_message,
    get_commit_hash_for_path, load_changesets, run_publish as core_publish,
    run_release as core_release, run_stabilize_release as core_stabilize_release,
};
use std::collections::BTreeMap;
use std::path::Path;

fn set_cargo_env_var(value: &str) {
    unsafe {
        std::env::set_var("CARGO_REGISTRY_TOKEN", value);
    }
}

#[derive(Debug)]
pub struct ReleasePlan {
    pub has_changes: bool,
    /// key: canonical identifier, value: (display name, old version, new version)
    pub releases: BTreeMap<String, (String, String, String)>,
}

/// Run sampo release and capture the plan
pub fn capture_release_plan(workspace: &Path) -> Result<ReleasePlan> {
    let release_output =
        core_release(workspace, true).map_err(|e| ActionError::SampoCommandFailed {
            operation: "release-plan".to_string(),
            message: format!("Release plan failed: {}", e),
        })?;

    let has_changes = !release_output.released_packages.is_empty();
    let mut releases: BTreeMap<String, (String, String, String)> = BTreeMap::new();
    if has_changes {
        for pkg in release_output.released_packages {
            releases.insert(pkg.identifier, (pkg.name, pkg.old_version, pkg.new_version));
        }
    }

    Ok(ReleasePlan {
        has_changes,
        releases,
    })
}

/// Execute sampo release
pub fn run_release(workspace: &Path, dry_run: bool, cargo_token: Option<&str>) -> Result<()> {
    // Set cargo token if provided
    if let Some(token) = cargo_token {
        set_cargo_env_var(token);
    }

    core_release(workspace, dry_run).map_err(|e| ActionError::SampoCommandFailed {
        operation: "release".to_string(),
        message: format!("sampo release failed: {}", e),
    })?;

    Ok(())
}

/// Execute sampo publish and return information about created/would-be-created tags
pub fn run_publish(
    workspace: &Path,
    dry_run: bool,
    extra_args: &PublishExtraArgs,
    cargo_token: Option<&str>,
) -> Result<PublishOutput> {
    // Set cargo token if provided
    if let Some(token) = cargo_token {
        set_cargo_env_var(token);
    }

    core_publish(workspace, dry_run, extra_args).map_err(|e| ActionError::SampoCommandFailed {
        operation: "publish".to_string(),
        message: format!("sampo publish failed: {}", e),
    })
}

/// Dry-run stabilize release to compute the stable version plan.
pub fn capture_stabilize_plan(workspace: &Path) -> Result<ReleasePlan> {
    let release_output =
        core_stabilize_release(workspace, true).map_err(|e| ActionError::SampoCommandFailed {
            operation: "stabilize-plan".to_string(),
            message: format!("Stabilize plan failed: {}", e),
        })?;

    let has_changes = !release_output.released_packages.is_empty();
    let mut releases: BTreeMap<String, (String, String, String)> = BTreeMap::new();
    if has_changes {
        for pkg in release_output.released_packages {
            releases.insert(pkg.identifier, (pkg.name, pkg.old_version, pkg.new_version));
        }
    }

    Ok(ReleasePlan {
        has_changes,
        releases,
    })
}

/// Execute stabilize release (prerelease → stable).
pub fn run_stabilize_release(
    workspace: &Path,
    dry_run: bool,
    cargo_token: Option<&str>,
) -> Result<()> {
    if let Some(token) = cargo_token {
        set_cargo_env_var(token);
    }

    core_stabilize_release(workspace, dry_run).map_err(|e| ActionError::SampoCommandFailed {
        operation: "stabilize-release".to_string(),
        message: format!("sampo stabilize release failed: {}", e),
    })?;

    Ok(())
}

/// Compute a markdown PR body summarizing the pending release by crate,
/// grouping changes by semantic bump type, and showing old -> new versions.
///
/// This function builds the PR body using stdout from `sampo release --dry-run`
/// to infer planned crate version changes, and reads changesets for change messages.
///
/// # Arguments
/// * `workspace` - Path to the workspace root
/// * `plan_stdout` - Output from `sampo release --dry-run`
/// * `config` - Configuration reference to use for dependency policies and GitHub settings
///
/// # Returns
/// A formatted markdown string for the PR body, or empty string if no releases are planned
pub fn build_release_pr_body(
    workspace: &Path,
    releases: &BTreeMap<String, (String, String, String)>,
    config: &Config,
) -> Result<String> {
    if releases.is_empty() {
        return Ok(String::new());
    }

    let changesets_dir = workspace.join(".sampo").join("changesets");
    let changesets = load_changesets(&changesets_dir, &config.changesets_tags)?;

    // Load workspace for dependency explanations
    let ws = discover_workspace(workspace).map_err(|e| ActionError::SampoCommandFailed {
        operation: "workspace-discovery".into(),
        message: e.to_string(),
    })?;
    let include_kind = ws.has_multiple_package_kinds();

    // Group messages per canonical package id by category
    let mut messages_by_pkg: BTreeMap<String, Vec<(String, ChangelogCategory)>> = BTreeMap::new();

    // Resolve GitHub slug and token for commit links and acknowledgments
    let repo_slug =
        detect_github_repo_slug_with_config(workspace, config.github_repository.as_deref());
    let github_token = std::env::var("GITHUB_TOKEN")
        .ok()
        .or_else(|| std::env::var("GH_TOKEN").ok());

    for cs in &changesets {
        for (pkg_spec, bump, tag) in &cs.entries {
            let identifier = resolve_specifier_identifier(&ws, pkg_spec)?;
            if releases.contains_key(&identifier) {
                let commit_hash = get_commit_hash_for_path(workspace, &cs.path);
                let enriched = if let Some(hash) = commit_hash {
                    enrich_changeset_message(
                        &cs.message,
                        &hash,
                        workspace,
                        repo_slug.as_deref(),
                        github_token.as_deref(),
                        config.changelog_show_commit_hash,
                        config.changelog_show_acknowledgments,
                    )
                } else {
                    cs.message.clone()
                };
                let category = if let Some(t) = tag {
                    ChangelogCategory::Tag(t.clone())
                } else {
                    ChangelogCategory::Bump(*bump)
                };
                messages_by_pkg
                    .entry(identifier)
                    .or_default()
                    .push((enriched, category));
            }
        }
    }

    // Add automatic dependency explanations using unified function
    let release_lookup: BTreeMap<String, (String, String)> = releases
        .iter()
        .map(|(identifier, (_display, old_version, new_version))| {
            (
                identifier.clone(),
                (old_version.clone(), new_version.clone()),
            )
        })
        .collect();
    let explanations =
        detect_all_dependency_explanations(&changesets, &ws, config, &release_lookup)?;

    // Merge explanations into messages_by_pkg
    for (pkg_name, explanations) in explanations {
        messages_by_pkg
            .entry(pkg_name)
            .or_default()
            .extend(explanations);
    }

    // Compose header
    let mut output = String::new();
    output.push_str("This PR was generated by ");
    output.push_str("[Sampo GitHub Action](https://github.com/bruits/sampo/blob/main/crates/sampo-github-action/README.md).");
    output.push_str(" When you're ready to do a release, you can merge this and the packages will be published automatically. ");
    output.push_str("Not ready yet? Just keep adding changesets to the default branch, and this PR will stay up to date.\n\n");

    // Deterministic crate order by name
    let mut crate_ids: Vec<_> = releases.keys().cloned().collect();
    crate_ids.sort();
    for identifier in crate_ids {
        let (fallback_name, old_version, new_version) = &releases[&identifier];
        let pretty_name = display_label_for_release(&ws, &identifier, include_kind, fallback_name);
        output.push_str(&format!(
            "## {} {} -> {}\n\n",
            pretty_name, old_version, new_version
        ));

        // Collect changes by category
        let mut changes_by_category: BTreeMap<ChangelogCategory, Vec<String>> = BTreeMap::new();

        if let Some(changeset_list) = messages_by_pkg.get(&identifier) {
            // Helper to push without duplicates (preserve append order)
            let push_unique = |list: &mut Vec<String>, msg: &str| {
                if !list.iter().any(|m| m == msg) {
                    list.push(msg.to_string());
                }
            };

            for (message, category) in changeset_list {
                push_unique(
                    changes_by_category.entry(category.clone()).or_default(),
                    message,
                );
            }
        }

        // Sort categories: tags alphabetically first, then bump types by severity
        let mut categories: Vec<_> = changes_by_category.keys().cloned().collect();
        categories.sort_by_key(|c| c.sort_key());

        for category in categories {
            if let Some(changes) = changes_by_category.get(&category) {
                append_changes_section(&mut output, &category.heading(), changes);
            }
        }
    }

    Ok(output)
}

fn resolve_specifier_identifier(
    workspace: &sampo_core::Workspace,
    spec: &PackageSpecifier,
) -> Result<String> {
    match workspace.resolve_specifier(spec) {
        SpecResolution::Match(info) => Ok(info.canonical_identifier().to_string()),
        SpecResolution::NotFound { query } => {
            let error = if let Some(identifier) = query.identifier() {
                sampo_core::errors::SampoError::Changeset(format!(
                    "Changeset references '{}', but it was not found in the workspace.",
                    identifier
                ))
            } else {
                sampo_core::errors::SampoError::Changeset(format!(
                    "Changeset references '{}', but no matching package exists in the workspace.",
                    query.base_name()
                ))
            };
            Err(error.into())
        }
        SpecResolution::Ambiguous { query, matches } => {
            let options = format_ambiguity_options(&matches);
            Err(sampo_core::errors::SampoError::Changeset(format!(
                "Changeset references '{}', which matches multiple packages. Disambiguate using one of: {}.",
                query.base_name(),
                options
            ))
            .into())
        }
    }
}

fn display_label_for_release(
    workspace: &sampo_core::Workspace,
    identifier: &str,
    include_kind: bool,
    fallback: &str,
) -> String {
    if let Some(info) = workspace.find_by_identifier(identifier) {
        return info.display_name(include_kind);
    }
    if let Ok(spec) = PackageSpecifier::parse(identifier) {
        return spec.display_name(include_kind);
    }
    fallback.to_string()
}

/// Append a changes section to the output if the changes list is not empty
fn append_changes_section(output: &mut String, section_title: &str, changes: &[String]) {
    if !changes.is_empty() {
        output.push_str(&format!("### {}\n\n", section_title));
        for change in changes {
            output.push_str(&format_markdown_list_item(change));
        }
        output.push('\n');
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::sync::{Mutex, MutexGuard, OnceLock};

    static ENV_MUTEX: OnceLock<Mutex<()>> = OnceLock::new();

    fn env_lock() -> &'static Mutex<()> {
        ENV_MUTEX.get_or_init(|| Mutex::new(()))
    }

    struct EnvVarGuard {
        key: &'static str,
        original: Option<String>,
        _lock: MutexGuard<'static, ()>,
    }

    impl EnvVarGuard {
        fn set_branch(value: &str) -> Self {
            let key = "SAMPO_RELEASE_BRANCH";
            let lock = env_lock().lock().unwrap();
            let original = std::env::var(key).ok();
            unsafe {
                std::env::set_var(key, value);
            }
            Self {
                key,
                original,
                _lock: lock,
            }
        }
    }

    impl Drop for EnvVarGuard {
        fn drop(&mut self) {
            unsafe {
                if let Some(ref value) = self.original {
                    std::env::set_var(self.key, value);
                } else {
                    std::env::remove_var(self.key);
                }
            }
        }
    }

    #[test]
    fn test_append_changes_section() {
        let mut output = String::new();
        let changes = vec!["Fix bug A".to_string(), "Add feature B".to_string()];

        append_changes_section(&mut output, "Major changes", &changes);

        let expected = "### Major changes\n\n- Fix bug A\n- Add feature B\n\n";
        assert_eq!(output, expected);
    }

    #[test]
    fn test_append_changes_section_empty() {
        let mut output = String::new();
        let changes: Vec<String> = vec![];

        append_changes_section(&mut output, "Major changes", &changes);

        assert_eq!(output, "");
    }

    #[test]
    fn test_append_changes_section_multiline_with_nested_list() {
        let mut output = String::new();
        let changes = vec!["feat: big change with details\n- add A\n- add B".to_string()];

        append_changes_section(&mut output, "Minor changes", &changes);

        let expected =
            "### Minor changes\n\n- feat: big change with details\n  - add A\n  - add B\n\n";
        assert_eq!(output, expected);
    }

    #[test]
    fn test_no_duplicate_messages_in_changelog() {
        // Test that duplicate messages are filtered out properly
        let mut major_changes: Vec<String> = Vec::new();

        // Helper function that mimics the one used in build_release_pr_body_from_stdout
        let push_unique = |list: &mut Vec<String>, msg: &str| {
            if !list.iter().any(|m| m == msg) {
                list.push(msg.to_string());
            }
        };

        // Simulate adding the same message multiple times
        push_unique(&mut major_changes, "Fix critical bug");
        push_unique(&mut major_changes, "Fix critical bug"); // duplicate
        push_unique(&mut major_changes, "Add new feature");
        push_unique(&mut major_changes, "Fix critical bug"); // another duplicate

        // Should only have 2 unique messages
        assert_eq!(major_changes.len(), 2);
        assert_eq!(major_changes, vec!["Fix critical bug", "Add new feature"]);
    }

    #[test]
    fn test_dependency_updates_in_pr_body() {
        let _branch = EnvVarGuard::set_branch("main");
        use std::fs;
        let temp = tempfile::tempdir().unwrap();
        let root = temp.path();

        // Create workspace structure
        fs::write(
            root.join("Cargo.toml"),
            "[workspace]\nmembers=[\"crates/*\"]\n",
        )
        .unwrap();

        let a_dir = root.join("crates/a");
        let b_dir = root.join("crates/b");
        fs::create_dir_all(&a_dir).unwrap();
        fs::create_dir_all(&b_dir).unwrap();

        fs::write(
            b_dir.join("Cargo.toml"),
            "[package]\nname=\"b\"\nversion=\"0.1.0\"\n",
        )
        .unwrap();

        // a depends on b
        fs::write(
            a_dir.join("Cargo.toml"),
            "[package]\nname=\"a\"\nversion=\"0.1.0\"\n\n[dependencies]\nb = { path=\"../b\", version=\"0.1.0\" }\n",
        )
        .unwrap();

        // Create a changeset that only affects b
        let csdir = root.join(".sampo/changesets");
        fs::create_dir_all(&csdir).unwrap();
        fs::write(
            csdir.join("b-minor.md"),
            "---\nb: minor\n---\n\nfeat: b adds new feature\n",
        )
        .unwrap();

        // Compute the release plan using core logic (structured)
        let plan = capture_release_plan(root).unwrap();
        assert!(plan.has_changes);
        let config = Config::default();
        let pr_body = build_release_pr_body(root, &plan.releases, &config).unwrap();

        // Should contain dependency update information for package a
        assert!(pr_body.contains("## a 0.1.0 -> 0.1.1"));
        assert!(pr_body.contains("## b 0.1.0 -> 0.2.0"));
        assert!(pr_body.contains("feat: b adds new feature"));
        assert!(pr_body.contains("Updated dependencies: b@0.2.0"));
    }

    #[test]
    fn test_fixed_dependencies_in_pr_body() {
        let _branch = EnvVarGuard::set_branch("main");
        use std::fs;
        let temp = tempfile::tempdir().unwrap();
        let root = temp.path();

        // Create workspace structure
        fs::write(
            root.join("Cargo.toml"),
            "[workspace]\nmembers=[\"crates/*\"]\n",
        )
        .unwrap();

        let a_dir = root.join("crates/a");
        let b_dir = root.join("crates/b");
        fs::create_dir_all(&a_dir).unwrap();
        fs::create_dir_all(&b_dir).unwrap();

        fs::write(
            b_dir.join("Cargo.toml"),
            "[package]\nname=\"b\"\nversion=\"1.0.0\"\n",
        )
        .unwrap();

        // a depends on b
        fs::write(
            a_dir.join("Cargo.toml"),
            "[package]\nname=\"a\"\nversion=\"1.0.0\"\n\n[dependencies]\nb = { path=\"../b\", version=\"1.0.0\" }\n",
        )
        .unwrap();

        // Create sampo config with fixed dependencies
        let sampo_dir = root.join(".sampo");
        fs::create_dir_all(&sampo_dir).unwrap();
        fs::write(
            sampo_dir.join("config.toml"),
            "[packages]\nfixed = [[\"a\", \"b\"]]\n",
        )
        .unwrap();

        // Create a changeset that only affects b
        let csdir = root.join(".sampo/changesets");
        fs::create_dir_all(&csdir).unwrap();
        fs::write(
            csdir.join("b-major.md"),
            "---\nb: major\n---\n\nbreaking: b breaking change\n",
        )
        .unwrap();

        // Compute the plan using core logic and the fixed dependency config
        let plan = capture_release_plan(root).unwrap();
        assert!(plan.has_changes);
        let config = Config::load(root).unwrap();
        let pr_body = build_release_pr_body(root, &plan.releases, &config).unwrap();

        // Should contain information for both packages with same version
        assert!(pr_body.contains("## a 1.0.0 -> 2.0.0"));
        assert!(pr_body.contains("## b 1.0.0 -> 2.0.0"));
        assert!(pr_body.contains("breaking: b breaking change"));
        // Fixed dependency should show dependency update too
        assert!(pr_body.contains("Updated dependencies: b@2.0.0"));
    }

    #[test]
    fn test_fixed_dependencies_without_actual_dependency() {
        let _branch = EnvVarGuard::set_branch("main");
        use std::fs;
        let temp = tempfile::tempdir().unwrap();
        let root = temp.path();

        // Create workspace structure
        fs::write(
            root.join("Cargo.toml"),
            "[workspace]\nmembers=[\"crates/*\"]\n",
        )
        .unwrap();

        let a_dir = root.join("crates/a");
        let b_dir = root.join("crates/b");
        fs::create_dir_all(&a_dir).unwrap();
        fs::create_dir_all(&b_dir).unwrap();

        fs::write(
            b_dir.join("Cargo.toml"),
            "[package]\nname=\"b\"\nversion=\"1.0.0\"\n",
        )
        .unwrap();

        // a does NOT depend on b (important difference)
        fs::write(
            a_dir.join("Cargo.toml"),
            "[package]\nname=\"a\"\nversion=\"1.0.0\"\n",
        )
        .unwrap();

        // Create sampo config with fixed dependencies
        let sampo_dir = root.join(".sampo");
        fs::create_dir_all(&sampo_dir).unwrap();
        fs::write(
            sampo_dir.join("config.toml"),
            "[packages]\nfixed = [[\"a\", \"b\"]]\n",
        )
        .unwrap();

        // Create a changeset that only affects b
        let csdir = root.join(".sampo/changesets");
        fs::create_dir_all(&csdir).unwrap();
        fs::write(
            csdir.join("b-major.md"),
            "---\nb: major\n---\n\nbreaking: b breaking change\n",
        )
        .unwrap();

        // Compute the plan using core logic and the fixed dependency config
        let plan = capture_release_plan(root).unwrap();
        assert!(plan.has_changes);
        let config = Config::load(root).unwrap();
        let pr_body = build_release_pr_body(root, &plan.releases, &config).unwrap();

        println!("PR Body:\n{}", pr_body);

        // Should contain information for both packages with same version
        assert!(pr_body.contains("## a 1.0.0 -> 2.0.0"));
        assert!(pr_body.contains("## b 1.0.0 -> 2.0.0"));
        assert!(pr_body.contains("breaking: b breaking change"));

        // FIXED: Package 'a' should now have an explanation for the bump!
        assert!(pr_body.contains("Bumped due to fixed dependency group policy"));
    }

    #[test]
    fn test_capture_plan_and_pr_body_end_to_end() {
        let _branch = EnvVarGuard::set_branch("main");
        use std::fs;
        // Setup a minimal workspace with one crate and a minor changeset
        let temp = tempfile::tempdir().unwrap();
        let root = temp.path();

        // Workspace root
        fs::write(
            root.join("Cargo.toml"),
            "[workspace]\nmembers=[\"crates/*\"]\n",
        )
        .unwrap();

        // Single crate 'example' v0.1.0
        let ex_dir = root.join("crates/example");
        fs::create_dir_all(&ex_dir).unwrap();
        fs::write(
            ex_dir.join("Cargo.toml"),
            "[package]\nname=\"example\"\nversion=\"0.1.0\"\n",
        )
        .unwrap();

        // Changeset: example minor change
        let cs_dir = root.join(".sampo/changesets");
        fs::create_dir_all(&cs_dir).unwrap();
        fs::write(
            cs_dir.join("example-minor.md"),
            "---\nexample: minor\n---\n\nfeat: add new thing\n",
        )
        .unwrap();

        // Capture release plan (dry-run) using core logic
        let plan = capture_release_plan(root).expect("plan should succeed");
        assert!(plan.has_changes);
        assert_eq!(
            plan.releases.get("cargo/example"),
            Some(&(
                "example".to_string(),
                "0.1.0".to_string(),
                "0.2.0".to_string()
            ))
        );

        // Build PR body from the structured plan
        let config = Config::load(root).unwrap_or_default();
        let pr_body = build_release_pr_body(root, &plan.releases, &config).unwrap();

        // Ensure PR body uses the changelog layout
        assert!(pr_body.contains("## example 0.1.0 -> 0.2.0"));
        assert!(pr_body.contains("### Minor changes"));
        assert!(pr_body.contains("- feat: add new thing"));
    }
}