Skip to content

Opposite flow merged during open pr#5230

Merged
adamzip merged 14 commits intodotnet:mainfrom
adamzip:opposite-flow-merged-during-open-pr
Sep 3, 2025
Merged

Opposite flow merged during open pr#5230
adamzip merged 14 commits intodotnet:mainfrom
adamzip:opposite-flow-merged-during-open-pr

Conversation

@adamzip
Copy link
Copy Markdown
Contributor

@adamzip adamzip commented Sep 1, 2025

#5148
Note: still WIP. The refactoring commit actually includes some functional changes - I should clean it up

@adamzip adamzip force-pushed the opposite-flow-merged-during-open-pr branch 2 times, most recently from aa2e9a9 to 838c278 Compare September 1, 2025 14:29
Comment thread src/Microsoft.DotNet.Darc/DarcLib/VirtualMonoRepo/Exceptions.cs Outdated
Comment thread src/Microsoft.DotNet.Darc/DarcLib/VirtualMonoRepo/Exceptions.cs
Comment thread src/Microsoft.DotNet.Darc/DarcLib/VirtualMonoRepo/VmrCodeflower.cs Outdated
Comment thread src/Microsoft.DotNet.Darc/DarcLib/VirtualMonoRepo/VmrCodeflower.cs
Comment thread src/Microsoft.DotNet.Darc/DarcLib/VirtualMonoRepo/VmrCodeflower.cs Outdated
@adamzip adamzip force-pushed the opposite-flow-merged-during-open-pr branch from 838c278 to 3ea0c5a Compare September 1, 2025 16:00
@adamzip adamzip marked this pull request as ready for review September 1, 2025 16:36
Copilot AI review requested due to automatic review settings September 1, 2025 16:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements functionality to handle "opposite flow merged during open PR" scenarios by blocking pull requests from receiving future codeflow updates when conflicting flows have been merged.

Key changes include:

  • Added detection logic for when opposite direction flows have been merged while a PR is open
  • Implemented PR blocking mechanism with new BlockingCodeflowException and BlockedFromFutureUpdates property
  • Enhanced comment system to support template replacements for better user messaging

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
PullRequestUpdater.cs Refactored code flow execution into separate method and added blocking logic for PRs
PullRequestCommenter.cs Added template replacement functionality for dynamic comment content
InProgressPullRequest.cs Added BlockedFromFutureUpdates property to track blocked PRs
VmrCodeflower.cs Added detection logic for opposite flow scenarios and blocking exception
Exceptions.cs Added new BlockingCodeflowException for codeflow blocking scenarios
PcsVmrForwardFlower.cs Updated constructor to include comment collector dependency
PcsVmrBackFlower.cs Updated constructor to include comment collector dependency
VmrForwardFlower.cs Updated constructor to include comment collector dependency
VmrBackflower.cs Updated constructor to include comment collector dependency

Comment thread src/Microsoft.DotNet.Darc/DarcLib/VirtualMonoRepo/VmrCodeflower.cs Outdated
private readonly ILogger<VmrCodeFlower> _logger;

private static readonly string CannotFlowAdditionalFlowsInPrMsg = string.Concat(
"The source repository has received code changes from outside of this PR branch. This PR will stop ",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

isn't the problem that an opposite direction codeflow was merged?
For example, if we're printing this for a backflow, it means that a forward flow for that repo was merged, causing the next backflow to be considered "opposite direction"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's true

"PR must be merged or closed. Once this is done, code flows into the repository will resume normally ",
"on the next subscription trigger. In order to force the subscription trigger, merge or close this PR " +
"and run the following command using the subscription-id found in this PR. \n",
"`darc trigger-subscription --id <subscriptionId>`.");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

think this has to be updated for the force parameter?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That message is about closing or merging the PR and triggering the subscription normally (no force needed)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

but that is another option, no? if a person wants to trigger another subscription update in the same PR, they can use force

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this part of the sentence is problematic:

