Skip to content

Commit

Permalink
Show associated PRS and associated reviews in review page (#5417)
Browse files Browse the repository at this point in the history
  • Loading branch information
chidozieononiwu authored Feb 13, 2023
1 parent 2c09d93 commit 92c4c76
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/dotnet/APIView/APIViewWeb/Client/src/pages/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,14 +485,12 @@ $(() => {
});

// Manage Expand / Collapse State of options
[$("#approveCollapse"), $("#requestReviewersCollapse"), $("#reviewOptionsCollapse"), $("#pageSettingsCollapse")].forEach(function (value, index) {
[$("#approveCollapse"), $("#requestReviewersCollapse"), $("#reviewOptionsCollapse"), $("#pageSettingsCollapse"), $("#associatedPRCollapse"), $("#associatedReviewsCollapse")].forEach(function (value, index) {
const id = value.attr("id");
value.on('hidden.bs.collapse', function () {
console.log(id);
document.cookie = `${id}=hidden; max-age=${7 * 24 * 60 * 60}`;
});
value.on('shown.bs.collapse', function () {
console.log(id);
document.cookie = `${id}=shown; max-age=${7 * 24 * 60 * 60}`;
});
});
Expand Down
5 changes: 5 additions & 0 deletions src/dotnet/APIView/APIViewWeb/Managers/IPullRequestManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using APIViewWeb.Models;

namespace APIViewWeb.Managers
{
Expand All @@ -8,5 +10,8 @@ public Task<string> DetectApiChanges(string buildId, string artifactName, string
string commitSha, string repoName, string packageName, int prNumber, string hostName, string codeFileName = null,
string baselineCodeFileName = null, bool commentOnPR = true, string language = null, string project = "public");
public Task CleanupPullRequestData();

public Task<IEnumerable<PullRequestModel>> GetPullRequestsModel(string reviewId);
public Task<IEnumerable<PullRequestModel>> GetPullRequestsModel(int pullRequestNumber, string repoName);
}
}
9 changes: 9 additions & 0 deletions src/dotnet/APIView/APIViewWeb/Managers/PullRequestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ public async Task CleanupPullRequestData()
}
}

public async Task<IEnumerable<PullRequestModel>> GetPullRequestsModel(string reviewId) {
return await _pullRequestsRepository.GetPullRequestsAsync(reviewId);
}

public async Task<IEnumerable<PullRequestModel>> GetPullRequestsModel(int pullRequestNumber, string repoName)
{
return await _pullRequestsRepository.GetPullRequestsAsync(pullRequestNumber, repoName);
}

