Skip to content

changelogs: Add --plan flag to changelog bundle#3028

Merged
cotti merged 11 commits intomainfrom
feature/changelog-bundle-plan
Apr 7, 2026
Merged

changelogs: Add --plan flag to changelog bundle#3028
cotti merged 11 commits intomainfrom
feature/changelog-bundle-plan

Conversation

@cotti
Copy link
Copy Markdown
Contributor

@cotti cotti commented Apr 2, 2026

Dependency of elastic/docs-actions#42

This pull request adds a new --plan mode to the changelog bundling CLI and supporting code, allowing CI actions to determine required Docker flags, network access, and output paths before actually generating the bundle. The implementation includes a new planning method, structured result type, CLI wiring, and comprehensive tests.

The most important changes are:

New Planning Feature:

  • Added a --plan option to the CLI, documented in docs/cli/changelog/bundle.md, which outputs a structured set of CI step outputs describing Docker flags, network requirements, and the resolved output path, then exits without generating the bundle.
  • Introduced a new BundlePlanResult record type to represent the plan output, and implemented the PlanBundleAsync method in ChangelogBundlingService to resolve plan details from config/profile metadata without executing network calls or file scanning. [1] [2]

CLI and Service Integration:

  • Updated the Bundle command in ChangelogCommand.cs to support the --plan flag, wiring it to call the new planning method and emit outputs for CI consumption. [1] [2] [3] [4] [5]

Testing:

  • Added a new test suite BundlePlanTests to verify plan output logic for various config and profile scenarios, including output path resolution, network requirements, and error handling.

@cotti cotti self-assigned this Apr 2, 2026
@cotti cotti added the feature label Apr 2, 2026
@cotti cotti requested review from a team as code owners April 2, 2026 22:21
@cotti cotti requested a review from reakaleek April 2, 2026 22:21
@coderabbitai coderabbitai bot added documentation Improvements or additions to documentation and removed feature labels Apr 2, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a --plan option to changelog bundle that computes bundle metadata without performing bundling. Introduces ChangelogBundlingService.PlanBundleAsync(...), which conditionally loads changelog configuration (profile or standard), determines NeedsNetwork and NeedsGithubToken (e.g., when a profile source is github_release), and resolves the expected OutputPath. In plan mode the CLI emits structured outputs (GitHub Actions outputs when running in GH Actions or writes to stdout otherwise) and exits with code 0. Tests and documentation were added/updated for the new behavior.

Sequence Diagram(s)

sequenceDiagram
    participant User as User/CLI
    participant Cmd as ChangelogCommand
    participant Svc as ChangelogBundlingService
    participant Config as Configuration Loader
    participant GH as GitHub Actions Outputs

    User->>Cmd: Run `changelog bundle --plan`
    activate Cmd
    Cmd->>Svc: PlanBundleAsync(collector, args, hasReleaseVersion, ctx)
    activate Svc
    Svc->>Config: Load changelog configuration (profile or standard) if needed
    activate Config
    Config-->>Svc: Return configuration / profile metadata
    deactivate Config
    Svc->>Svc: Evaluate NeedsNetwork / NeedsGithubToken (e.g., github_release)
    Svc->>Svc: Compute OutputPath (profile templates or defaults)
    Svc-->>Cmd: Return BundlePlanResult{NeedsNetwork, NeedsGithubToken, OutputPath}
    deactivate Svc
    Cmd->>GH: Set outputs (needs_network, needs_github_token, output_path) or write to stdout
    Cmd-->>User: Exit (no bundle created)
    deactivate Cmd
Loading
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main feature addition: a new --plan flag for the changelog bundle command.
Description check ✅ Passed The description is well-structured, explains the purpose of the changes, identifies key components affected, and relates directly to the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feature/changelog-bundle-plan

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/Elastic.Changelog.Tests/Changelogs/BundlePlanTests.cs (1)

161-185: Misleading test name.