In order to force the subscription trigger

and then it proceeds to give instructions for re-opening while we have 2 options - force-trigger or re-open

Comment on lines +55 to +62
private static readonly string CannotFlowAdditionalFlowsInPrMsg = string.Concat(
"The source repository has received code changes from an opposite flow. Any additional codeflows into ",
"this PR may potentially result in lost changes. Please continue with one of the following options: \n",
"1. Close or merge this PR and let the codeflow continue normally. \n",
"2. Close or merge this PR and receive the new codeflow immediately by running ",
"`darc trigger-subscription --id <subscriptionId>`. \n",
"3. Keep flowing changes into this PR anyway by force-triggering the subscription: ",
"`darc trigger-subscription --force --id <subscriptionId>`.");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the new lines are missing in some of these place. Would it be better to just use a multi-line string?

Suggested change
private static readonly string CannotFlowAdditionalFlowsInPrMsg = string.Concat(
"The source repository has received code changes from an opposite flow. Any additional codeflows into ",
"this PR may potentially result in lost changes. Please continue with one of the following options: \n",
"1. Close or merge this PR and let the codeflow continue normally. \n",
"2. Close or merge this PR and receive the new codeflow immediately by running ",
"`darc trigger-subscription --id <subscriptionId>`. \n",
"3. Keep flowing changes into this PR anyway by force-triggering the subscription: ",
"`darc trigger-subscription --force --id <subscriptionId>`.");
private static readonly string CannotFlowAdditionalFlowsInPrMsg =
"""
The source repository has received code changes from an opposite flow. Any additional codeflows into
this PR may potentially result in lost changes.
Please continue with one of the following options:
1. Close or merge this PR and let the codeflow continue normally
2. Close or merge this PR and receive the new codeflow immediately by running
`darc trigger-subscription --id <subscriptionId>`
3. Force-flow changes into this PR but at your own risk (some PR commits might be reverted):
`darc trigger-subscription --force --id <subscriptionId>`
""";

Copy link
Copy Markdown
Contributor Author

@adamzip adamzip Sep 3, 2025

Choose a reason for hiding this comment

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

I think the newlines are in the right place. I avoided multiline string because I didn't want extremely long lines in the editor. Here's what the comment would currently look like on GH:

Important

The source repository has received code changes from an opposite flow. Any additional codeflows into this PR may potentially result in lost changes. Please continue with one of the following options:

  1. Close or merge this PR and let the codeflow continue normally.
  2. Close or merge this PR and receive the new codeflow immediately by running darc trigger-subscription --id <subscriptionId>.
  3. Keep flowing changes into this PR anyway by force-triggering the subscription: darc trigger-subscription --id <subscriptionId>.

In case of unclarities, consult the FAQ or tag \@dotnet/product-construction for assistance.

Copy link
Copy Markdown
Member

@premun premun Sep 3, 2025

Choose a reason for hiding this comment

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

Ah, that looks good.
Mine will look like this:

Important

The source repository has received code changes from an opposite flow. Any additional codeflows into
this PR may potentially result in lost changes.

Please continue with one of the following options:

  1. Close or merge this PR and let the codeflow continue normally
  2. Close or merge this PR and receive the new codeflow immediately by running
    darc trigger-subscription --id <subscriptionId>
  3. Force-flow changes into this PR but at your own risk (some PR commits might be reverted):
    darc trigger-subscription --force --id <subscriptionId>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe it's more readable without all those \n and ",?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@adamzip my suggestion also had this part at your own risk (some PR commits might be reverted). Maybe we should keep that?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I also had the commands on their own line so they are easier to copy (3 mouse clicks)

Comment thread src/Microsoft.DotNet.Darc/DarcLib/VirtualMonoRepo/VmrCodeflower.cs Outdated
premun
premun previously approved these changes Sep 3, 2025
@adamzip adamzip merged commit ee1c036 into dotnet:main Sep 3, 2025
9 checks passed
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.

4 participants