Skip to content

Add --repo --owner to changelog init#3042

Open
lcawl wants to merge 11 commits intomainfrom
changelog-allowlist-init
Open

Add --repo --owner to changelog init#3042
lcawl wants to merge 11 commits intomainfrom
changelog-allowlist-init

Conversation

@lcawl
Copy link
Copy Markdown
Contributor

@lcawl lcawl commented Apr 6, 2026

This PR must be merged after #3029

Summary

Enhance changelog init command to reduce likelihood of users forgetting to add their own repo to link_allow_repos.

Implementation details

Here is what was implemented:

New helpers (src/Elastic.Documentation.Configuration)

  • GitHubRemoteParser – Parses github.com HTTPS and SSH remote URLs into owner and repo.
  • GitConfigOriginParser – Reads the first url under [remote "origin"] from config text.
  • GitRemoteConfigurationReader – Loads that URL via IFileSystem from .git/config, or from a git worktree when .git is a gitdir: file.

changelog init in src/tooling/docs-builder/Commands/ChangelogCommand.cs

  • New optional --owner and --repo (CLI overrides git).
  • On first changelog.yml creation only: resolves owner/repo from git origin (when it parses as github.com) and/or CLI; if only repo is known, owner defaults to elastic.
  • Replaces the template line # changelog-init-bundle-seed with:
  owner: 
  repo: 
  link_allow_repos:
    - owner/repo

or removes that line when seeding is not possible.

Template config/changelog.example.yml

  • Single placeholder line for init, plus comments on explicit allowlist behavior and examples.

Docs (docs/cli/changelog/init.md)

  • Describes seeding, --owner / --repo, and adds an example for CI or non-git use.

Tests (tests/Elastic.Documentation.Configuration.Tests/)

  • URL parsing, config parsing, and MockFileSystem coverage for .git/config and worktree layout.

docs-builder builds successfully; changelog init --help lists the new options with readable descriptions (XML tags removed from summaries so they do not leak into the CLI help).

Generative AI disclosure

  1. Did you use a generative AI (GenAI) tool to assist in creating this contribution?
  • Yes
  • No
  1. If you answered "Yes" to the previous question, please specify the tool(s) and model(s) used (e.g., Google Gemini, OpenAI ChatGPT-4, etc.).

Tool(s) and model(s) used: composer-2

@lcawl lcawl marked this pull request as ready for review April 6, 2026 19:10
@lcawl lcawl requested review from a team as code owners April 6, 2026 19:10
@lcawl lcawl requested a review from Mpdreamz April 6, 2026 19:10
@coderabbitai coderabbitai bot added documentation Improvements or additions to documentation and removed enhancement labels Apr 6, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 6, 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

Replaces bundle.sanitize_private_links with a new bundle.link_allow_repos allowlist (when present, non-matching PR/issue links are rewritten to '# PRIVATE:' when resolve: true; omitting the field applies no filtering). Adds seeding for bundle.owner, bundle.repo, and bundle.link_allow_repos when changelog init creates changelog.yml, with optional --owner/--repo CLI flags and defined precedence. Introduces Git parsing utilities (GitConfigOriginParser, GitHubRemoteParser, GitRemoteConfigurationReader) to extract origin without subprocesses. Updates ChangelogCommand to apply template seeding and adds unit tests for the new parsers/readers and the seeder.

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
Loading

Suggested labels

feature

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% 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 directly describes the main change: adding --repo and --owner optional parameters to the changelog init command.
Description check ✅ Passed The description comprehensively covers the implementation, new helpers, CLI changes, template/docs updates, and test coverage related to the changelog init enhancements.

✏️ 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 changelog-allowlist-init

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.

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.

ReadAllText on lines 31 and 56 can throw if the file exists but is unreadable (permissions, locked, etc.). Since this is a TryXxx pattern, callers expect false on 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9eb637f and b720026.

📒 Files selected for processing (9)
  • config/changelog.example.yml
  • docs/cli/changelog/init.md
  • src/Elastic.Documentation.Configuration/GitConfigOriginParser.cs
  • src/Elastic.Documentation.Configuration/GitHubRemoteParser.cs
  • src/Elastic.Documentation.Configuration/GitRemoteConfigurationReader.cs
  • src/tooling/docs-builder/Commands/ChangelogCommand.cs
  • tests/Elastic.Documentation.Configuration.Tests/GitConfigOriginParserTests.cs
  • tests/Elastic.Documentation.Configuration.Tests/GitHubRemoteParserTests.cs
  • tests/Elastic.Documentation.Configuration.Tests/GitRemoteConfigurationReaderTests.cs

@lcawl lcawl added enhancement and removed documentation Improvements or additions to documentation labels Apr 6, 2026
@coderabbitai coderabbitai bot added feature and removed enhancement labels Apr 6, 2026
@coderabbitai coderabbitai bot added documentation Improvements or additions to documentation and removed feature labels Apr 6, 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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between c91bab0 and dbc074d.

📒 Files selected for processing (3)
  • src/Elastic.Documentation.Configuration/ChangelogTemplateSeeder.cs
  • src/tooling/docs-builder/Commands/ChangelogCommand.cs
  • tests/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

@coderabbitai coderabbitai bot added feature and removed documentation Improvements or additions to documentation labels Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants