Fix --use-pr-number for changelog add #2485
Open
+106
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Impetus
The
--use-pr-numberoption is no longer working. The filename output from "docs-builder changelog add" is unchanged when that option is present.Problem
Before this PR, the following command (with the config file from elastic/elasticsearch#140141):
./docs-builder changelog add --prs 140034 \ --repo elasticsearch --owner elastic \ --products "elasticsearch 9.3.0" \ --output /GitHub/elasticsearch/docs/changelog/ \ --type bug-fix --config /GitHub/elasticsearch/docs/changelog.yml --use-pr-number... incorrectly generated a file called
1768517811-esql-fix-extent-reading-when-missing.yaml.This is a regression from the behaviour implemented in #2422.
With this PR fix, it once again generates a file called
140034.yaml.Solution
The
--use-pr-numberoption wasn't working because:Filename generation ignored
UsePrNumber: InCreateSingleChangelog(lines 388-393), the code always generated timestamp-based filenames ({timestamp}-{slug}.yaml) without checkinginput.UsePrNumber.Missing property copy for multiple PRs: In
CreateChangelogsForMultiplePrs(lines 131-149), when creating a copy of the input for each PR, theUsePrNumberproperty wasn't being copied, so it was lost when processing multiple PRs.Fixes Applied
Updated filename generation (lines 381-410): Added logic to check
input.UsePrNumber. When true and a PR URL is provided, it extracts the PR number using the existingExtractPrNumbermethod and uses{prNumber}.yamlas the filename. Falls back to the timestamp-based format if extraction fails.Fixed property copy (line 148): Added
UsePrNumber = input.UsePrNumberto theprInputcopy inCreateChangelogsForMultiplePrsso the flag is preserved when processing multiple PRs.The build completed successfully with no errors. Your command should now create a file named
140034.yamlinstead of the timestamp-based filename.Testing
CreateChangelog_WithUsePrNumber_CreatesFileWithPrNumberAsFilenameintests/Elastic.Documentation.Services.Tests/ChangelogServiceTests.csto verify that when--use-pr-numberis used, the changelog filename is the PR number (e.g.,140034.yaml) instead of a timestamp-based name.The test:
ChangelogInputwithUsePrNumber = trueand a PR URLCreateChangelogto generate the changelog file140034.yaml(not a timestamp-based name like1768517811-esql-fix-extent-reading-when-missing.yaml)The test:
This ensures the --use-pr-number option works as expected and prevents regressions.
Generative AI disclosure
Tool(s) and model(s) used: composer-1