Skip to content

Commit 54c46b8

Browse files
authored
Add AWS arguments to generate-script commands (#682)
1 parent 0e7883f commit 54c46b8

9 files changed

+379
-109
lines changed

RELEASENOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
- Added additional retry logic covering the case when polling for migration status fails for any reason (along with a few other situations)
2+
- Added `--aws-bucket-name` to `gh gei generate-script` and removed `--azure-storage-connection-string`.

src/OctoshiftCLI.Tests/gei/Commands/GenerateScriptCommandTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public void Should_Have_Options()
4646
TestHelpers.VerifyCommandOption(command.Options, "ado-team-project", false, true);
4747
TestHelpers.VerifyCommandOption(command.Options, "github-target-org", true);
4848
TestHelpers.VerifyCommandOption(command.Options, "ghes-api-url", false);
49-
TestHelpers.VerifyCommandOption(command.Options, "azure-storage-connection-string", false);
5049
TestHelpers.VerifyCommandOption(command.Options, "no-ssl-verify", false);
5150
TestHelpers.VerifyCommandOption(command.Options, "skip-releases", false);
5251
TestHelpers.VerifyCommandOption(command.Options, "lock-source-repo", false);
@@ -56,6 +55,7 @@ public void Should_Have_Options()
5655
TestHelpers.VerifyCommandOption(command.Options, "github-source-pat", false);
5756
TestHelpers.VerifyCommandOption(command.Options, "ado-pat", false, true);
5857
TestHelpers.VerifyCommandOption(command.Options, "verbose", false);
58+
TestHelpers.VerifyCommandOption(command.Options, "aws-bucket-name", false);
5959
}
6060

6161
[Fact]

src/OctoshiftCLI.Tests/gei/Handlers/GenerateScriptCommandHandlerTests.cs

Lines changed: 85 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Octoshift.Models;
99
using OctoshiftCLI.Contracts;
1010
using OctoshiftCLI.Extensions;
11-
using OctoshiftCLI.GithubEnterpriseImporter;
1211
using OctoshiftCLI.GithubEnterpriseImporter.Commands;
1312
using OctoshiftCLI.GithubEnterpriseImporter.Handlers;
1413
using Xunit;
@@ -19,7 +18,6 @@ public class GenerateScriptCommandHandlerTests
1918
{
2019
private readonly Mock<GithubApi> _mockGithubApi = TestHelpers.CreateMock<GithubApi>();
2120
private readonly Mock<AdoApi> _mockAdoApi = TestHelpers.CreateMock<AdoApi>();
22-
private readonly Mock<EnvironmentVariableProvider> _mockEnvironmentVariableProvider = TestHelpers.CreateMock<EnvironmentVariableProvider>();
2321
private readonly Mock<OctoLogger> _mockOctoLogger = TestHelpers.CreateMock<OctoLogger>();
2422
private readonly Mock<IVersionProvider> _mockVersionProvider = new Mock<IVersionProvider>();
2523

@@ -28,6 +26,7 @@ public class GenerateScriptCommandHandlerTests
2826
private const string SOURCE_ORG = "FOO-SOURCE-ORG";
2927
private const string TARGET_ORG = "FOO-TARGET-ORG";
3028
private const string REPO = "REPO";
29+
private const string AWS_BUCKET_NAME = "AWS_BUCKET_NAME";
3130
private string _script;
3231

3332
public GenerateScriptCommandHandlerTests()
@@ -36,7 +35,6 @@ public GenerateScriptCommandHandlerTests()
3635
_mockOctoLogger.Object,
3736
_mockGithubApi.Object,
3837
_mockAdoApi.Object,
39-
_mockEnvironmentVariableProvider.Object,
4038
_mockVersionProvider.Object
4139
)
4240
{
@@ -61,6 +59,14 @@ await FluentActions
6159
.Should().ThrowAsync<OctoshiftCliException>();
6260
}
6361

