From 14d3ebc47ffa5d6bd1059d601463d56493eb00b5 Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Tue, 28 Sep 2021 13:46:27 -0400 Subject: [PATCH 1/4] Pass package name from calling pipeline to uniquely identify pull request review --- eng/common/scripts/Detect-Api-Changes.ps1 | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/eng/common/scripts/Detect-Api-Changes.ps1 b/eng/common/scripts/Detect-Api-Changes.ps1 index 37521017179..115c6eaf8a7 100644 --- a/eng/common/scripts/Detect-Api-Changes.ps1 +++ b/eng/common/scripts/Detect-Api-Changes.ps1 @@ -16,7 +16,7 @@ Param ( ) # Submit API review request and return status whether current revision is approved or pending or failed to create review -function Submit-Request($filePath) +function Submit-Request($filePath, $packageName) { $repoName = $RepoFullName if (!$repoName) { @@ -29,6 +29,7 @@ function Submit-Request($filePath) $query.Add('commitSha', $CommitSha) $query.Add('repoName', $repoName) $query.Add('pullRequestNumber', $PullRequestNumber) + $query.Add('packageName', $packageName) $uri = [System.UriBuilder]$APIViewUri $uri.query = $query.toString() Write-Host "Request URI: $($uri.Uri.OriginalString)" @@ -71,6 +72,7 @@ function Log-Input-Params() Write-Host "Language: $($Language)" Write-Host "Commit SHA: $($CommitSha)" Write-Host "Repo Name: $($RepoFullName)" + Write-Host "Package Name: $($PackageName)" } . (Join-Path $PSScriptRoot common.ps1) @@ -95,7 +97,7 @@ foreach ($artifact in $ArtifactList) if (Should-Process-Package -pkgPath $pkgPath -packageName $artifact.name) { $filePath = $pkgPath.Replace($ArtifactPath , "").Replace("\", "/") - $respCode = Submit-Request -filePath $filePath + $respCode = Submit-Request -filePath $filePath -packageName $artifact.name if ($respCode -ne '200') { $responses[$artifact.name] = $respCode @@ -108,12 +110,7 @@ foreach ($artifact in $ArtifactList) } } -if ($responses) +foreach($pkg in $responses.keys) { - # Will update this with a link to wiki on how to resolve - Write-Warning "API change detection failed for following packages. Please check above for package level error details." - foreach($pkg in $responses.keys) - { - Write-Host "$pkg failed with $($responses[$pkg]) code" - } + Write-Host "API detectiopn request status for $pkg: $($responses[$pkg])" } From bb946d0c7f4a23b3072d16760f2d49842056c29a Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Tue, 28 Sep 2021 14:23:42 -0400 Subject: [PATCH 2/4] Add new query param for Package name and store it in cosmos --- .../APIViewWeb/Controllers/PullRequestController.cs | 5 +++-- src/dotnet/APIView/APIViewWeb/Models/PullRequestModel.cs | 1 + .../Repositories/CosmosPullRequestsRepository.cs | 4 ++-- .../APIView/APIViewWeb/Repositories/PullRequestManager.cs | 7 ++++--- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/dotnet/APIView/APIViewWeb/Controllers/PullRequestController.cs b/src/dotnet/APIView/APIViewWeb/Controllers/PullRequestController.cs index 5cbcd9a1c33..458e583d038 100644 --- a/src/dotnet/APIView/APIViewWeb/Controllers/PullRequestController.cs +++ b/src/dotnet/APIView/APIViewWeb/Controllers/PullRequestController.cs @@ -30,14 +30,15 @@ public async Task DetectApiChanges( string filePath, int pullRequestNumber, string commitSha, - string repoName) + string repoName, + string packageName) { if (!ValidateInputParams()) { return StatusCode(StatusCodes.Status400BadRequest); } - await _pullRequestManager.DetectApiChanges(buildId, artifactName, filePath, pullRequestNumber, commitSha, repoName); + await _pullRequestManager.DetectApiChanges(buildId, artifactName, filePath, pullRequestNumber, commitSha, repoName, packageName); return Ok(); } diff --git a/src/dotnet/APIView/APIViewWeb/Models/PullRequestModel.cs b/src/dotnet/APIView/APIViewWeb/Models/PullRequestModel.cs index 1263ea405d9..5b97d621c1f 100644 --- a/src/dotnet/APIView/APIViewWeb/Models/PullRequestModel.cs +++ b/src/dotnet/APIView/APIViewWeb/Models/PullRequestModel.cs @@ -17,5 +17,6 @@ public class PullRequestModel public bool IsOpen { get; set; } = true; public string ReviewId { get; set; } public string Author { get; set; } + public string PackageName { get; set; } } } \ No newline at end of file diff --git a/src/dotnet/APIView/APIViewWeb/Repositories/CosmosPullRequestsRepository.cs b/src/dotnet/APIView/APIViewWeb/Repositories/CosmosPullRequestsRepository.cs index 082c44b6df6..2b7ce92fdc2 100644 --- a/src/dotnet/APIView/APIViewWeb/Repositories/CosmosPullRequestsRepository.cs +++ b/src/dotnet/APIView/APIViewWeb/Repositories/CosmosPullRequestsRepository.cs @@ -19,9 +19,9 @@ public CosmosPullRequestsRepository(IConfiguration configuration) _pullRequestsContainer = client.GetContainer("APIView", "PullRequests"); } - public async Task GetPullRequestAsync(int pullRequestNumber, string repoName, string filePath) + public async Task GetPullRequestAsync(int pullRequestNumber, string repoName, string packageName) { - var query = $"SELECT * FROM PullRequests c WHERE c.PullRequestNumber = {pullRequestNumber} and c.RepoName = '{repoName}' and c.FilePath = '{filePath}'"; + var query = $"SELECT * FROM PullRequests c WHERE c.PullRequestNumber = {pullRequestNumber} and c.RepoName = '{repoName}' and c.PackageName = '{packageName}'"; return await GetPullRequestFromQueryAsync(query); } diff --git a/src/dotnet/APIView/APIViewWeb/Repositories/PullRequestManager.cs b/src/dotnet/APIView/APIViewWeb/Repositories/PullRequestManager.cs index 9d9739ddb85..6689b2a3cd1 100644 --- a/src/dotnet/APIView/APIViewWeb/Repositories/PullRequestManager.cs +++ b/src/dotnet/APIView/APIViewWeb/Repositories/PullRequestManager.cs @@ -60,14 +60,14 @@ IConfiguration configuration } // API change detection for PR will pull artifact from devops artifact - public async Task DetectApiChanges(string buildId, string artifactName, string filePath, int prNumber, string commitSha, string repoName) + public async Task DetectApiChanges(string buildId, string artifactName, string filePath, int prNumber, string commitSha, string repoName, string packageName) { var requestTelemetry = new RequestTelemetry { Name = "Detecting API changes for PR: " + prNumber }; var operation = _telemetryClient.StartOperation(requestTelemetry); try { string[] repoInfo = repoName.Split("/"); - var pullRequestModel = await _pullRequestsRepository.GetPullRequestAsync(prNumber, repoName, filePath); + var pullRequestModel = await _pullRequestsRepository.GetPullRequestAsync(prNumber, repoName, packageName); if (pullRequestModel == null) { var issue = await _githubClient.Issue.Get(repoInfo[0], repoInfo[1], prNumber); @@ -76,7 +76,8 @@ public async Task DetectApiChanges(string buildId, string artifactName, string f RepoName = repoName, PullRequestNumber = prNumber, FilePath = filePath, - Author = issue.User.Login + Author = issue.User.Login, + PackageName = packageName }; } else From aaa91c138eacc7e3fc7fa501062cb7d8cb657979 Mon Sep 17 00:00:00 2001 From: praveenkuttappan Date: Tue, 28 Sep 2021 14:52:22 -0400 Subject: [PATCH 3/4] Update log summary --- eng/common/scripts/Detect-Api-Changes.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/scripts/Detect-Api-Changes.ps1 b/eng/common/scripts/Detect-Api-Changes.ps1 index 115c6eaf8a7..257ea37c4f5 100644 --- a/eng/common/scripts/Detect-Api-Changes.ps1 +++ b/eng/common/scripts/Detect-Api-Changes.ps1 @@ -112,5 +112,5 @@ foreach ($artifact in $ArtifactList) foreach($pkg in $responses.keys) { - Write-Host "API detectiopn request status for $pkg: $($responses[$pkg])" + Write-Host "API detectiopn request status for $($pkg) : $($responses[$pkg])" } From 0764207ab9093d2c1d3eefb4acc42fad946d7d21 Mon Sep 17 00:00:00 2001 From: praveenkuttappan <55455725+praveenkuttappan@users.noreply.github.com> Date: Tue, 28 Sep 2021 15:53:04 -0400 Subject: [PATCH 4/4] Update eng/common/scripts/Detect-Api-Changes.ps1 Co-authored-by: Wes Haggard --- eng/common/scripts/Detect-Api-Changes.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/scripts/Detect-Api-Changes.ps1 b/eng/common/scripts/Detect-Api-Changes.ps1 index 257ea37c4f5..3c88398ce55 100644 --- a/eng/common/scripts/Detect-Api-Changes.ps1 +++ b/eng/common/scripts/Detect-Api-Changes.ps1 @@ -112,5 +112,5 @@ foreach ($artifact in $ArtifactList) foreach($pkg in $responses.keys) { - Write-Host "API detectiopn request status for $($pkg) : $($responses[$pkg])" + Write-Host "API detection request status for $($pkg) : $($responses[$pkg])" }