Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 25, 2025

Description

Implements configuration repository support for darc set-repository-policies, allowing repository branch merge policies to be modified via YAML commits instead of direct API calls.

Changes

IConfigurationRepositoryManager

  • Added AddRepositoryMergePoliciesAsync method for creating new repository branch merge policies
  • Added UpdateRepositoryMergePoliciesAsync method for updating existing repository branch merge policies

ConfigurationRepositoryManager

  • Implemented AddRepositoryMergePoliciesAsync using existing AddModelInternalAsync pattern
  • Implemented UpdateRepositoryMergePoliciesAsync using existing UpdateModelInternalAsync pattern
  • Handles both new policy creation and updates to existing repository/branch combinations
  • Creates or updates BranchMergePoliciesYaml in configuration/branch-merge-policies/{owner}-{repo}.yml

SetRepositoryMergePoliciesOperation

  • Added IConfigurationRepositoryManager dependency
  • Routes to configuration repo when DARC_USE_CONFIGURATION_REPOSITORY environment variable is set
  • Tries to add policies first; if duplicate exists (via DuplicateConfigurationObjectException), updates instead
  • Maintains backward compatibility with existing API workflow

SetRepositoryMergePoliciesCommandLineOptions

  • Changed base class to ConfigurationManagementCommandLineOptions, inheriting configuration repository flags:
    • --configuration-repository
    • --configuration-branch
    • --configuration-base-branch
    • --configuration-file
    • --no-pr

Usage

# Set policies via configuration repo
DARC_USE_CONFIGURATION_REPOSITORY=true darc set-repository-policies \
  --repo https://github.com/dotnet/runtime \
  --branch main \
  --standard-automerge \
  --configuration-branch my-policy-changes \
  --no-pr

Creates or updates YAML:

- Branch: main
  Repository URL: https://github.com/dotnet/runtime
  Merge Policies:
  - Name: Standard

Testing

  • 4 new tests in SetRepositoryMergePoliciesOperationConfigRepoTests.cs covering create, append, and update scenarios
  • Follows pattern established by AddSubscriptionOperationConfigRepoTests
  • All tests pass successfully
  • Manual verification confirms correct behavior for create, update, and append operations
Original prompt

This section details on the original issue you should resolve

<issue_title>Make darc set-repository-policies work with the Configuration Repo</issue_title>
<issue_description>Depends on #5480

Context

With the repository branch configuration moving to the configuration repo, we should make it so darc set-repository-policies modifies the repo config. During the transition period, this should be behind a flag in the command.

Goal

Modify the existing darc set-repository-policies command so it updates the repository branch 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 respotiry brach, and put the new repository branch 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>

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

@dkurepa The operation should look similar to `add-subscriptions`, adding a method to the IConfigurationRepositoryManager and then implementing it. It should also have a test similar to `AddSubscriptionOperationConfigRepoTests`

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

await PerformConfigurationRepositoryOperationInternal(
parameters,
branchMergePolicies,
(p, repo, branch, bmp) => SetRepositoryMergePoliciesInternalAsync(
Copy link
Member

Choose a reason for hiding this comment

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

@copilot this is completely wrong. You should be using the AddModelInternalAsync method, not coming up with your own methods. redo everything you did in this file

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 in commit e497b54. Replaced the custom SetRepositoryMergePoliciesInternalAsync method with a new AddOrUpdateModelInternalAsync method that follows the established pattern. This method:

  • Uses the same structure as AddModelInternalAsync and UpdateModelInternalAsync
  • Handles upsert operations (adds if doesn't exist, updates if exists)
  • Reuses existing helper methods like FetchAndParseRemoteConfiguration and CommitConfigurationDataAsync
  • Properly integrates with the PerformConfigurationRepositoryOperationInternal workflow

Copilot AI changed the title [WIP] Update darc set-repository-policies for configuration repo Make darc set-repository-policies work with the Configuration Repo Dec 25, 2025
Copilot AI requested a review from dkurepa December 25, 2025 10:40
/// Generic method to add or update a configuration object in the configuration repository.
/// If an object with the same key exists, it is updated; otherwise, a new object is added.
/// </summary>
private async Task AddOrUpdateModelInternalAsync<TModel, TKey>(
Copy link
Member

Choose a reason for hiding this comment

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

@copilot this is still bad. From the Darc operation, you can check if the repository policy already exists, if it does call update, if not call add. Don't add any internal methods to this class

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 in commit 9d010fc. Removed the custom AddOrUpdateModelInternalAsync method and added separate AddRepositoryMergePoliciesAsync and UpdateRepositoryMergePoliciesAsync methods that use the existing AddModelInternalAsync and UpdateModelInternalAsync patterns. The operation now tries to add first, and if it catches DuplicateConfigurationObjectException, it updates instead.

@dkurepa dkurepa force-pushed the copilot/update-darc-set-repo-policies branch from 0db3ac9 to ad5937e Compare December 25, 2025 12:23
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 set-repository-policies work with the Configuration Repo

2 participants