62+
[Fact]
63+
public async Task No_Github_Source_Org_Or_Ado_Source_Org_Throws()
64+
{
65+
await _handler.Invoking(async handler => await handler.Handle(new GenerateScriptCommandArgs { GithubTargetOrg = TARGET_ORG }))
66+
.Should()
67+
.ThrowAsync<OctoshiftCliException>();
68+
}
69+
6470
[Fact]
6571
public async Task Sequential_Github_No_Data()
6672
{
@@ -295,13 +301,12 @@ public async Task Sequential_Github_Ghes_Repo()
295301
{
296302
// Arrange
297303
const string ghesApiUrl = "https://foo.com/api/v3";
298-
const string azureStorageConnectionString = "FOO-STORAGE-CONNECTION-STRING";
299304

300305
_mockGithubApi
301306
.Setup(m => m.GetRepos(SOURCE_ORG))
302307
.ReturnsAsync(new[] { REPO });
303308

304-
var expected = $"Exec {{ gh gei migrate-repo --github-source-org \"{SOURCE_ORG}\" --source-repo \"{REPO}\" --github-target-org \"{TARGET_ORG}\" --target-repo \"{REPO}\" --ghes-api-url \"{ghesApiUrl}\" --azure-storage-connection-string \"{azureStorageConnectionString}\" --wait }}";
309+
var expected = $"Exec {{ gh gei migrate-repo --github-source-org \"{SOURCE_ORG}\" --source-repo \"{REPO}\" --github-target-org \"{TARGET_ORG}\" --target-repo \"{REPO}\" --ghes-api-url \"{ghesApiUrl}\" --wait }}";
305310

306311
// Act
307312
var args = new GenerateScriptCommandArgs
@@ -310,7 +315,6 @@ public async Task Sequential_Github_Ghes_Repo()
310315
GithubTargetOrg = TARGET_ORG,
311316
Output = new FileInfo("unit-test-output"),
312317
GhesApiUrl = ghesApiUrl,
313-
AzureStorageConnectionString = azureStorageConnectionString,
314318
Sequential = true
315319
};
316320
await _handler.Handle(args);
@@ -319,7 +323,6 @@ public async Task Sequential_Github_Ghes_Repo()
319323

320324
// Assert
321325
_script.Should().Be(expected);
322-
_mockOctoLogger.Verify(m => m.LogInformation("AZURE STORAGE CONNECTION STRING: ***"));
323326
_mockOctoLogger.Verify(m => m.LogInformation($"GHES API URL: {ghesApiUrl}"));
324327
}
325328

@@ -658,7 +661,6 @@ public async Task Parallel_Github_Ghes_Single_Repo()
658661
{
659662
// Arrange
660663
const string ghesApiUrl = "https://foo.com/api/v3";
661-
const string azureStorageConnectionString = "FOO-STORAGE-CONNECTION-STRING";
662664

663665
_mockGithubApi
664666
.Setup(m => m.GetRepos(SOURCE_ORG))
@@ -699,7 +701,7 @@ function ExecAndGetMigrationID {
699701
expected.AppendLine($"# =========== Organization: {SOURCE_ORG} ===========");
700702
expected.AppendLine();
701703
expected.AppendLine("# === Queuing repo migrations ===");
702-
expected.AppendLine($"$MigrationID = ExecAndGetMigrationID {{ gh gei migrate-repo --github-source-org \"{SOURCE_ORG}\" --source-repo \"{REPO}\" --github-target-org \"{TARGET_ORG}\" --target-repo \"{REPO}\" --ghes-api-url \"{ghesApiUrl}\" --azure-storage-connection-string \"{azureStorageConnectionString}\" }}");
704+
expected.AppendLine($"$MigrationID = ExecAndGetMigrationID {{ gh gei migrate-repo --github-source-org \"{SOURCE_ORG}\" --source-repo \"{REPO}\" --github-target-org \"{TARGET_ORG}\" --target-repo \"{REPO}\" --ghes-api-url \"{ghesApiUrl}\" }}");
703705
expected.AppendLine($"$RepoMigrations[\"{REPO}\"] = $MigrationID");
704706
expected.AppendLine();
705707
expected.AppendLine();
@@ -725,14 +727,12 @@ exit 1
725727
GithubSourceOrg = SOURCE_ORG,
726728
GithubTargetOrg = TARGET_ORG,
727729
Output = new FileInfo("unit-test-output"),
728-
GhesApiUrl = ghesApiUrl,
729-
AzureStorageConnectionString = azureStorageConnectionString
730+
GhesApiUrl = ghesApiUrl
730731
};
731732
await _handler.Handle(args);
732733

733734
// Assert
734735
_script.Should().Be(expected.ToString());
735-
_mockOctoLogger.Verify(m => m.LogInformation("AZURE STORAGE CONNECTION STRING: ***"));
736736
_mockOctoLogger.Verify(m => m.LogInformation($"GHES API URL: {ghesApiUrl}"));
737737
}
738738

