Skip to content

Changelog: ensure product labels are validated and used#2974

Merged
cotti merged 5 commits intomainfrom
fix/changelog_product_labels
Mar 27, 2026
Merged

Changelog: ensure product labels are validated and used#2974
cotti merged 5 commits intomainfrom
fix/changelog_product_labels

Conversation

@cotti
Copy link
Copy Markdown
Contributor

@cotti cotti commented Mar 27, 2026

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:

  • Added logic in ChangelogCreationService to 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]
  • Implemented parsing and formatting utilities in ProductArgument for 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:

  • Updated ChangelogPrEvaluationService to 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:

  • Extended CLI documentation to describe the new CHANGELOG_PRODUCTS environment variable and its mapping, and documented the new products and product-label-table outputs for the changelog-evaluate-pr command. [1] [2]

Testing and Validation:

  • Added and updated tests to verify that product resolution works correctly in various CI and CLI scenarios, including precedence rules, parsing of complex product specs, and fallback behavior when products are missing. Introduced a new test suite for 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.

@cotti cotti self-assigned this Mar 27, 2026
@cotti cotti requested review from a team as code owners March 27, 2026 12:51
@cotti cotti added the fix label Mar 27, 2026
@cotti cotti requested a review from Mpdreamz March 27, 2026 12:51
@coderabbitai coderabbitai bot added documentation Improvements or additions to documentation feature and removed fix labels Mar 27, 2026
@cotti cotti added fix and removed feature documentation Improvements or additions to documentation labels Mar 27, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 27, 2026

📝 Walkthrough

Walkthrough

The 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 products and product-label-table. ProductArgument gained parsing/formatting helpers. Documentation and tests were added/updated accordingly.

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
Loading

Suggested labels

feature, documentation

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% 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 'Changelog: ensure product labels are validated and used' directly describes the PR's main objective: adding product label support and validation throughout the changelog system.
Description check ✅ Passed The PR description accurately and comprehensively describes the changeset, detailing product resolution logic, environment variable support, evaluation service enhancements, documentation updates, and testing additions across multiple files.

✏️ 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 fix/changelog_product_labels

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

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 | 🟠 Major

CI enrichment gate can drop valid CHANGELOG_PRODUCTS input.

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

📥 Commits

Reviewing files that changed from the base of the PR and between c8877a0 and 7d7bd3e.

📒 Files selected for processing (9)
  • docs/cli/release/changelog-add.md
  • docs/cli/release/changelog-evaluate-pr.md
  • src/services/Elastic.Changelog/Creation/ChangelogCreationService.cs
  • src/services/Elastic.Changelog/Evaluation/ChangelogPrEvaluationService.cs
  • src/services/Elastic.Changelog/ProductArgument.cs
  • tests/Elastic.Changelog.Tests/Creation/CIEnrichmentTests.cs
  • tests/Elastic.Changelog.Tests/Creation/ChangelogCreationServiceTests.cs
  • tests/Elastic.Changelog.Tests/Evaluation/ChangelogPrEvaluationServiceTests.cs
  • tests/Elastic.Changelog.Tests/ProductArgumentTests.cs

cotti and others added 2 commits March 27, 2026 10:00
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@coderabbitai coderabbitai bot added documentation Improvements or additions to documentation feature and removed fix labels Mar 27, 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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7d7bd3e and dde6ec2.

📒 Files selected for processing (2)
  • src/services/Elastic.Changelog/ProductArgument.cs
  • tests/Elastic.Changelog.Tests/Evaluation/ChangelogPrEvaluationServiceTests.cs

@cotti cotti removed the documentation Improvements or additions to documentation label Mar 27, 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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between dde6ec2 and f436deb.

📒 Files selected for processing (3)
  • docs/cli/release/changelog-evaluate-pr.md
  • src/services/Elastic.Changelog/Evaluation/ChangelogPrEvaluationService.cs
  • tests/Elastic.Changelog.Tests/Evaluation/ChangelogPrEvaluationServiceTests.cs
✅ Files skipped from review due to trivial changes (1)
  • docs/cli/release/changelog-evaluate-pr.md

@cotti cotti merged commit 0485881 into main Mar 27, 2026
28 of 29 checks passed
@cotti cotti deleted the fix/changelog_product_labels branch March 27, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants