Skip to content

Commit

Permalink
Exclude any API reviews no longer affected by PR (#7641)
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenkuttappan authored Feb 14, 2024
1 parent 25f60c3 commit c34b5ab
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ await ManagerHelpers.AssertPullRequestCreatorPermission(prModel: pullRequestMode
//Generate combined single comment to update on PR or add a comment stating no API changes.
if (commentOnPR)
{
await _pullRequestManager.CreateOrUpdateCommentsOnPR(pullRequests, repoInfo[0], repoInfo[1], prNumber, hostName);
await _pullRequestManager.CreateOrUpdateCommentsOnPR(pullRequests, repoInfo[0], repoInfo[1], prNumber, hostName, commitSha);
}
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface IPullRequestManager
public Task<IEnumerable<PullRequestModel>> GetPullRequestsModelAsync(string reviewId, string apiRevisionId = null);
public Task<IEnumerable<PullRequestModel>> GetPullRequestsModelAsync(int pullRequestNumber, string repoName);
public Task<PullRequestModel> GetPullRequestModelAsync(int prNumber, string repoName, string packageName, string originalFile, string language);
public Task CreateOrUpdateCommentsOnPR(List<PullRequestModel> pullRequests, string repoOwner, string repoName, int prNumber, string hostName);
public Task CreateOrUpdateCommentsOnPR(List<PullRequestModel> pullRequests, string repoOwner, string repoName, int prNumber, string hostName, string commitSha);
public Task CleanupPullRequestData();
}
}
6 changes: 4 additions & 2 deletions src/dotnet/APIView/APIViewWeb/Managers/PullRequestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,17 @@ public async Task<PullRequestModel> GetPullRequestModelAsync(int prNumber, strin
return pullRequestModel;
}

public async Task CreateOrUpdateCommentsOnPR(List<PullRequestModel> pullRequests, string repoOwner, string repoName, int prNumber, string hostName)
public async Task CreateOrUpdateCommentsOnPR(List<PullRequestModel> pullRequests, string repoOwner, string repoName, int prNumber, string hostName, string commitSha)
{
var existingComment = await GetExistingCommentForPackage(repoOwner, repoName, prNumber);
var bldr = new StringBuilder(PR_APIVIEW_BOT_COMMENT_IDENTIFIER);
bldr.Append(Environment.NewLine).Append(Environment.NewLine);
if (pullRequests.Count > 0)
{
bldr.Append(PR_APIVIEW_BOT_COMMENT).Append(Environment.NewLine).Append(Environment.NewLine);
foreach (var p in pullRequests)
// Include API review revisions generated with same exact Commit Sha as latest commit SHA to exclude any stale reviews that are not modified in latest commit.
// This will ensure comment shows only the reviews modified byu latest commit.
foreach (var p in pullRequests.Where(p => p.Commits.LastOrDefault() == commitSha))
{
var revisionLink = ManagerHelpers.ResolveReviewUrl(pullRequest: p, hostName: hostName);
bldr.Append('[').Append(p.PackageName).Append("](").Append(revisionLink).Append(')');
Expand Down

0 comments on commit c34b5ab

Please sign in to comment.