The test is named Plan_ProfileNotFound_ReturnsNull but asserts result.Should().NotBeNull(). Consider renaming to Plan_ProfileNotFound_ReturnsResultWithNoNetworkRequirement to match the actual behavior being tested.

Suggested rename
 [Fact]
-public async Task Plan_ProfileNotFound_ReturnsNull()
+public async Task Plan_ProfileNotFound_ReturnsResultWithNoNetworkRequirement()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/Elastic.Changelog.Tests/Changelogs/BundlePlanTests.cs` around lines 161
- 185, Rename the misleading test method Plan_ProfileNotFound_ReturnsNull to
reflect its assertions (e.g.,
Plan_ProfileNotFound_ReturnsResultWithNoNetworkRequirement); update the method
name declaration in the BundlePlanTests class and any references to it so the
test name matches the behavior being asserted (result is not null and
NeedsNetwork is false) when calling Service.PlanBundleAsync with a nonexistent
profile via the BundleChangelogsArguments instance.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/Elastic.Changelog.Tests/Changelogs/BundlePlanTests.cs`:
- Around line 161-185: Rename the misleading test method
Plan_ProfileNotFound_ReturnsNull to reflect its assertions (e.g.,
Plan_ProfileNotFound_ReturnsResultWithNoNetworkRequirement); update the method
name declaration in the BundlePlanTests class and any references to it so the
test name matches the behavior being asserted (result is not null and
NeedsNetwork is false) when calling Service.PlanBundleAsync with a nonexistent
profile via the BundleChangelogsArguments instance.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2b7a7b5c-1c2b-4521-b5f4-5f5005869e03

📥 Commits

Reviewing files that changed from the base of the PR and between c4473c9 and 7e1be03.

📒 Files selected for processing (4)
  • docs/cli/changelog/bundle.md
  • src/services/Elastic.Changelog/Bundling/ChangelogBundlingService.cs
  • src/tooling/docs-builder/Commands/ChangelogCommand.cs
  • tests/Elastic.Changelog.Tests/Changelogs/BundlePlanTests.cs

@coderabbitai coderabbitai bot added feature and removed documentation Improvements or additions to documentation labels Apr 2, 2026
Copy link
Copy Markdown
Contributor

@lcawl lcawl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc updates LGTM

@coderabbitai coderabbitai bot added documentation Improvements or additions to documentation and removed feature labels Apr 7, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/tooling/docs-builder/Commands/ChangelogCommand.cs`:
- Around line 506-507: The XML documentation for the Bundle method mentions
parameters sanitizePrivateLinks and noSanitizePrivateLinks that don't exist;
update the Bundle method signature or the docs so they match: either add bool?
sanitizePrivateLinks and bool? noSanitizePrivateLinks parameters to the Bundle
method (and propagate their use to bundle-time sanitization logic and any
callers), or remove the two <param> XML entries from the Bundle method's
docblock so the docs reflect the actual signature; locate the Bundle method and
its XML comments by the method name Bundle to apply the fix.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 57f3dc19-7cad-4c86-901f-6969fb23aaed

📥 Commits

Reviewing files that changed from the base of the PR and between 91aae3c and 517d4f0.

📒 Files selected for processing (3)
  • docs/cli/changelog/bundle.md
  • src/services/Elastic.Changelog/Bundling/ChangelogBundlingService.cs
  • src/tooling/docs-builder/Commands/ChangelogCommand.cs

@coderabbitai coderabbitai bot added feature and removed documentation Improvements or additions to documentation labels Apr 7, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/tooling/docs-builder/Commands/ChangelogCommand.cs`:
- Around line 505-506: The XML doc for the "plan" parameter is incorrect: it
says "Output a structured JSON plan" but the implementation in ChangelogCommand
uses SetOutputAsync to emit GitHub Actions outputs (e.g., "needs_network",
"needs_github_token", "output_path"); update the <param name="plan"> summary to
describe that the command emits GitHub Actions outputs (names of outputs and
purpose) and exits without generating the bundle, or alternately note that it
writes a structured JSON to an output variable only if behavior changes;
reference the ChangelogCommand implementation and SetOutputAsync and the output
keys ("needs_network", "needs_github_token", "output_path") when editing the XML
doc.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 37c9fda3-2e15-4413-998e-7fc1e757caf4

