Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass package name from calling pipeline to uniquely identify pull req… #2046

Merged
4 commits merged into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 detectiopn request status for $($pkg) : $($responses[$pkg])"
praveenkuttappan marked this conversation as resolved.
Show resolved Hide resolved
}
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will work for most cases but something to consider for Java is that packageName is often artifactId and groupId. So when testing in Java we may hit a conflict but it should only ever happen if we mix track 1 and track 2 libraries but currently we only support track 2 so shouldn't be an issue. Just something to keep in the back of your mind.

{
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