diff --git a/docs/cli/release/changelog-add.md b/docs/cli/release/changelog-add.md index 35802bb27..5d02b5c94 100644 --- a/docs/cli/release/changelog-add.md +++ b/docs/cli/release/changelog-add.md @@ -38,10 +38,6 @@ docs-builder changelog add [options...] [-h|--help] `--output ` : Optional: Output directory for the changelog fragment. Defaults to current directory. -`--use-pr-number` -: Optional: Use the PR number as the filename instead of generating it from a unique ID and title. -: When using this option, you must also provide the `--pr` option. - `--owner ` : Optional: GitHub repository owner (used when `--pr` is just a number). @@ -64,6 +60,11 @@ docs-builder changelog add [options...] [-h|--help] `--repo ` : Optional: GitHub repository name (used when `--pr` is just a number). +`--strip-title-prefix` +: Optional: When used with `--prs`, remove square brackets and text within them from the beginning of PR titles. +: For example, if a PR title is `"[Attack discovery] Improves Attack discovery hallucination detection"`, the changelog title will be `"Improves Attack discovery hallucination detection"`. +: This option applies only when the title is derived from the PR (when `--title` is not explicitly provided). + `--subtype ` : Optional: Subtype for breaking changes (for example, `api`, `behavioral`, or `configuration`). : The valid subtypes are listed in [ChangelogConfiguration.cs](https://github.com/elastic/docs-builder/blob/main/src/services/Elastic.Documentation.Services/Changelog/ChangelogConfiguration.cs). @@ -76,3 +77,7 @@ docs-builder changelog add [options...] [-h|--help] `--type ` : Required: Type of change (for example, `feature`, `enhancement`, `bug-fix`, or `breaking-change`). : The valid types are listed in [ChangelogConfiguration.cs](https://github.com/elastic/docs-builder/blob/main/src/services/Elastic.Documentation.Services/Changelog/ChangelogConfiguration.cs). + +`--use-pr-number` +: Optional: Use the PR number as the filename instead of generating it from a unique ID and title. +: When using this option, you must also provide the `--pr` option. diff --git a/docs/contribute/changelog.md b/docs/contribute/changelog.md index aa18c5f4d..b1218febb 100644 --- a/docs/contribute/changelog.md +++ b/docs/contribute/changelog.md @@ -140,6 +140,7 @@ Options: --output Optional: Output directory for the changelog. Defaults to current directory [Default: null] --config Optional: Path to the changelog.yml configuration file. Defaults to 'docs/changelog.yml' [Default: null] --use-pr-number Optional: Use the PR number as the filename instead of generating it from a unique ID and title + --strip-title-prefix Optional: When used with --prs, remove square brackets and text within them from the beginning of PR titles ``` ### Authorization @@ -242,11 +243,18 @@ When you use the `--prs` option to derive information from a pull request, it ca docs-builder changelog add \ --prs https://github.com/elastic/elasticsearch/pull/139272 \ --products "elasticsearch 9.3.0" \ - --config test/changelog.yml + --config test/changelog.yml \ + --strip-title-prefix ``` In this case, the changelog file derives the title, type, and areas from the pull request. +The `--strip-title-prefix` option in this example means that if the PR title has a prefix in square brackets (such as `[ES|QL]` or `[Security]`), it is automatically removed from the changelog title. + +:::{note} +The `--strip-title-prefix` option only applies when the title is derived from the PR (when `--title` is not explicitly provided). If you specify `--title` explicitly, that title is used as-is without any prefix stripping. +::: + #### Block changelog creation with PR labels [example-block-label] You can configure product-specific label blockers to prevent changelog creation for certain PRs based on their labels. diff --git a/src/services/Elastic.Documentation.Services/Changelog/ChangelogInput.cs b/src/services/Elastic.Documentation.Services/Changelog/ChangelogInput.cs index d7ef6aaa6..63b0c8f9f 100644 --- a/src/services/Elastic.Documentation.Services/Changelog/ChangelogInput.cs +++ b/src/services/Elastic.Documentation.Services/Changelog/ChangelogInput.cs @@ -26,5 +26,6 @@ public class ChangelogInput public string? Output { get; set; } public string? Config { get; set; } public bool UsePrNumber { get; set; } + public bool StripTitlePrefix { get; set; } } diff --git a/src/services/Elastic.Documentation.Services/ChangelogService.cs b/src/services/Elastic.Documentation.Services/ChangelogService.cs index 77a3695ed..350020325 100644 --- a/src/services/Elastic.Documentation.Services/ChangelogService.cs +++ b/src/services/Elastic.Documentation.Services/ChangelogService.cs @@ -145,7 +145,9 @@ Cancel ctx FeatureId = input.FeatureId, Highlight = input.Highlight, Output = input.Output, - Config = input.Config + Config = input.Config, + UsePrNumber = input.UsePrNumber, + StripTitlePrefix = input.StripTitlePrefix }; // Process this PR (treat as single PR) @@ -244,7 +246,13 @@ Cancel ctx collector.EmitError(string.Empty, $"PR {prUrl} does not have a title. Please provide --title or ensure the PR has a title."); return false; } - input.Title = prInfo.Title; + var prTitle = prInfo.Title; + // Strip prefix if requested + if (input.StripTitlePrefix) + { + prTitle = StripSquareBracketPrefix(prTitle); + } + input.Title = prTitle; _logger.LogInformation("Using PR title: {Title}", input.Title); } else @@ -752,6 +760,25 @@ private static string SanitizeFilename(string input) return sanitized; } + private static string StripSquareBracketPrefix(string title) + { + if (string.IsNullOrWhiteSpace(title)) + return title; + + // Check if title starts with '[' + if (!title.StartsWith('[')) + return title; + + // Find the matching ']' + var closingBracketIndex = title.IndexOf(']', 1); + if (closingBracketIndex < 0) + return title; // No matching ']', return as-is + + // Extract everything after the closing bracket and trim whitespace + var remaining = title[(closingBracketIndex + 1)..].TrimStart(); + return remaining; + } + private static int? ExtractPrNumber(string prUrl, string? defaultOwner = null, string? defaultRepo = null) { // Handle full URL: https://github.com/owner/repo/pull/123 diff --git a/src/tooling/docs-builder/Commands/ChangelogCommand.cs b/src/tooling/docs-builder/Commands/ChangelogCommand.cs index b34a09ba0..4d5b0f702 100644 --- a/src/tooling/docs-builder/Commands/ChangelogCommand.cs +++ b/src/tooling/docs-builder/Commands/ChangelogCommand.cs @@ -51,6 +51,7 @@ public Task Default() /// Optional: Output directory for the changelog. Defaults to current directory /// Optional: Path to the changelog.yml configuration file. Defaults to 'docs/changelog.yml' /// Optional: Use the PR number as the filename instead of generating it from a unique ID and title + /// Optional: When used with --prs, remove square brackets and text within them from the beginning of PR titles (e.g., "[Inference API] Title" becomes "Title") /// [Command("add")] public async Task Create( @@ -71,6 +72,7 @@ public async Task Create( string? output = null, string? config = null, bool usePrNumber = false, + bool stripTitlePrefix = false, Cancel ctx = default ) { @@ -136,7 +138,8 @@ public async Task Create( Highlight = highlight, Output = output, Config = config, - UsePrNumber = usePrNumber + UsePrNumber = usePrNumber, + StripTitlePrefix = stripTitlePrefix }; serviceInvoker.AddCommand(service, input,