@@ -1026,7 +1026,6 @@ public async Task Parallel_Github_Ghes_Single_Repo_With_Download_Migration_Logs(
10261026
{
10271027
// Arrange
10281028
const string ghesApiUrl = "https://foo.com/api/v3";
1029-
const string azureStorageConnectionString = "FOO-STORAGE-CONNECTION-STRING";
10301029

10311030
_mockGithubApi
10321031
.Setup(m => m.GetRepos(SOURCE_ORG))
@@ -1067,7 +1066,7 @@ function ExecAndGetMigrationID {
10671066
expected.AppendLine($"# =========== Organization: {SOURCE_ORG} ===========");
10681067
expected.AppendLine();
10691068
expected.AppendLine("# === Queuing repo migrations ===");
1070-
expected.AppendLine($"$MigrationID = ExecAndGetMigrationID {{ gh gei migrate-repo --github-source-org \"{SOURCE_ORG}\" --source-repo \"{REPO}\" --github-target-org \"{TARGET_ORG}\" --target-repo \"{REPO}\" --ghes-api-url \"{ghesApiUrl}\" --azure-storage-connection-string \"{azureStorageConnectionString}\" }}");
1069+
expected.AppendLine($"$MigrationID = ExecAndGetMigrationID {{ gh gei migrate-repo --github-source-org \"{SOURCE_ORG}\" --source-repo \"{REPO}\" --github-target-org \"{TARGET_ORG}\" --target-repo \"{REPO}\" --ghes-api-url \"{ghesApiUrl}\" }}");
10711070
expected.AppendLine($"$RepoMigrations[\"{REPO}\"] = $MigrationID");
10721071
expected.AppendLine();
10731072
expected.AppendLine();
@@ -1095,7 +1094,6 @@ exit 1
10951094
GithubTargetOrg = TARGET_ORG,
10961095
Output = new FileInfo("unit-test-output"),
10971096
GhesApiUrl = ghesApiUrl,
1098-
AzureStorageConnectionString = azureStorageConnectionString,
10991097
DownloadMigrationLogs = true
11001098
};
11011099
await _handler.Handle(args);
@@ -1109,7 +1107,6 @@ public async Task Parallel_Github_Ghes_Single_Repo_No_Ssl()
11091107
{
11101108
// Arrange
11111109
const string ghesApiUrl = "https://foo.com/api/v3";
1112-
const string azureStorageConnectionString = "FOO-STORAGE-CONNECTION-STRING";
11131110

11141111
_mockGithubApi
11151112
.Setup(m => m.GetRepos(SOURCE_ORG))
@@ -1150,7 +1147,7 @@ function ExecAndGetMigrationID {
11501147
expected.AppendLine($"# =========== Organization: {SOURCE_ORG} ===========");
11511148
expected.AppendLine();
11521149
expected.AppendLine("# === Queuing repo migrations ===");
1153-
expected.AppendLine($"$MigrationID = ExecAndGetMigrationID {{ gh gei migrate-repo --github-source-org \"{SOURCE_ORG}\" --source-repo \"{REPO}\" --github-target-org \"{TARGET_ORG}\" --target-repo \"{REPO}\" --ghes-api-url \"{ghesApiUrl}\" --azure-storage-connection-string \"{azureStorageConnectionString}\" --no-ssl-verify }}");
1150+
expected.AppendLine($"$MigrationID = ExecAndGetMigrationID {{ gh gei migrate-repo --github-source-org \"{SOURCE_ORG}\" --source-repo \"{REPO}\" --github-target-org \"{TARGET_ORG}\" --target-repo \"{REPO}\" --ghes-api-url \"{ghesApiUrl}\" --no-ssl-verify }}");
11541151
expected.AppendLine($"$RepoMigrations[\"{REPO}\"] = $MigrationID");
11551152
expected.AppendLine();
11561153
expected.AppendLine();
@@ -1177,7 +1174,6 @@ exit 1
11771174
GithubTargetOrg = TARGET_ORG,
11781175
Output = new FileInfo("unit-test-output"),
11791176
GhesApiUrl = ghesApiUrl,
1180-
AzureStorageConnectionString = azureStorageConnectionString,
11811177
NoSslVerify = true
11821178
};
11831179
await _handler.Handle(args);
@@ -1402,6 +1398,77 @@ public async Task Parallel_Ado_Contains_Cli_Version()
14021398
_script.Should().Contain(expectedCliVersionComment);
14031399
}
14041400

1401+
[Fact]
1402+
public async Task Sequential_Ghes_Single_Repo_Aws_S3()
1403+
{
1404+
// Arrange
1405+
const string ghesApiUrl = "https://foo.com/api/v3";
1406+
1407+
_mockGithubApi
1408+
.Setup(m => m.GetRepos(SOURCE_ORG))
1409+
.ReturnsAsync(new[] { REPO });
1410+
1411+
var expected = $"Exec {{ gh gei migrate-repo --github-source-org \"{SOURCE_ORG}\" --source-repo \"{REPO}\" --github-target-org \"{TARGET_ORG}\" --target-repo \"{REPO}\" --ghes-api-url \"{ghesApiUrl}\" --aws-bucket-name \"{AWS_BUCKET_NAME}\" --wait }}";
1412+
1413+
// Act
1414+
var args = new GenerateScriptCommandArgs
1415+
{
1416+
GithubSourceOrg = SOURCE_ORG,
1417+
GithubTargetOrg = TARGET_ORG,
1418+
Output = new FileInfo("unit-test-output"),
1419+
GhesApiUrl = ghesApiUrl,
1420+
AwsBucketName = AWS_BUCKET_NAME,
1421+
Sequential = true
1422+
};
1423+
await _handler.Handle(args);
1424+
1425+
_script = TrimNonExecutableLines(_script);
1426+
1427+
// Assert
1428+
_script.Should().Be(expected);
1429+
_mockOctoLogger.Verify(m => m.LogInformation($"AWS BUCKET NAME: {AWS_BUCKET_NAME}"));
1430+
}
1431+
1432+
[Fact]
1433+
public async Task It_Throws_When_Aws_Bucket_Name_Is_Provided_But_Ghes_Api_Url_Is_Not()
1434+
{
1435+
// Arrange
1436+
var args = new GenerateScriptCommandArgs
1437+
{
1438+
GithubSourceOrg = SOURCE_ORG,
1439+
GithubTargetOrg = TARGET_ORG,
1440+
Output = new FileInfo("unit-test-output"),
1441+
AwsBucketName = AWS_BUCKET_NAME,
1442+
Sequential = true
1443+
};
1444+
1445+
// Act, Assert
1446+
await _handler
1447+
.Invoking(async handler => await handler.Handle(args))
1448+
.Should()
1449+
.ThrowAsync<OctoshiftCliException>();
1450+
}
1451+
1452+
[Fact]
1453+
public async Task It_Throws_When_No_Ssl_Verify_Is_Set_But_Ghes_Api_Url_Is_Not()
1454+
{
1455+
// Arrange
1456+
var args = new GenerateScriptCommandArgs
1457+
{
1458+
GithubSourceOrg = SOURCE_ORG,
1459+
GithubTargetOrg = TARGET_ORG,
1460+
Output = new FileInfo("unit-test-output"),
1461+
NoSslVerify = true,
1462+
Sequential = true
1463+
};
1464+
1465+
// Act, Assert
1466+
await _handler
1467+
.Invoking(async handler => await handler.Handle(args))
1468+
.Should()
1469+
.ThrowAsync<OctoshiftCliException>();
1470+
}
1471+
14051472
private string TrimNonExecutableLines(string script, int skipFirst = 9, int skipLast = 0)
14061473
{
14071474
var lines = script.Split(new[] { Environment.NewLine, "\n" }, StringSplitOptions.RemoveEmptyEntries).AsEnumerable();

0 commit comments

Comments
 (0)