Changelog: ensure product labels are validated and used#2974
Conversation
📝 WalkthroughWalkthroughThe PR adds CI and PR-label-based product resolution for changelog workflows. The creation service now fetches PR info when any of Title, Type, or Products is missing. CI enrichment reads a new CHANGELOG_PRODUCTS environment variable and, when CLI input lacks products, parses it into Products. The evaluation service maps PR labels to products, formats product specs, and emits new GitHub Actions outputs Sequence Diagram(s)sequenceDiagram
participant CI as CI Environment
participant CCS as ChangelogCreationService
participant PA as ProductArgument
participant GH as GitHub PR Service
participant PES as ChangelogPrEvaluationService
participant Config as Config/Label Mappings
CI->>CCS: EnrichFromCI (reads CHANGELOG_PRODUCTS)
alt CHANGELOG_PRODUCTS provided and CLI products empty
CCS->>PA: ParseProductSpecs(env_products)
PA-->>CCS: ProductArgument list
CCS->>CCS: Populate Products from CI
end
alt Title, Type, or Products missing
CCS->>GH: FetchPrInfoAsync(prNumber)
GH-->>CCS: PR details (title, labels, etc.)
CCS->>PES: EvaluatePr(PR details)
PES->>Config: Resolve label->product mappings
Config-->>PES: mapped products or mapping table
alt mapped products found
PES->>PA: FormatProductSpecs(resolvedProducts)
PA-->>PES: comma-separated products
PES->>PES: SetOutputs(status=proceed, products, ...)
else no mapped products
PES->>PES: Build product-label-table
PES->>PES: SetOutputs(status=no-label, product-label-table)
end
else All required fields provided
CCS->>CCS: Skip PR API fetch
end
Suggested labelsfeature, documentation 🚥 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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/services/Elastic.Changelog/Creation/ChangelogCreationService.cs (1)
399-401:⚠️ Potential issue | 🟠 MajorCI enrichment gate can drop valid
CHANGELOG_PRODUCTSinput.At Line 399, enrichment runs only when PR number or title exists. If CI provides
CHANGELOG_PRODUCTS(or only type/owner/repo), this early return skips enrichment entirely.Proposed fix
- var hasCiData = !string.IsNullOrEmpty(prNumber) || !string.IsNullOrEmpty(ciTitle); + var hasCiData = + !string.IsNullOrEmpty(prNumber) || + !string.IsNullOrEmpty(ciTitle) || + !string.IsNullOrEmpty(ciType) || + !string.IsNullOrEmpty(ciOwner) || + !string.IsNullOrEmpty(ciRepo) || + !string.IsNullOrEmpty(ciProducts);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/services/Elastic.Changelog/Creation/ChangelogCreationService.cs` around lines 399 - 401, The early return uses hasCiData (based only on prNumber or ciTitle) and therefore skips enrichment when CI supplied CHANGELOG_PRODUCTS or when only type/owner/repo are present; update the gate inside ChangelogCreationService (the block using hasCiData and returning input) to also treat presence of input.CHANGELOG_PRODUCTS (or input.ChangelogProducts) and presence of input.Type, input.Owner, and input.Repo as valid CI data so enrichment proceeds; replace the current hasCiData condition with a check that returns only when none of prNumber, ciTitle, changelog products, nor type/owner/repo are provided, ensuring enrichment runs whenever any of those fields exist.
🤖 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/services/Elastic.Changelog/ProductArgument.cs`:
- Around line 81-89: The parsing uses entry.Split(' ', ...) which only splits on
literal spaces and misses tabs/newlines; update the split call in the
ProductArgument parsing block (where variable parts is assigned) to split on all
whitespace by calling entry.Split((char[])null,
StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) (or an
equivalent overload that splits on any whitespace) so Product, Target, and
Lifecycle extraction from ProductArgument works for tabs/newlines as well.
In
`@tests/Elastic.Changelog.Tests/Evaluation/ChangelogPrEvaluationServiceTests.cs`:
- Around line 420-423: The test currently uses WriteMinimalConfig which omits
pivot.products so it validates “no product mapping” instead of “no product
labels”; update the test to call ConfigWithProducts (or otherwise ensure
pivot.products exists) and supply args/labels that include no `@Product`:* entries
to exercise the “no product labels” branch—locate the test setup where
WriteMinimalConfig(), CreateService(), and DefaultArgs() are used and
replace/adjust the config call to ConfigWithProducts while keeping labels free
of any `@Product`: tokens.
---
Outside diff comments:
In `@src/services/Elastic.Changelog/Creation/ChangelogCreationService.cs`:
- Around line 399-401: The early return uses hasCiData (based only on prNumber
or ciTitle) and therefore skips enrichment when CI supplied CHANGELOG_PRODUCTS
or when only type/owner/repo are present; update the gate inside
ChangelogCreationService (the block using hasCiData and returning input) to also
treat presence of input.CHANGELOG_PRODUCTS (or input.ChangelogProducts) and
presence of input.Type, input.Owner, and input.Repo as valid CI data so
enrichment proceeds; replace the current hasCiData condition with a check that
returns only when none of prNumber, ciTitle, changelog products, nor
type/owner/repo are provided, ensuring enrichment runs whenever any of those
fields exist.
🪄 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: c1bc1ed0-e3b8-4770-8fa7-36c3068a7006
📒 Files selected for processing (9)
docs/cli/release/changelog-add.mddocs/cli/release/changelog-evaluate-pr.mdsrc/services/Elastic.Changelog/Creation/ChangelogCreationService.cssrc/services/Elastic.Changelog/Evaluation/ChangelogPrEvaluationService.cssrc/services/Elastic.Changelog/ProductArgument.cstests/Elastic.Changelog.Tests/Creation/CIEnrichmentTests.cstests/Elastic.Changelog.Tests/Creation/ChangelogCreationServiceTests.cstests/Elastic.Changelog.Tests/Evaluation/ChangelogPrEvaluationServiceTests.cstests/Elastic.Changelog.Tests/ProductArgumentTests.cs
tests/Elastic.Changelog.Tests/Evaluation/ChangelogPrEvaluationServiceTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/services/Elastic.Changelog/ProductArgument.cs`:
- Around line 48-59: To preserve roundtrip symmetry between ToSpecString() and
ParseProductSpecs, update ToSpecString (in ProductArgument) so that when
Lifecycle is non-empty but Target is null/empty it emits an explicit placeholder
for Target (e.g., "-") instead of omitting it; alternatively enforce validation
in ProductArgument.ParseProductSpecs/constructor to require Target whenever
Lifecycle is set. Modify ToSpecString() to append the placeholder before
Lifecycle (or add validation that throws/returns error if Lifecycle is set
without Target) and update ParseProductSpecs to recognize the placeholder and
map it back to a null/empty Target while keeping Lifecycle populated.
🪄 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: 07f6b486-cd9b-40c0-99b8-852883ce7087
📒 Files selected for processing (2)
src/services/Elastic.Changelog/ProductArgument.cstests/Elastic.Changelog.Tests/Evaluation/ChangelogPrEvaluationServiceTests.cs
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/services/Elastic.Changelog/Evaluation/ChangelogPrEvaluationService.cs`:
- Around line 117-121: The early return using SetOutputs with
PrEvaluationResult.NoLabel is not passing through the resolvedProducts, so
products output is lost; update the call in ChangelogPrEvaluationService (the
branch that returns PrEvaluationResult.NoLabel) to include resolvedProducts
(same variable used to build productLabelTable) as the products argument when
calling SetOutputs, keeping title, labelTable
(BuildLabelTable(config.LabelToType)) and productLabelTable unchanged.
🪄 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: fce2f308-10c1-4f97-8b4d-0ed397280fb3
📒 Files selected for processing (3)
docs/cli/release/changelog-evaluate-pr.mdsrc/services/Elastic.Changelog/Evaluation/ChangelogPrEvaluationService.cstests/Elastic.Changelog.Tests/Evaluation/ChangelogPrEvaluationServiceTests.cs
✅ Files skipped from review due to trivial changes (1)
- docs/cli/release/changelog-evaluate-pr.md
This pull request adds comprehensive support for resolving and handling "products" in the changelog CLI, especially when running in CI environments like GitHub Actions. It introduces new logic to parse, format, and propagate product information from environment variables, PR labels, and CLI arguments, ensuring that changelog entries are accurately associated with the correct products. Additionally, it updates documentation and adds thorough tests to cover these new behaviors.
Enhancements to Product Resolution and Handling:
ChangelogCreationServiceto derive products from environment variables (CHANGELOG_PRODUCTS), PR labels, or CLI arguments, ensuring that products are always resolved before creating a changelog entry. Now, if products are provided via environment or CLI, GitHub API calls are skipped; otherwise, the service falls back to PR label resolution. [1] [2] [3] [4]ProductArgumentfor product specs, supporting complex product strings with optional target and lifecycle fields, and added methods to convert between string representations and structured data.PR Evaluation Output Improvements:
ChangelogPrEvaluationServiceto resolve products from PR labels using new mappings, and to output both a comma-separated product spec and a markdown table of label-to-product mappings. Output logic now covers both type and product mappings for better traceability. [1] [2] [3] [4]Documentation Updates:
CHANGELOG_PRODUCTSenvironment variable and its mapping, and documented the newproductsandproduct-label-tableoutputs for thechangelog-evaluate-prcommand. [1] [2]Testing and Validation:
ChangelogCreationService. [1] [2] [3] [4] [5] [6]These changes ensure that changelog automation robustly supports product-aware workflows and that all relevant information is surfaced in both automation outputs and documentation.