Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughReplaces Sequence Diagram(s)sequenceDiagram
actor User
participant CLI as changelog init (ChangelogCommand)
participant FS as File System
participant GitConfig as GitConfigOriginParser
participant GitHubParser as GitHubRemoteParser
participant Seeder as ChangelogTemplateSeeder
User->>CLI: Invoke init (--owner/--repo optional)
CLI->>FS: Check for changelog.yml
FS-->>CLI: Not found
CLI->>FS: Read template
FS-->>CLI: Return template content
CLI->>FS: Read .git/config or .git worktree pointer
FS-->>CLI: Return config content or pointer
CLI->>GitConfig: TryGetRemoteOriginUrl(configContent)
GitConfig-->>CLI: Return origin URL or fail
CLI->>GitHubParser: TryParseGitHubComOwnerRepo(url)
GitHubParser-->>CLI: Return owner/repo or fail
CLI->>Seeder: ApplyBundleRepoSeed(content, ownerCli, repoCli, gitOwner, gitRepo)
Seeder-->>CLI: Return seeded YAML content
CLI->>FS: Write changelog.yml with seeded bundle fields
FS-->>User: File created
Suggested labels
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches✨ Simplify code
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/Elastic.Documentation.Configuration/GitRemoteConfigurationReader.cs (1)
31-47: Consider wrapping file reads in try-catch for robustness.
ReadAllTexton lines 31 and 56 can throw if the file exists but is unreadable (permissions, locked, etc.). Since this is aTryXxxpattern, callers expectfalseon failure rather than exceptions.This is a minor edge case—may not be worth the complexity if the calling code handles exceptions upstream.
🛡️ Optional: wrap reads defensively
public static bool TryReadOriginUrl(IFileSystem fileSystem, string repositoryRoot, [NotNullWhen(true)] out string? url) { url = null; + try + { var gitPath = fileSystem.Path.Combine(repositoryRoot, ".git"); if (fileSystem.Directory.Exists(gitPath)) { var configPath = fileSystem.Path.Combine(gitPath, "config"); return TryReadOriginUrlFromConfigPath(fileSystem, configPath, out url); } if (!fileSystem.File.Exists(gitPath)) return false; var gitFileText = fileSystem.File.ReadAllText(gitPath); // ... rest of method + } + catch + { + return false; + } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/Elastic.Documentation.Configuration/GitRemoteConfigurationReader.cs` around lines 31 - 47, The file reads using fileSystem.File.ReadAllText (the read of gitPath and the later read at the worktree config path) should be wrapped in try/catch so the Try* pattern returns false on IO errors instead of throwing; update the method containing these ReadAllText calls to catch exceptions (IOException, UnauthorizedAccessException, and a general Exception fallback) around each ReadAllText invocation and return false (and set out url to null if applicable) when an exception is caught, preserving existing behavior when reads succeed—refer to the ReadAllText calls and the call site TryReadOriginUrlFromConfigPath to locate the two places to add the defensive try/catch.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@config/changelog.example.yml`:
- Around line 215-224: The changelog template documents a non-existent
link_allow_repos feature; to fix, remove all references and seeding of
link_allow_repos from the template and the init code paths (the changelog init
generator) OR implement the feature by adding a property to BundleConfiguration
to accept link_allow_repos and wiring deserialization/usage where PR/issue links
are resolved (ensure code that rewrites links to '# PRIVATE:' consults
bundle.owner/bundle.repo and the new BundleConfiguration.link_allow_repos).
Update any tests and the init generator to stop seeding link_allow_repos if you
choose removal, or to seed and validate it if you implement it.
In `@src/tooling/docs-builder/Commands/ChangelogCommand.cs`:
- Around line 1335-1345: Normalize and YAML-escape CLI owner/repo values before
using them in the seeding logic: treat ownerCli and repoCli that are null,
empty, or only whitespace as null overrides (so resolvedOwner/resolvedRepo fall
back to gitOwner/gitRepo), and sanitize/escape resolvedOwner and resolvedRepo
for safe YAML insertion (escape special characters and wrap if needed) before
computing shouldSeed and building block; update the logic around resolvedRepo,
resolvedOwner, shouldSeed, and block to use the normalized/escaped values.
---
Nitpick comments:
In `@src/Elastic.Documentation.Configuration/GitRemoteConfigurationReader.cs`:
- Around line 31-47: The file reads using fileSystem.File.ReadAllText (the read
of gitPath and the later read at the worktree config path) should be wrapped in
try/catch so the Try* pattern returns false on IO errors instead of throwing;
update the method containing these ReadAllText calls to catch exceptions
(IOException, UnauthorizedAccessException, and a general Exception fallback)
around each ReadAllText invocation and return false (and set out url to null if
applicable) when an exception is caught, preserving existing behavior when reads
succeed—refer to the ReadAllText calls and the call site
TryReadOriginUrlFromConfigPath to locate the two places to add the defensive
try/catch.
🪄 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: 1379386a-f981-4c6b-8a0c-3343094b5578
📒 Files selected for processing (9)
config/changelog.example.ymldocs/cli/changelog/init.mdsrc/Elastic.Documentation.Configuration/GitConfigOriginParser.cssrc/Elastic.Documentation.Configuration/GitHubRemoteParser.cssrc/Elastic.Documentation.Configuration/GitRemoteConfigurationReader.cssrc/tooling/docs-builder/Commands/ChangelogCommand.cstests/Elastic.Documentation.Configuration.Tests/GitConfigOriginParserTests.cstests/Elastic.Documentation.Configuration.Tests/GitHubRemoteParserTests.cstests/Elastic.Documentation.Configuration.Tests/GitRemoteConfigurationReaderTests.cs
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/Elastic.Documentation.Configuration/ChangelogTemplateSeeder.cs`:
- Around line 40-43: The QuoteForYaml method fails to escape backslashes and
control characters, so strings like "C:\repo" produce invalid or mutated YAML;
update QuoteForYaml to escape backslashes first (replace "\" with "\\") and then
escape double quotes and common YAML/C-style control characters (e.g., \n, \r,
\t, \b, \f, vertical tab) into their backslash-escaped forms before wrapping in
double quotes; keep the existing check for colon/space/#/quote and apply these
replacements inside the branch that quotes the value (refer to QuoteForYaml).
- Line 37: The current replacement only removes Placeholder followed by eol, so
a placeholder at EOF without a trailing newline remains; update the seeding
logic in ChangelogTemplateSeeder to also handle the bare Placeholder by
performing an additional replacement of content.Replace(Placeholder, block,
StringComparison.Ordinal) (or check content.EndsWith(Placeholder) and replace
that suffix) after the existing content.Replace(Placeholder + eol, block,
StringComparison.Ordinal) call so templates that end without a newline are
seeded too.
🪄 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: 48553708-98f7-442d-b53b-1a8eaebdc1b1
📒 Files selected for processing (3)
src/Elastic.Documentation.Configuration/ChangelogTemplateSeeder.cssrc/tooling/docs-builder/Commands/ChangelogCommand.cstests/Elastic.Documentation.Configuration.Tests/ChangelogTemplateSeederTests.cs
🚧 Files skipped from review as they are similar to previous changes (1)
- src/tooling/docs-builder/Commands/ChangelogCommand.cs
This PR must be merged after #3029
Summary
Enhance
changelog initcommand to reduce likelihood of users forgetting to add their own repo tolink_allow_repos.Implementation details
Here is what was implemented:
New helpers (
src/Elastic.Documentation.Configuration)GitHubRemoteParser– Parsesgithub.comHTTPS and SSH remote URLs intoownerandrepo.GitConfigOriginParser– Reads the firsturlunder[remote "origin"]from config text.GitRemoteConfigurationReader– Loads that URL viaIFileSystemfrom.git/config, or from a git worktree when.gitis agitdir:file.changelog initinsrc/tooling/docs-builder/Commands/ChangelogCommand.cs--ownerand--repo(CLI overrides git).changelog.ymlcreation only: resolves owner/repo from gitorigin(when it parses as github.com) and/or CLI; if onlyrepois known, owner defaults toelastic.# changelog-init-bundle-seedwith:or removes that line when seeding is not possible.
Template
config/changelog.example.ymlDocs (
docs/cli/changelog/init.md)--owner/--repo, and adds an example for CI or non-git use.Tests (
tests/Elastic.Documentation.Configuration.Tests/)MockFileSystemcoverage for.git/configand worktree layout.docs-builderbuilds successfully;changelog init --helplists the new options with readable descriptions (XML tags removed from summaries so they do not leak into the CLI help).Generative AI disclosure
Tool(s) and model(s) used: composer-2