Skip to content

Make sure comment about conflicts is sent always#4882

Merged
premun merged 5 commits intodotnet:mainfrom
premun:prvysoky/conflict-comment
May 28, 2025
Merged

Make sure comment about conflicts is sent always#4882
premun merged 5 commits intodotnet:mainfrom
premun:prvysoky/conflict-comment

Conversation

@premun
Copy link
Copy Markdown
Member

@premun premun commented May 23, 2025

Resolves #4854

Copilot AI review requested due to automatic review settings May 23, 2025 13:53
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 ensures that a comment about conflicts is always sent by updating conflict exception handling throughout the codebase. Key changes include updating exception constructors to accept error strings from StandardError, refactoring property names from FilesInConflict to ConflictedFiles, and removing conditional checks that prevented notification when no version files conflicted.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/ProductConstructionService.DependencyFlow.Tests/PullRequestUpdaterTests.cs Updated test to reflect changes in exception constructor parameters.
src/ProductConstructionService/ProductConstructionService.DependencyFlow/PullRequestConflictNotifier.cs Adjusted property name usage and removed early exits to always send conflict notifications.
src/Microsoft.DotNet.Darc/DarcLib/VirtualMonoRepo/VmrForwardFlower.cs Updated exception throwing to use StandardError for conflict details.
src/Microsoft.DotNet.Darc/DarcLib/VirtualMonoRepo/VmrBackflower.cs Made similar adjustments for conflict exception handling in backflow scenarios.
src/Microsoft.DotNet.Darc/DarcLib/VirtualMonoRepo/Exceptions.cs Refactored ConflictInPrBranchException with updated parsing logic and new collection expressions.
src/Microsoft.DotNet.Darc/DarcLib/Helpers/ProcessExecutionResult.cs Replaced generic Exception with a custom ProcessFailedException for improved error reporting.
Comments suppressed due to low confidence (8)

test/ProductConstructionService.DependencyFlow.Tests/PullRequestUpdaterTests.cs:506

  • Ensure the provided error message pattern in the new constructor accurately captures all expected conflict messages, as this replaces the previous gitMergeResult parameter.
.Throws(() => new ConflictInPrBranchException(

src/ProductConstructionService/ProductConstructionService.DependencyFlow/PullRequestConflictNotifier.cs:66

  • Update the loop to use the new property 'ConflictedFiles' and verify that all references to conflicting files are consistent with this change.
foreach (var file in conflictException.ConflictedFiles)

src/Microsoft.DotNet.Darc/DarcLib/VirtualMonoRepo/VmrForwardFlower.cs:225

  • Using 'e.Result.StandardError' aligns with the updated exception constructor; please confirm that 'StandardError' reliably contains the complete error details needed for conflict parsing.
throw new ConflictInPrBranchException(e.Result.StandardError, targetBranch, mapping.Name, isForwardFlow: true);

src/Microsoft.DotNet.Darc/DarcLib/VirtualMonoRepo/VmrBackflower.cs:243

  • Confirm that passing 'e.Result.StandardError' for backflow scenarios provides sufficient error details for accurate conflict reporting.
throw new ConflictInPrBranchException(e.Result.StandardError, targetBranch, mapping.Name, isForwardFlow: false);

src/Microsoft.DotNet.Darc/DarcLib/VirtualMonoRepo/VmrBackflower.cs:280

  • Ensure that catching ProcessFailedException and rethrowing as ConflictInPrBranchException preserves all necessary error details for troubleshooting merge conflicts.
throw new ConflictInPrBranchException(e.ExecutionResult.StandardError, targetBranch, mapping.Name, isForwardFlow: false);

src/Microsoft.DotNet.Darc/DarcLib/VirtualMonoRepo/Exceptions.cs:88

  • Ensure all file paths processed here have at least three segments to avoid potential index out-of-range errors during the split operation.
return [..filesInConflict.Select(file => file.Split('/', 3)[2]).Distinct()];

src/Microsoft.DotNet.Darc/DarcLib/VirtualMonoRepo/Exceptions.cs:93

  • Review the file path normalization logic to ensure it fully meets expected formats for all backflow conflict cases.
return [..filesInConflict.Distinct().Select(file => $"src/{mappingName}/{file}")];

src/Microsoft.DotNet.Darc/DarcLib/Helpers/ProcessExecutionResult.cs:21

  • The change to a custom ProcessFailedException improves error reporting; ensure that all consumers of ProcessExecutionResult are updated to handle this new exception type appropriately.
throw new ProcessFailedException(this, failureMessage);

{
await workBranch.MergeBackAsync(commitMessage);
}
catch (ProcessFailedException e) when (headBranchExisted && e.ExecutionResult.StandardError.Contains("CONFLICT (content): Merge conflict"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there no better way to find that we are in this situation than matching hardcoded strings?
Would it be possible to use LibGit2Sharp to recognize that a merge conflict occurred while running git merge?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

LibGit2Sharp would just fail and not tell us any details. It only returns a MergeResult.Conflicts. The merge can fail for more reasons and since there's no special exit code from git, we do have to parse the outputs unfortunately.

premun added 2 commits May 27, 2025 16:11
# Conflicts:
#	src/ProductConstructionService/ProductConstructionService.DependencyFlow/PullRequestConflictNotifier.cs
@premun premun requested a review from adamzip May 28, 2025 10:30
@premun premun merged commit 5c93b29 into dotnet:main May 28, 2025
9 checks passed
@premun premun deleted the prvysoky/conflict-comment branch May 28, 2025 14:15
premun added a commit to premun/arcade-services that referenced this pull request May 30, 2025
Another code path that was omitted in dotnet#4882 and which did not post a comment here: dotnet/runtime#115833
premun added a commit that referenced this pull request May 31, 2025
This PR does the same as
#4882 where another code
path was omitted and which did not post a comment here:
dotnet/runtime#115833

#4854
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.

PCS does not always drop the "PR has a conflict" comment

3 participants