Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions docs/cli/release/changelog-add.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ docs-builder changelog add [options...] [-h|--help]
`--output <string?>`
: 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 <string?>`
: Optional: GitHub repository owner (used when `--pr` is just a number).

Expand All @@ -64,6 +60,11 @@ docs-builder changelog add [options...] [-h|--help]
`--repo <string?>`
: 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 <string?>`
: 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).
Expand All @@ -76,3 +77,7 @@ docs-builder changelog add [options...] [-h|--help]
`--type <string>`
: 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.
10 changes: 9 additions & 1 deletion docs/contribute/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ Options:
--output <string?> Optional: Output directory for the changelog. Defaults to current directory [Default: null]
--config <string?> 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
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}

31 changes: 29 additions & 2 deletions src/services/Elastic.Documentation.Services/ChangelogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/tooling/docs-builder/Commands/ChangelogCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public Task<int> Default()
/// <param name="output">Optional: Output directory for the changelog. Defaults to current directory</param>
/// <param name="config">Optional: Path to the changelog.yml configuration file. Defaults to 'docs/changelog.yml'</param>
/// <param name="usePrNumber">Optional: Use the PR number as the filename instead of generating it from a unique ID and title</param>
/// <param name="stripTitlePrefix">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")</param>
/// <param name="ctx"></param>
[Command("add")]
public async Task<int> Create(
Expand All @@ -71,6 +72,7 @@ public async Task<int> Create(
string? output = null,
string? config = null,
bool usePrNumber = false,
bool stripTitlePrefix = false,
Cancel ctx = default
)
{
Expand Down Expand Up @@ -136,7 +138,8 @@ public async Task<int> Create(
Highlight = highlight,
Output = output,
Config = config,
UsePrNumber = usePrNumber
UsePrNumber = usePrNumber,
StripTitlePrefix = stripTitlePrefix
};

serviceInvoker.AddCommand(service, input,
Expand Down
Loading