Skip to content

Commit 0d9758f

Browse files
committed
Modify Scenario Test to check tagged pull requests
1 parent 51f5493 commit 0d9758f

File tree

3 files changed

+65
-10
lines changed

3 files changed

+65
-10
lines changed

test/ProductConstructionService.ScenarioTests/CodeFlowScenarioTestBase.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ protected async Task<PullRequest> CheckForwardFlowGitHubPullRequest(
1919
string targetRepoName,
2020
string targetBranch,
2121
string[] testFiles,
22-
Dictionary<string, string> testFilePatches)
22+
Dictionary<string, string> testFilePatches,
23+
PullRequestCleanupOperation cleanupOperation = PullRequestCleanupOperation.Close)
2324
{
2425
// When we expect updates from multiple repos (batchable subscriptions), we need to wait until the PR gets updated with the second repository after it is created
2526
// Otherwise it might try to validate the contents before all updates are in place
2627
PullRequest pullRequest = repoUpdates.Length > 1
2728
? await WaitForUpdatedPullRequestAsync(targetRepoName, targetBranch)
2829
: await WaitForPullRequestAsync(targetRepoName, targetBranch);
2930

30-
await using (CleanUpPullRequestAfter(TestParameters.GitHubTestOrg, targetRepoName, pullRequest))
31+
await using (CleanUpPullRequestAfter(TestParameters.GitHubTestOrg, targetRepoName, pullRequest, cleanupOperation))
3132
{
3233
IReadOnlyList<PullRequestFile> files = await GitHubApi.PullRequest.Files(
3334
TestParameters.GitHubTestOrg,
@@ -200,9 +201,10 @@ public async Task<PullRequest> WaitForPullRequestComment(
200201
string targetRepo,
201202
string targetBranch,
202203
string partialComment,
204+
ItemStateFilter prState = ItemStateFilter.Open,
203205
int attempts = 40)
204206
{
205-
PullRequest pullRequest = await WaitForPullRequestAsync(targetRepo, targetBranch);
207+
PullRequest pullRequest = await WaitForPullRequestAsync(targetRepo, targetBranch, prState);
206208

207209
while (attempts-- > 0)
208210
{

test/ProductConstructionService.ScenarioTests/ScenarioTestBase.cs

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
using Microsoft.DotNet.DarcLib.Models.AzureDevOps;
1313
using Microsoft.DotNet.DarcLib.Models.Darc;
1414
using Microsoft.DotNet.Internal.Testing.Utility;
15+
using Microsoft.DotNet.ProductConstructionService.Client;
16+
using Microsoft.DotNet.ProductConstructionService.Client.Models;
1517
using Microsoft.Extensions.Logging;
1618
using Newtonsoft.Json.Linq;
1719
using NuGet.Configuration;
1820
using NUnit.Framework;
19-
using Microsoft.DotNet.ProductConstructionService.Client;
20-
using Microsoft.DotNet.ProductConstructionService.Client.Models;
2121
using ProductConstructionService.ScenarioTests.ObjectHelpers;
2222

2323
[assembly: Parallelizable(ParallelScope.Fixtures)]
@@ -46,7 +46,7 @@ public void BaseSetup()
4646
_packageNameSalt = Guid.NewGuid().ToString().Substring(0, 8);
4747
}
4848

49-
protected async Task<Octokit.PullRequest> WaitForPullRequestAsync(string targetRepo, string targetBranch)
49+
protected async Task<Octokit.PullRequest> WaitForPullRequestAsync(string targetRepo, string targetBranch, Octokit.ItemStateFilter prState = Octokit.ItemStateFilter.Open)
5050
{
5151
Octokit.Repository repo = await GitHubApi.Repository.Get(TestParameters.GitHubTestOrg, targetRepo);
5252

@@ -56,6 +56,7 @@ public void BaseSetup()
5656
IReadOnlyList<Octokit.PullRequest> prs = await GitHubApi.PullRequest.GetAllForRepository(repo.Id, new Octokit.PullRequestRequest
5757
{
5858
Base = targetBranch,
59+
State = prState
5960
});
6061

6162
if (prs.Count == 1)
@@ -1189,10 +1190,21 @@ protected string GetUniqueAssetName(string packageName)
11891190
return $"{packageName}.{_packageNameSalt}";
11901191
}
11911192

1192-
protected static IAsyncDisposable CleanUpPullRequestAfter(string owner, string repo, Octokit.PullRequest pullRequest)
1193+
protected static IAsyncDisposable CleanUpPullRequestAfter(
1194+
string owner,
1195+
string repo,
1196+
Octokit.PullRequest pullRequest,
1197+
PullRequestCleanupOperation cleanupOperation = PullRequestCleanupOperation.Close)
11931198
=> AsyncDisposable.Create(async () =>
11941199
{
1195-
await ClosePullRequest(owner, repo, pullRequest);
1200+
if (cleanupOperation == PullRequestCleanupOperation.Merge)
1201+
{
1202+
await MergePullRequest(owner, repo, pullRequest);
1203+
}
1204+
else
1205+
{
1206+
await ClosePullRequest(owner, repo, pullRequest);
1207+
}
11961208
});
11971209

11981210
protected static async Task ClosePullRequest(string owner, string repo, Octokit.PullRequest pullRequest)
@@ -1220,6 +1232,34 @@ protected static async Task ClosePullRequest(string owner, string repo, Octokit.
12201232
}
12211233
}
12221234

1235+
protected static async Task MergePullRequest(string owner, string repo, Octokit.PullRequest pullRequest)
1236+
{
1237+
try
1238+
{
1239+
await GitHubApi.PullRequest.Merge(
1240+
owner,
1241+
repo,
1242+
pullRequest.Number,
1243+
new Octokit.MergePullRequest
1244+
{
1245+
CommitMessage = "Merge pull request",
1246+
MergeMethod = Octokit.PullRequestMergeMethod.Merge
1247+
});
1248+
}
1249+
catch
1250+
{
1251+
// Closed already
1252+
}
1253+
try
1254+
{
1255+
await GitHubApi.Git.Reference.Delete(owner, repo, $"heads/{pullRequest.Head.Ref}");
1256+
}
1257+
catch
1258+
{
1259+
// branch already deleted
1260+
}
1261+
}
1262+
12231263
protected static async Task CreateTargetBranchAndExecuteTest(string targetBranchName, string targetDirectory, Func<Task> test)
12241264
{
12251265
// first create a new target branch
@@ -1285,3 +1325,9 @@ protected static async Task WaitForNewCommitInPullRequest(string repo, Octokit.P
12851325
return pr;
12861326
}
12871327
}
1328+
1329+
internal enum PullRequestCleanupOperation
1330+
{
1331+
Close,
1332+
Merge
1333+
}

test/ProductConstructionService.ScenarioTests/ScenarioTests/ScenarioTests_CodeFlow.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,19 @@ await CreateTargetBranchAndExecuteTest(targetBranchName, vmrDirectory.Directory,
9898
TestRepository.VmrTestRepoName,
9999
targetBranchName,
100100
[$"src/{TestRepository.TestRepo1Name}/{TestFile1Name}"],
101-
TestFilePatches);
101+
TestFilePatches,
102+
PullRequestCleanupOperation.Merge);
102103

103104
await CheckIfPullRequestCommentExists(
104105
TestRepository.VmrTestRepoName,
105106
pr,
106-
[$"https://github.com/maestro-auth-test/maestro-test1/pull/{testPrNumber}"]);
107+
[$"(https://github.com/maestro-auth-test/maestro-test1/pull/{testPrNumber})"]);
108+
109+
await WaitForPullRequestComment(
110+
TestRepository.VmrTestRepoName,
111+
targetBranchName,
112+
$"- https://github.com/maestro-auth-test/maestro-test1/pull/{testPrNumber}",
113+
Octokit.ItemStateFilter.Closed);
107114
}
108115
}
109116
}

0 commit comments

Comments
 (0)