Skip to content

Commit

Permalink
Pass package name from calling pipeline to uniquely identify pull req… (
Browse files Browse the repository at this point in the history
#2046)

Currently file name is used to query API review document from cosmos DB within same PR. But .Net file path is different across each build due to generated version number for each build. This PR will submit a package name to API view to be used in query.
  • Loading branch information
praveenkuttappan authored Sep 29, 2021
1 parent 4849d89 commit 321d650
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
15 changes: 6 additions & 9 deletions eng/common/scripts/Detect-Api-Changes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)"
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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 detection request status for $($pkg) : $($responses[$pkg])"
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ public async Task<ActionResult> 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();
}

Expand Down
1 change: 1 addition & 0 deletions src/dotnet/APIView/APIViewWeb/Models/PullRequestModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public CosmosPullRequestsRepository(IConfiguration configuration)
_pullRequestsContainer = client.GetContainer("APIView", "PullRequests");
}

public async Task<PullRequestModel> GetPullRequestAsync(int pullRequestNumber, string repoName, string filePath)
public async Task<PullRequestModel> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 321d650

Please sign in to comment.