Skip to content

Commit 7561385

Browse files
committed
[BUGFIX] Azdo client fetches wrong branch's SHA
TargetBranchCommitSha was erroneously called "target branch" because it represents the branch in the codeflow that belongs to the `target` repo. Howevever, in practice it is actually the PR Head branch. Therefore it is now renamed to HeadBranchCommitSha. Furthermore, setting HeadBRanchCommitSha is fixed in the Azdo client.
1 parent 83c2628 commit 7561385

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

src/Microsoft.DotNet.Darc/DarcLib/AzureDevOpsClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public async Task<PullRequest> GetPullRequestAsync(string pullRequestUrl)
344344
_ => PrStatus.None,
345345
},
346346
UpdatedAt = DateTimeOffset.UtcNow,
347-
TargetBranchCommitSha = pr.LastMergeTargetCommit.CommitId,
347+
HeadBranchCommitSha = pr.LastMergeSourceCommit.CommitId,
348348
};
349349
}
350350

src/Microsoft.DotNet.Darc/DarcLib/Models/PullRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ public class PullRequest
1212
public string HeadBranch { get; set; }
1313
public PrStatus Status { get; set; }
1414
public DateTimeOffset UpdatedAt { get; set; }
15-
public string TargetBranchCommitSha { get; set; }
15+
public string HeadBranchCommitSha { get; set; }
1616
}

src/ProductConstructionService/ProductConstructionService.DependencyFlow/PullRequestUpdater.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,11 @@ private async Task<MergePolicyCheckResult> TryMergingPrAsync(
414414
PullRequestUpdateSummary prSummary = CreatePrSummaryFromInProgressPr(pr, targetRepository);
415415
MergePolicyEvaluationResults? cachedResults = await _mergePolicyEvaluationState.TryGetStateAsync();
416416

417-
IEnumerable<MergePolicyEvaluationResult> updatedMergePolicyResults = await _mergePolicyEvaluator.EvaluateAsync(prSummary, remote, policyDefinitions, cachedResults, prInfo.TargetBranchCommitSha);
417+
IEnumerable<MergePolicyEvaluationResult> updatedMergePolicyResults = await _mergePolicyEvaluator.EvaluateAsync(prSummary, remote, policyDefinitions, cachedResults, prInfo.HeadBranchCommitSha);
418418

419419
MergePolicyEvaluationResults updatedResult = new MergePolicyEvaluationResults(
420420
updatedMergePolicyResults.ToImmutableList(),
421-
prInfo.TargetBranchCommitSha);
421+
prInfo.HeadBranchCommitSha);
422422

423423
await _mergePolicyEvaluationState.SetAsync(updatedResult);
424424

test/ProductConstructionService.DependencyFlow.Tests/PullRequestUpdaterTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ protected IDisposable WithExistingCodeFlowPullRequest(
466466
Status = prStatus,
467467
HeadBranch = InProgressPrHeadBranch,
468468
BaseBranch = TargetBranch,
469-
TargetBranchCommitSha = "sha123456",
469+
HeadBranchCommitSha = "sha123456",
470470
});
471471

472472
if (willFlowNewBuild

0 commit comments

Comments
 (0)