📥 Commits

Reviewing files that changed from the base of the PR and between 517d4f0 and 6fd6393.

📒 Files selected for processing (1)
  • src/tooling/docs-builder/Commands/ChangelogCommand.cs

Copy link
Copy Markdown
Member

@Mpdreamz Mpdreamz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review (nitpicks + small fixes)

Thanks for the --plan flow — this matches what we need for docs-actions and avoids duplicating resolution logic in JS.

1. Use filesystem path joining in PlanBundleAsync (not UrlPath.Join)

UrlPath is for URL-style paths (always /). The plan output output_path is a filesystem path for CI/Docker; it should match how the real bundle path is built elsewhere (_fileSystem.Path.Join / Path.Join in ApplyConfigDefaults and BundleChangelogs).

Suggestion: replace UrlPath.Join with _fileSystem.Path.Join (or Path.Join consistent with ApplyConfigDefaults line ~432) and drop the comment about “CI runners expect forward slashes” — Windows runners need correct OS separators.

// Resolve output path — mirrors the logic in ProcessProfile + ApplyConfigDefaults.
var outputPath = input.Output;
if (string.IsNullOrWhiteSpace(outputPath) && profileDef?.Output != null)
{
	var version = input.ProfileArgument ?? "unknown";
	var lifecycle = VersionLifecycleInference.InferLifecycle(version);
	var outputPattern = profileDef.Output
		.Replace("{version}", version)
		.Replace("{lifecycle}", lifecycle);
	var outputDir = config?.Bundle?.OutputDirectory
		?? config?.Bundle?.Directory
		?? _fileSystem.Directory.GetCurrentDirectory();
	outputPath = _fileSystem.Path.Join(outputDir, outputPattern);
}
else if (string.IsNullOrWhiteSpace(outputPath) && config?.Bundle?.OutputDirectory != null)
	outputPath = Path.Join(config.Bundle.OutputDirectory, "changelog-bundle.yaml");

(Adjust if you prefer Path.Join for both branches to match ApplyConfigDefaults exactly.)

2. XML / docs: say “GitHub Actions outputs”, not JSON

  • PlanBundleAsync <summary> currently says CI consumes “structured JSON”; implementation sets GHA step outputs via SetOutputAsync (needs_network, needs_github_token, output_path). Worth aligning the summary with that.
  • The plan parameter on Bundle has the same “JSON plan” wording — suggest describing the output keys and that no bundle is written.

3. Test name vs assertions

Plan_ProfileNotFound_ReturnsNull asserts result.Should().NotBeNull(). Consider renaming to something like Plan_ProfileNotFound_StillReturnsResult_WithNeedsNetworkFalse (or similar) so the name matches behavior.


Happy to re-review after these tweaks.

@Mpdreamz
Copy link
Copy Markdown
Member

Mpdreamz commented Apr 7, 2026

Clarification on the review: for joining paths in PlanBundleAsync, use _fileSystem.Path.Join (not Path.Join / UrlPath.Join alone). This service uses ScopedFileSystem to constrain filesystem access; staying on the injected IFileSystem path API matches the rest of ChangelogBundlingService (e.g. default bundle output) and keeps path resolution within that abstraction.

@cotti cotti requested a review from Mpdreamz April 7, 2026 17:12
@cotti cotti merged commit 3ea7f85 into main Apr 7, 2026
28 checks passed
@cotti cotti deleted the feature/changelog-bundle-plan branch April 7, 2026 21:29
cotti added a commit that referenced this pull request Apr 8, 2026
* Add --plan flag to bundle

* Update bundle docs

* use UrlPath

* Fix merge mishap

* Add allowlist and https checks for report URLs

* Use ScopedFileSystem, update xml docs

* Adjust test names

* Fix tests on Windows

* Sanitize paths

* Use OptionalWindowsReplace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants