Skip to content

Persist the base commit of subscription update for diff links #4870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1111,25 +1111,27 @@ private async Task UpdateCodeFlowPullRequestAsync(
IRemote remote = await _remoteFactory.CreateRemoteAsync(subscription.TargetRepository);
var build = await _sqlClient.GetBuildAsync(update.BuildId);

string? baseSourceSha= pullRequest.ContainedSubscriptions.FirstOrDefault(u => u.SubscriptionId.Equals(update.SubscriptionId))?.BaseSourceSha
?? previousSourceSha;
pullRequest.ContainedSubscriptions.RemoveAll(s => s.SubscriptionId.Equals(update.SubscriptionId));
pullRequest.ContainedSubscriptions.Add(new SubscriptionPullRequestUpdate
{
SubscriptionId = update.SubscriptionId,
BuildId = update.BuildId,
SourceRepo = update.SourceRepo,
CommitSha = update.SourceSha
CommitSha = update.SourceSha,
BaseSourceSha = baseSourceSha,
});

pullRequest.RequiredUpdates = MergeExistingWithIncomingUpdates(pullRequest.RequiredUpdates, newDependencyUpdates);

var title = _pullRequestBuilder.GenerateCodeFlowPRTitle(
subscription.TargetBranch,
pullRequest.ContainedSubscriptions.Select(s => s.SourceRepo).ToList());

var description = _pullRequestBuilder.GenerateCodeFlowPRDescription(
update,
build,
previousSourceSha,
baseSourceSha,
pullRequest.RequiredUpdates,
prInfo?.Description,
isForwardFlow: isForwardFlow);
Expand Down Expand Up @@ -1213,7 +1215,8 @@ private async Task<InProgressPullRequest> CreateCodeFlowPullRequestAsync(
SubscriptionId = update.SubscriptionId,
BuildId = update.BuildId,
SourceRepo = update.SourceRepo,
CommitSha = update.SourceSha
CommitSha = update.SourceSha,
BaseSourceSha = previousSourceSha,
}
],
RequiredUpdates = requiredUpdates,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ public class SubscriptionPullRequestUpdate

[DataMember]
public string CommitSha { get; set; }

Copy link
Preview

Copilot AI May 22, 2025

Choose a reason for hiding this comment

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

[nitpick] Add XML documentation for BaseSourceSha explaining that it holds the original base commit SHA used for generating diffs.

Suggested change
/// <summary>
/// Gets or sets the original base commit SHA used for generating diffs.
/// </summary>

Copilot uses AI. Check for mistakes.

Copy link
Member

Choose a reason for hiding this comment

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

This would be nice to add

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a bit difficult to describe. I'm thinking "The earliest commit in the source repository from the changes contained in the current PR".
While writing this, I realize that this property is a bit out of place - technically, SubscriptionPullRequestUpdate shouldn't depend on any PR state - it only represents a single subscription update (i.e. changes from one subscription trigger), while BaseSourceSha only makes sense in the context of the PR

Copy link
Member

Choose a reason for hiding this comment

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

That's a good point. Why isn't it in the InProgressPullRequest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll change it

[DataMember]
/// <summary>
/// The earliest commit in the source repository from the changes contained in the current PR
/// </summary>
public string BaseSourceSha { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected override void RegisterServices(IServiceCollection services)
services.AddSingleton(_forwardFlower.Object);
services.AddSingleton(_gitClient.Object);

CodeFlowResult codeFlowRes = new CodeFlowResult(true, [], new NativePath(VmrPath), "aaa1234", []);
CodeFlowResult codeFlowRes = new CodeFlowResult(true, [], new NativePath(VmrPath), "base_codeflow_sha_123", []);
_forwardFlower.SetReturnsDefault(Task.FromResult(codeFlowRes));
_backFlower.SetReturnsDefault(Task.FromResult(codeFlowRes));
_gitClient.SetReturnsDefault(Task.CompletedTask);
Expand Down Expand Up @@ -623,7 +623,8 @@ protected InProgressPullRequest CreatePullRequestState(
BuildId = forBuild.Id,
SubscriptionId = Subscription.Id,
SourceRepo = forBuild.GetRepository(),
CommitSha = forBuild.Commit
CommitSha = forBuild.Commit,
BaseSourceSha = Subscription.SourceEnabled ? "base_codeflow_sha_123" : null,
}
],
RequiredUpdates = forBuild.Assets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public async Task UpdateWithNoExistingState()
SubscriptionId = Subscription.Id,
BuildId = build.Id,
SourceRepo = build.GetRepository(),
CommitSha = build.Commit
CommitSha = build.Commit,
BaseSourceSha = "base_codeflow_sha_123",
}
],
RequiredUpdates = [],
Expand Down Expand Up @@ -178,7 +179,8 @@ public async Task UpdateWithManuallyMergedPrAndNewBuild()
SubscriptionId = Subscription.Id,
BuildId = build2.Id,
SourceRepo = build.GetRepository(),
CommitSha = build2.Commit
CommitSha = build2.Commit,
BaseSourceSha = "base_codeflow_sha_123"
}
],
RequiredUpdates = [],
Expand Down