private async Task CreateOrUpdateComment(List<PullRequestModel> prReviews, string repoOwner, string repoName, int prNumber, string hostName)
{
var existingComment = await GetExistingCommentForPackage(repoOwner, repoName, prNumber);
Expand Down
57 changes: 57 additions & 0 deletions src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,63 @@
</span>
</li>
</ul>
@if (Model.Review.FilterType == ReviewType.PullRequest)
{
var associatedPRs = await Model.GetAssociatedPullRequest();
@if (associatedPRs != null && associatedPRs.Count() > 0)
{
var associatedPRState = String.Empty;
if (Request.Cookies.ContainsKey("associatedPRCollapse"))
{
if (Request.Cookies["associatedPRCollapse"].Equals("shown"))
associatedPRState = " show";
}
<p class="h6">
<a data-bs-toggle="collapse" href="#associatedPRCollapse" aria-expanded="true" aria-controls="associatedPRCollapse">Associated Pull Requests&nbsp;&nbsp;<i class="fa-solid fa-ellipsis"></i></a>
</p>
<ul class="list-group collapse mb-3@(associatedPRState)" id="associatedPRCollapse">
@foreach (var prModel in associatedPRs)
{
var url = $"https://github.com/{prModel.RepoName}/pull/{prModel.PullRequestNumber}";
var txt = $"{prModel.RepoName}/{prModel.PullRequestNumber}";
<li class="list-group-item">
<a href="@url" target="_blank">@txt</a>
</li> }
</ul>
}
}
@if ((Model.Review.Language == "Swagger" || Model.Review.Language == "Cadl") &&
Model.Review.FilterType == ReviewType.PullRequest)
{
var prsOfAssociatedReviews = await Model.GetPRsOfAssoicatedReviews();
@if (prsOfAssociatedReviews != null && prsOfAssociatedReviews.Count() > 1)
{
var associatedReviewsState = String.Empty;
if (Request.Cookies.ContainsKey("associatedReviewsCollapse"))
{
if (Request.Cookies["associatedReviewsCollapse"].Equals("shown"))
associatedReviewsState = " show";
}
<p class="h6">
<a data-bs-toggle="collapse" href="#associatedReviewsCollapse" aria-expanded="true" aria-controls="associatedReviewsCollapse">Associated Reviews&nbsp;&nbsp;<i class="fa-solid fa-ellipsis"></i></a>
</p>
<ul class="list-group collapse mb-3@(associatedReviewsState)" id="associatedReviewsCollapse">
@foreach (var pr in prsOfAssociatedReviews)
{
if (pr.ReviewId != Model.Review.ReviewId)
{
var url = @Url.ActionLink("Review", "Assemblies", new
{
id = pr.ReviewId,
});
<li class="list-group-item">
<a href="@url" target="_blank">@(pr.Language ?? pr.ReviewId)</a>
</li>
}
}
</ul>
}
}
<p class="h6">
<a data-bs-toggle="collapse" href="#reviewOptionsCollapse" aria-expanded="true" aria-controls="approvalCollapse">Review Options&nbsp;&nbsp;<i class="fa-solid fa-ellipsis"></i></a>
</p>
Expand Down
15 changes: 15 additions & 0 deletions src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class ReviewPageModel : PageModel

private readonly IReviewManager _manager;

private readonly IPullRequestManager _pullRequestManager;

private readonly IBlobCodeFileRepository _codeFileRepository;

private readonly ICommentsManager _commentsManager;
Expand All @@ -39,6 +41,7 @@ public class ReviewPageModel : PageModel

public ReviewPageModel(
IReviewManager manager,
IPullRequestManager pullRequestManager,
IBlobCodeFileRepository codeFileRepository,
ICommentsManager commentsManager,
INotificationManager notificationManager,
Expand All @@ -47,6 +50,7 @@ public ReviewPageModel(
IConfiguration configuration)
{
_manager = manager;
_pullRequestManager = pullRequestManager;
_codeFileRepository = codeFileRepository;
_commentsManager = commentsManager;
_notificationManager = notificationManager;
Expand Down Expand Up @@ -277,6 +281,17 @@ public UserPreferenceModel GetUserPreference()
return _preferenceCache.GetUserPreferences(User).Result;
}

public async Task<IEnumerable<PullRequestModel>> GetAssociatedPullRequest()
{
return await _pullRequestManager.GetPullRequestsModel(Review.ReviewId);
}

public async Task<IEnumerable<PullRequestModel>> GetPRsOfAssoicatedReviews()
{
var creatingPR = (await _pullRequestManager.GetPullRequestsModel(Review.ReviewId)).FirstOrDefault();
return await _pullRequestManager.GetPullRequestsModel(creatingPR.PullRequestNumber, creatingPR.RepoName);;
}

private async Task GetReviewPageModelPropertiesAsync(string id, string revisionId = null, string diffRevisionId = null, bool diffOnly = false)
{
Review = await _manager.GetReviewAsync(User, id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public async Task<List<PullRequestModel>> GetPullRequestsAsync(int pullRequestNu
{
var query = $"SELECT * FROM PullRequests c WHERE c.PullRequestNumber = {pullRequestNumber} and c.RepoName = '{repoName}'";
return await GetPullRequestFromQueryAsync(query);
}

public async Task<IEnumerable<PullRequestModel>> GetPullRequestsAsync(string reviewId) {
var query = $"SELECT * FROM PullRequests c WHERE c.ReviewId = '{reviewId}'";
return await GetPullRequestFromQueryAsync(query);
}

private async Task<List<PullRequestModel>> GetPullRequestFromQueryAsync(string query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace APIViewWeb.Repositories
public interface ICosmosPullRequestsRepository
{
public Task<PullRequestModel> GetPullRequestAsync(int pullRequestNumber, string repoName, string packageName, string language = null);
public Task<IEnumerable<PullRequestModel>> GetPullRequestsAsync(string reviewId);
public Task UpsertPullRequestAsync(PullRequestModel pullRequestModel);
public Task<IEnumerable<PullRequestModel>> GetPullRequestsAsync(bool isOpen);
public Task<List<PullRequestModel>> GetPullRequestsAsync(int pullRequestNumber, string repoName);
Expand Down

0 comments on commit 92c4c76

Please sign in to comment.