Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 16, 2025

Implements configuration repository mode for darc add-channel to add channels via git repository instead of API calls, using the templatized pattern recently introduced to ConfigurationRepositoryManager.

Changes

Command Interface

  • AddChannelCommandLineOptions now inherits ConfigurationManagementCommandLineOptions, exposing:
    • --configuration-repository - Target repo URI
    • --configuration-base-branch - Base for PR creation
    • --configuration-branch - Working branch (auto-generated if unspecified)
    • --configuration-file - Override default file path
    • --no-pr - Skip PR creation (commit only)
  • Mode controlled by DARC_USE_CONFIGURATION_REPOSITORY environment variable

Core Implementation

  • AddChannelOperation validates channel doesn't already exist in API before constructing the YAML model, throwing ArgumentException if duplicate found
  • ConfigurationRepositoryManager.AddChannelAsync uses the templatized PerformConfigurationRepositoryOperationInternal pattern:
    • Delegates to AddChannelInternalAsync for actual implementation
    • Follows same structure as subscription operations (Add/Delete/Update)
    • Handles branch preparation and validation
    • YAML file fetch/parse/update with ChannelYamlComparer ordering
    • Duplicate detection in target file (case-insensitive name comparison)
    • Commit and PR creation

Testing

  • AddChannelOperationConfigRepoTests validates file creation, append behavior, duplicate detection (API and YAML), and YAML format
  • Uses ConfigurationManagementTestBase with real git repo (not mocked)
  • All 5 new tests passing, all 130 existing Darc tests passing

Usage

export DARC_USE_CONFIGURATION_REPOSITORY=true
darc add-channel --name ".NET 11" --classification "product"

# To specific branch without PR
darc add-channel --name ".NET 11" --classification "product" \
  --configuration-branch "existing-branch" --no-pr

API mode remains default (backward compatible). Configuration mode creates/updates files at configuration/channels/{normalized-name}.yml.

Implementation Notes

The implementation was refactored to align with the recently introduced templatized pattern in ConfigurationRepositoryManager, ensuring consistency across all configuration operations. Channel existence validation occurs before YAML construction to fail fast on duplicates.

Original prompt

This section details on the original issue you should resolve

<issue_title>Make darc add-channel work with the new configuration repo</issue_title>
<issue_description>Depends on #5480

Context

With the channel configuration moving to the configuration repo, we should make it so darc add-channel can modifies the repo config. During the transition period, this should be behind a flag in the command.

Goal

Modify the existing darc add-channel command so it adds the channel by modifying the configuration repo in whichever structure we agree on, using the available yaml models. We'll need to add a few flags to the command:

  • Flag to target the repo instead of the API
  • Flag to specify configuration repository
  • Flag to specify which branch to commit the config changes to (if we already have a PR, or for scenario tests)
  • Flag to specify which base branch to use for the PR creation
  • Flag to specify we don't want to open a PR (for scenario tests)
  • Flag to overwrite default file for the channel, and put the new channel in the provided file

This should be written so it makes it easy to remove the API part, and use the configuration repo as one and only way to modify the configuration
</issue_description>

<agent_instructions>Look at the implementation for AddSubscriptionOperation. Also it's part in the ConfigurationRepository Manager, they should look quite similar</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@dkurepa The implementation for this operation should look similar to the AddSubscriptionAsync one in the ConfigurationRepositoryManager.

We should be able to reuse most of the methods for fetching the file, commiting it, etc..</comment_new>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@dkurepa
Copy link
Member

dkurepa commented Dec 16, 2025

@copilot also make sure to add tests like we have for AddSubscriptionOperation

Co-authored-by: dkurepa <91743470+dkurepa@users.noreply.github.com>
Copilot AI changed the title [WIP] Modify darc add-channel to work with new configuration repo Add configuration repository support to darc add-channel Dec 16, 2025
Copilot AI requested a review from dkurepa December 16, 2025 17:11
Copy link
Contributor Author

Copilot AI commented Dec 16, 2025

@copilot also make sure to add tests like we have for AddSubscriptionOperation

Tests have been added following the same pattern as AddSubscriptionOperationConfigRepoTests. All 5 tests are passing:

  • AddChannelOperation_WithConfigRepo_CreatesChannelFile
  • AddChannelOperation_WithConfigRepo_AppendsToExistingFile
  • AddChannelOperation_WithConfigRepo_FailsWhenChannelAlreadyExistsInApi
  • AddChannelOperation_WithConfigRepo_FailsWhenChannelAlreadyExistsInYamlFile
  • AddChannelOperation_WithConfigRepo_FileContentIsValidYaml

Commit: c178bc0

break;
default:
throw new NotImplementedException($"Output type {_options.OutputFormat} not supported by add-channel");
ChannelYaml channelYaml = new()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before constructing this, we should have a look if a channel with this name already exists, and throw an argument error if it does

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Channel existence check now happens before constructing the ChannelYaml object and throws ArgumentException if channel already exists.

Commit: 2f35b49

@dkurepa
Copy link
Member

dkurepa commented Dec 17, 2025

@copilot we recently rewrote ConfigurationRepositoryManager to templatize a lot of the functions. Rewrite that part so it fits with the rest

…sting channels before constructing YAML model

Co-authored-by: dkurepa <91743470+dkurepa@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 17, 2025

@copilot we recently rewrote ConfigurationRepositoryManager to templatize a lot of the functions. Rewrite that part so it fits with the rest

Refactored AddChannelAsync to use the templatized PerformConfigurationRepositoryOperationInternal pattern. The implementation now follows the same structure as AddSubscriptionAsync, DeleteSubscriptionAsync, and UpdateSubscriptionAsync with an internal AddChannelInternalAsync method.

Commit: 2f35b49

@dkurepa
Copy link
Member

dkurepa commented Dec 17, 2025

@copilot this still has conflicts. you didn't rebase on latest main

Copilot AI and others added 2 commits December 17, 2025 16:09
Co-authored-by: dkurepa <91743470+dkurepa@users.noreply.github.com>
Co-authored-by: dkurepa <91743470+dkurepa@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make darc add-channel work with the new configuration repo

2 participants