diff --git a/src/dotnet/APIView/APIViewWeb/Client/src/pages/review.ts b/src/dotnet/APIView/APIViewWeb/Client/src/pages/review.ts index f3600faf446..10dfda6184e 100644 --- a/src/dotnet/APIView/APIViewWeb/Client/src/pages/review.ts +++ b/src/dotnet/APIView/APIViewWeb/Client/src/pages/review.ts @@ -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}`; }); }); diff --git a/src/dotnet/APIView/APIViewWeb/Managers/IPullRequestManager.cs b/src/dotnet/APIView/APIViewWeb/Managers/IPullRequestManager.cs index 15ef8e785fe..eaa714555d0 100644 --- a/src/dotnet/APIView/APIViewWeb/Managers/IPullRequestManager.cs +++ b/src/dotnet/APIView/APIViewWeb/Managers/IPullRequestManager.cs @@ -1,4 +1,6 @@ +using System.Collections.Generic; using System.Threading.Tasks; +using APIViewWeb.Models; namespace APIViewWeb.Managers { @@ -8,5 +10,8 @@ public Task 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> GetPullRequestsModel(string reviewId); + public Task> GetPullRequestsModel(int pullRequestNumber, string repoName); } } diff --git a/src/dotnet/APIView/APIViewWeb/Managers/PullRequestManager.cs b/src/dotnet/APIView/APIViewWeb/Managers/PullRequestManager.cs index 6976d5a00ea..5ade2b90b3e 100644 --- a/src/dotnet/APIView/APIViewWeb/Managers/PullRequestManager.cs +++ b/src/dotnet/APIView/APIViewWeb/Managers/PullRequestManager.cs @@ -178,6 +178,15 @@ public async Task CleanupPullRequestData() } } + public async Task> GetPullRequestsModel(string reviewId) { + return await _pullRequestsRepository.GetPullRequestsAsync(reviewId); + } + + public async Task> GetPullRequestsModel(int pullRequestNumber, string repoName) + { + return await _pullRequestsRepository.GetPullRequestsAsync(pullRequestNumber, repoName); + } + private async Task CreateOrUpdateComment(List prReviews, string repoOwner, string repoName, int prNumber, string hostName) { var existingComment = await GetExistingCommentForPackage(repoOwner, repoName, prNumber); diff --git a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml index 7df02541739..117bd6c2e64 100644 --- a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml +++ b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml @@ -204,6 +204,63 @@ + @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"; + } +

+ Associated Pull Requests   +

+
    + @foreach (var prModel in associatedPRs) + { + var url = $"https://github.com/{prModel.RepoName}/pull/{prModel.PullRequestNumber}"; + var txt = $"{prModel.RepoName}/{prModel.PullRequestNumber}"; +
  • + @txt +
  • } +
+ } + } + @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"; + } +

+ Associated Reviews   +

+
    + @foreach (var pr in prsOfAssociatedReviews) + { + if (pr.ReviewId != Model.Review.ReviewId) + { + var url = @Url.ActionLink("Review", "Assemblies", new + { + id = pr.ReviewId, + }); +
  • + @(pr.Language ?? pr.ReviewId) +
  • + } + } +
+ } + }

Review Options  

diff --git a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs index 549d1abff60..b5475c2f442 100644 --- a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs +++ b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs @@ -25,6 +25,8 @@ public class ReviewPageModel : PageModel private readonly IReviewManager _manager; + private readonly IPullRequestManager _pullRequestManager; + private readonly IBlobCodeFileRepository _codeFileRepository; private readonly ICommentsManager _commentsManager; @@ -39,6 +41,7 @@ public class ReviewPageModel : PageModel public ReviewPageModel( IReviewManager manager, + IPullRequestManager pullRequestManager, IBlobCodeFileRepository codeFileRepository, ICommentsManager commentsManager, INotificationManager notificationManager, @@ -47,6 +50,7 @@ public ReviewPageModel( IConfiguration configuration) { _manager = manager; + _pullRequestManager = pullRequestManager; _codeFileRepository = codeFileRepository; _commentsManager = commentsManager; _notificationManager = notificationManager; @@ -277,6 +281,17 @@ public UserPreferenceModel GetUserPreference() return _preferenceCache.GetUserPreferences(User).Result; } + public async Task> GetAssociatedPullRequest() + { + return await _pullRequestManager.GetPullRequestsModel(Review.ReviewId); + } + + public async Task> 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); diff --git a/src/dotnet/APIView/APIViewWeb/Repositories/CosmosPullRequestsRepository.cs b/src/dotnet/APIView/APIViewWeb/Repositories/CosmosPullRequestsRepository.cs index 00c2cbe5869..b20da7021f4 100644 --- a/src/dotnet/APIView/APIViewWeb/Repositories/CosmosPullRequestsRepository.cs +++ b/src/dotnet/APIView/APIViewWeb/Repositories/CosmosPullRequestsRepository.cs @@ -50,6 +50,11 @@ public async Task> GetPullRequestsAsync(int pullRequestNu { var query = $"SELECT * FROM PullRequests c WHERE c.PullRequestNumber = {pullRequestNumber} and c.RepoName = '{repoName}'"; return await GetPullRequestFromQueryAsync(query); + } + + public async Task> GetPullRequestsAsync(string reviewId) { + var query = $"SELECT * FROM PullRequests c WHERE c.ReviewId = '{reviewId}'"; + return await GetPullRequestFromQueryAsync(query); } private async Task> GetPullRequestFromQueryAsync(string query) diff --git a/src/dotnet/APIView/APIViewWeb/Repositories/ICosmosPullRequestsRepository.cs b/src/dotnet/APIView/APIViewWeb/Repositories/ICosmosPullRequestsRepository.cs index f4d22dc2a0d..d4e0fa09af0 100644 --- a/src/dotnet/APIView/APIViewWeb/Repositories/ICosmosPullRequestsRepository.cs +++ b/src/dotnet/APIView/APIViewWeb/Repositories/ICosmosPullRequestsRepository.cs @@ -7,6 +7,7 @@ namespace APIViewWeb.Repositories public interface ICosmosPullRequestsRepository { public Task GetPullRequestAsync(int pullRequestNumber, string repoName, string packageName, string language = null); + public Task> GetPullRequestsAsync(string reviewId); public Task UpsertPullRequestAsync(PullRequestModel pullRequestModel); public Task> GetPullRequestsAsync(bool isOpen); public Task> GetPullRequestsAsync(int pullRequestNumber, string repoName);