From 6ca4a1125e848bd66d88d6a5ab094749058b05d9 Mon Sep 17 00:00:00 2001 From: bbsadmin Date: Mon, 4 Nov 2024 09:52:22 -0800 Subject: [PATCH 01/15] Update logic for GHES generate script for --usegithubstorage option --- .../GenerateScriptCommandHandlerTests.cs | 57 +++++++++++++++++++ .../GenerateScriptCommandTests.cs | 3 +- .../GenerateScript/GenerateScriptCommand.cs | 6 ++ .../GenerateScriptCommandArgs.cs | 1 + .../GenerateScriptCommandHandler.cs | 23 ++++---- 5 files changed, 78 insertions(+), 12 deletions(-) diff --git a/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandHandlerTests.cs b/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandHandlerTests.cs index ffc34d024..2a5a718c5 100644 --- a/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandHandlerTests.cs +++ b/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandHandlerTests.cs @@ -1102,6 +1102,63 @@ exit 1 _script.Should().NotContain(expected); } + [Fact] + public async Task Sequential_Github_Single_Repo_With_UseGithubStorage() + { + // Arrange + _mockGithubApi + .Setup(m => m.GetRepos(SOURCE_ORG)) + .ReturnsAsync(new[] { (REPO, "private") }); + + var expected = $"Exec {{ gh gei migrate-repo --github-source-org \"{SOURCE_ORG}\" --source-repo \"{REPO}\" --github-target-org \"{TARGET_ORG}\" --target-repo \"{REPO}\" --target-repo-visibility private --use-github-storage true }}"; + + // Act + var args = new GenerateScriptCommandArgs + { + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + Output = new FileInfo("unit-test-output"), + Sequential = true, + UseGithubStorage = true + }; + await _handler.Handle(args); + + _script = TrimNonExecutableLines(_script); + + // Assert + _script.Should().Be(expected); + } + + [Fact] + public async Task Parallel_Github_Single_Repo_With_UseGithubStorage() + { + // Arrange + _mockGithubApi + .Setup(m => m.GetRepos(SOURCE_ORG)) + .ReturnsAsync(new[] { (REPO, "private") }); + + var expected = new StringBuilder(); + expected.AppendLine($"$MigrationID = ExecAndGetMigrationID {{ gh gei migrate-repo --github-source-org \"{SOURCE_ORG}\" --source-repo \"{REPO}\" --github-target-org \"{TARGET_ORG}\" --target-repo \"{REPO}\" --queue-only --target-repo-visibility private --use-github-storage true }}"); + expected.AppendLine($"$RepoMigrations[\"{REPO}\"] = $MigrationID"); + expected.Append($"if ($RepoMigrations[\"{REPO}\"]) {{ gh gei wait-for-migration --migration-id $RepoMigrations[\"{REPO}\"] }}"); + + // Act + var args = new GenerateScriptCommandArgs + { + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + Output = new FileInfo("unit-test-output"), + UseGithubStorage = true + }; + await _handler.Handle(args); + + _script = TrimNonExecutableLines(_script, 19, 7); + + // Assert + _script.Should().Be(expected.ToString()); + } + + [Fact] public async Task Validates_Env_Vars_Blob_Storage_Not_Validated_When_GHES_3_8() { diff --git a/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandTests.cs b/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandTests.cs index a24ff8de7..c7bc43c30 100644 --- a/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandTests.cs +++ b/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandTests.cs @@ -39,7 +39,7 @@ public void Should_Have_Options() var command = new GenerateScriptCommand(); command.Should().NotBeNull(); command.Name.Should().Be("generate-script"); - command.Options.Count.Should().Be(15); + command.Options.Count.Should().Be(16); TestHelpers.VerifyCommandOption(command.Options, "github-source-org", true); TestHelpers.VerifyCommandOption(command.Options, "github-target-org", true); @@ -56,6 +56,7 @@ public void Should_Have_Options() TestHelpers.VerifyCommandOption(command.Options, "aws-region", false); TestHelpers.VerifyCommandOption(command.Options, "keep-archive", false); TestHelpers.VerifyCommandOption(command.Options, "target-api-url", false); + TestHelpers.VerifyCommandOption(command.Options, "use-github-storage", false, true); } [Fact] diff --git a/src/gei/Commands/GenerateScript/GenerateScriptCommand.cs b/src/gei/Commands/GenerateScript/GenerateScriptCommand.cs index 2e20eae87..922f2183d 100644 --- a/src/gei/Commands/GenerateScript/GenerateScriptCommand.cs +++ b/src/gei/Commands/GenerateScript/GenerateScriptCommand.cs @@ -36,6 +36,7 @@ public GenerateScriptCommand() : base( AddOption(GithubSourcePat); AddOption(Verbose); AddOption(KeepArchive); + AddOption(UseGithubStorage); } public Option GithubSourceOrg { get; } = new("--github-source-org") { @@ -99,6 +100,11 @@ public GenerateScriptCommand() : base( { Description = "The URL of the target API, if not migrating to github.com. Defaults to https://api.github.com" }; + public Option UseGithubStorage { get; } = new("--use-github-storage") + { + IsHidden = true, + Description = "Enables multipart uploads to a GitHub owned storage for use during migration", + }; public override GenerateScriptCommandHandler BuildHandler(GenerateScriptCommandArgs args, IServiceProvider sp) { diff --git a/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs b/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs index d1f64956a..09c1ce759 100644 --- a/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs +++ b/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs @@ -23,6 +23,7 @@ public class GenerateScriptCommandArgs : CommandArgs public string GithubSourcePat { get; set; } public bool KeepArchive { get; set; } public string TargetApiUrl { get; set; } + public bool UseGithubStorage { get; set; } public override void Validate(OctoLogger log) { diff --git a/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs b/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs index 39f8b7aee..a4b3c8d53 100644 --- a/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs +++ b/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs @@ -44,7 +44,7 @@ public async Task Handle(GenerateScriptCommandArgs args) _log.LogInformation("Generating Script..."); - var script = await GenerateScript(args.GithubSourceOrg, args.GithubTargetOrg, args.GhesApiUrl, args.AwsBucketName, args.AwsRegion, args.NoSslVerify, args.Sequential, args.SkipReleases, args.LockSourceRepo, args.DownloadMigrationLogs, args.KeepArchive, args.TargetApiUrl); + var script = await GenerateScript(args.GithubSourceOrg, args.GithubTargetOrg, args.GhesApiUrl, args.AwsBucketName, args.AwsRegion, args.NoSslVerify, args.Sequential, args.SkipReleases, args.LockSourceRepo, args.DownloadMigrationLogs, args.KeepArchive, args.TargetApiUrl, args.UseGithubStorage); if (script.HasValue() && args.Output.HasValue()) { @@ -52,7 +52,7 @@ public async Task Handle(GenerateScriptCommandArgs args) } } - private async Task GenerateScript(string githubSourceOrg, string githubTargetOrg, string ghesApiUrl, string awsBucketName, string awsRegion, bool noSslVerify, bool sequential, bool skipReleases, bool lockSourceRepo, bool downloadMigrationLogs, bool keepArchive, string targetApiUrl) + private async Task GenerateScript(string githubSourceOrg, string githubTargetOrg, string ghesApiUrl, string awsBucketName, string awsRegion, bool noSslVerify, bool sequential, bool skipReleases, bool lockSourceRepo, bool downloadMigrationLogs, bool keepArchive, string targetApiUrl, bool useGithubStorage) { var repos = await GetGithubRepos(_sourceGithubApi, githubSourceOrg); if (!repos.Any()) @@ -62,8 +62,8 @@ private async Task GenerateScript(string githubSourceOrg, string githubT } return sequential - ? await GenerateSequentialGithubScript(repos, githubSourceOrg, githubTargetOrg, ghesApiUrl, awsBucketName, awsRegion, noSslVerify, skipReleases, lockSourceRepo, downloadMigrationLogs, keepArchive, targetApiUrl) - : await GenerateParallelGithubScript(repos, githubSourceOrg, githubTargetOrg, ghesApiUrl, awsBucketName, awsRegion, noSslVerify, skipReleases, lockSourceRepo, downloadMigrationLogs, keepArchive, targetApiUrl); + ? await GenerateSequentialGithubScript(repos, githubSourceOrg, githubTargetOrg, ghesApiUrl, awsBucketName, awsRegion, noSslVerify, skipReleases, lockSourceRepo, downloadMigrationLogs, keepArchive, targetApiUrl, useGithubStorage) + : await GenerateParallelGithubScript(repos, githubSourceOrg, githubTargetOrg, ghesApiUrl, awsBucketName, awsRegion, noSslVerify, skipReleases, lockSourceRepo, downloadMigrationLogs, keepArchive, targetApiUrl, useGithubStorage); } private async Task> GetGithubRepos(GithubApi github, string githubOrg) @@ -83,7 +83,7 @@ private async Task GenerateScript(string githubSourceOrg, string githubT return repos; } - private async Task GenerateSequentialGithubScript(IEnumerable<(string Name, string Visibility)> repos, string githubSourceOrg, string githubTargetOrg, string ghesApiUrl, string awsBucketName, string awsRegion, bool noSslVerify, bool skipReleases, bool lockSourceRepo, bool downloadMigrationLogs, bool keepArchive, string targetApiUrl) + private async Task GenerateSequentialGithubScript(IEnumerable<(string Name, string Visibility)> repos, string githubSourceOrg, string githubTargetOrg, string ghesApiUrl, string awsBucketName, string awsRegion, bool noSslVerify, bool skipReleases, bool lockSourceRepo, bool downloadMigrationLogs, bool keepArchive, string targetApiUrl, bool useGithubStorage) { var content = new StringBuilder(); @@ -110,7 +110,7 @@ private async Task GenerateSequentialGithubScript(IEnumerable<(string Na foreach (var (name, visibility) in repos) { - content.AppendLine(Exec(MigrateGithubRepoScript(githubSourceOrg, githubTargetOrg, name, ghesApiUrl, awsBucketName, awsRegion, noSslVerify, true, skipReleases, lockSourceRepo, keepArchive, visibility, targetApiUrl))); + content.AppendLine(Exec(MigrateGithubRepoScript(githubSourceOrg, githubTargetOrg, name, ghesApiUrl, awsBucketName, awsRegion, noSslVerify, true, skipReleases, lockSourceRepo, keepArchive, visibility, targetApiUrl, useGithubStorage))); if (downloadMigrationLogs) { @@ -121,7 +121,7 @@ private async Task GenerateSequentialGithubScript(IEnumerable<(string Na return content.ToString(); } - private async Task GenerateParallelGithubScript(IEnumerable<(string Name, string Visibility)> repos, string githubSourceOrg, string githubTargetOrg, string ghesApiUrl, string awsBucketName, string awsRegion, bool noSslVerify, bool skipReleases, bool lockSourceRepo, bool downloadMigrationLogs, bool keepArchive, string targetApiUrl) + private async Task GenerateParallelGithubScript(IEnumerable<(string Name, string Visibility)> repos, string githubSourceOrg, string githubTargetOrg, string ghesApiUrl, string awsBucketName, string awsRegion, bool noSslVerify, bool skipReleases, bool lockSourceRepo, bool downloadMigrationLogs, bool keepArchive, string targetApiUrl, bool useGithubStorage) { var content = new StringBuilder(); @@ -158,7 +158,7 @@ private async Task GenerateParallelGithubScript(IEnumerable<(string Name // Queuing migrations foreach (var (name, visibility) in repos) { - content.AppendLine($"$MigrationID = {ExecAndGetMigrationId(MigrateGithubRepoScript(githubSourceOrg, githubTargetOrg, name, ghesApiUrl, awsBucketName, awsRegion, noSslVerify, false, skipReleases, lockSourceRepo, keepArchive, visibility, targetApiUrl))}"); + content.AppendLine($"$MigrationID = {ExecAndGetMigrationId(MigrateGithubRepoScript(githubSourceOrg, githubTargetOrg, name, ghesApiUrl, awsBucketName, awsRegion, noSslVerify, false, skipReleases, lockSourceRepo, keepArchive, visibility, targetApiUrl, useGithubStorage))}"); content.AppendLine($"$RepoMigrations[\"{name}\"] = $MigrationID"); content.AppendLine(); } @@ -199,11 +199,12 @@ exit 1 return content.ToString(); } - private string MigrateGithubRepoScript(string githubSourceOrg, string githubTargetOrg, string repo, string ghesApiUrl, string awsBucketName, string awsRegion, bool noSslVerify, bool wait, bool skipReleases, bool lockSourceRepo, bool keepArchive, string repoVisibility, string targetApiUrl) + private string MigrateGithubRepoScript(string githubSourceOrg, string githubTargetOrg, string repo, string ghesApiUrl, string awsBucketName, string awsRegion, bool noSslVerify, bool wait, bool skipReleases, bool lockSourceRepo, bool keepArchive, string repoVisibility, string targetApiUrl, bool useGithubStorage) { var ghesRepoOptions = ghesApiUrl.HasValue() ? GetGhesRepoOptions(ghesApiUrl, awsBucketName, awsRegion, noSslVerify, keepArchive) : null; + var useGithubStorageOption = useGithubStorage ? " --use-github-storage true" : string.Empty; - return $"gh gei migrate-repo{(targetApiUrl.HasValue() ? $" --target-api-url \"{targetApiUrl}\"" : string.Empty)} --github-source-org \"{githubSourceOrg}\" --source-repo \"{repo}\" --github-target-org \"{githubTargetOrg}\" --target-repo \"{repo}\"{(!string.IsNullOrEmpty(ghesRepoOptions) ? $" {ghesRepoOptions}" : string.Empty)}{(_log.Verbose ? " --verbose" : string.Empty)}{(wait ? string.Empty : " --queue-only")}{(skipReleases ? " --skip-releases" : string.Empty)}{(lockSourceRepo ? " --lock-source-repo" : string.Empty)} --target-repo-visibility {repoVisibility}"; + return $"gh gei migrate-repo{(targetApiUrl.HasValue() ? $" --target-api-url \"{targetApiUrl}\"" : string.Empty)} --github-source-org \"{githubSourceOrg}\" --source-repo \"{repo}\" --github-target-org \"{githubTargetOrg}\" --target-repo \"{repo}\"{(!string.IsNullOrEmpty(ghesRepoOptions) ? $" {ghesRepoOptions}" : string.Empty)}{(_log.Verbose ? " --verbose" : string.Empty)}{(wait ? string.Empty : " --queue-only")}{(skipReleases ? " --skip-releases" : string.Empty)}{(lockSourceRepo ? " --lock-source-repo" : string.Empty)} --target-repo-visibility {repoVisibility}{useGithubStorageOption}"; } private string GetGhesRepoOptions(string ghesApiUrl, string awsBucketName, string awsRegion, bool noSslVerify, bool keepArchive) @@ -279,4 +280,4 @@ exit 1 } else { Write-Host ""AWS_SECRET_ACCESS_KEY environment variable is set and will be used to upload the migration archive to AWS S3."" }"; -} +} \ No newline at end of file From 414c4b391c28f4f8d18479ddbf7ae677833ae469 Mon Sep 17 00:00:00 2001 From: bbsadmin Date: Mon, 4 Nov 2024 10:03:30 -0800 Subject: [PATCH 02/15] Add int tests and fix linte error --- .../GhesToGithub.cs | 18 ++++++++++++++---- .../GenerateScriptCommandHandler.cs | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs b/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs index 727ebc232..f741daf1e 100644 --- a/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs +++ b/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs @@ -63,7 +63,10 @@ public GhesToGithub(ITestOutputHelper output) _targetHelper = new TestHelper(_output, _targetGithubApi, _targetGithubClient, _blobServiceClient); } - public async Task Basic() + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task Basic(bool useGithubStorage) { var githubSourceOrg = $"e2e-testing-{TestHelper.GetOsName()}"; var githubTargetOrg = $"octoshift-e2e-ghes-{TestHelper.GetOsName()}"; @@ -83,8 +86,14 @@ await retryPolicy.Retry(async () => await _sourceHelper.CreateGithubRepo(githubSourceOrg, repo2); }); - await _targetHelper.RunGeiCliMigration( - $"generate-script --github-source-org {githubSourceOrg} --github-target-org {githubTargetOrg} --ghes-api-url {GHES_API_URL} --download-migration-logs", _tokens); + // Build the command with conditional option + var command = $"generate-script --github-source-org {githubSourceOrg} --github-target-org {githubTargetOrg} --ghes-api-url {GHES_API_URL} --download-migration-logs"; + if (useGithubStorage) + { + command += " --use-github-storage true"; + } + + await _targetHelper.RunGeiCliMigration(command, _tokens); _targetHelper.AssertNoErrorInLogs(_startTime); @@ -96,10 +105,11 @@ await _targetHelper.RunGeiCliMigration( _targetHelper.AssertMigrationLogFileExists(githubTargetOrg, repo1); _targetHelper.AssertMigrationLogFileExists(githubTargetOrg, repo2); } + public void Dispose() { _sourceGithubHttpClient?.Dispose(); _targetGithubHttpClient?.Dispose(); _versionClient?.Dispose(); } -} +} \ No newline at end of file diff --git a/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs b/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs index a4b3c8d53..9564b22b0 100644 --- a/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs +++ b/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs @@ -280,4 +280,4 @@ exit 1 } else { Write-Host ""AWS_SECRET_ACCESS_KEY environment variable is set and will be used to upload the migration archive to AWS S3."" }"; -} \ No newline at end of file +} From 8f4f10d3e5dbf887510db2f11cd82bbe34124902 Mon Sep 17 00:00:00 2001 From: bbsadmin Date: Mon, 4 Nov 2024 10:08:10 -0800 Subject: [PATCH 03/15] linter --- src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs b/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs index f741daf1e..f96bdd20b 100644 --- a/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs +++ b/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs @@ -112,4 +112,4 @@ public void Dispose() _targetGithubHttpClient?.Dispose(); _versionClient?.Dispose(); } -} \ No newline at end of file +} From f9b3bb4d844450f9ac8360d63d7679d3436e6e43 Mon Sep 17 00:00:00 2001 From: bbsadmin Date: Mon, 4 Nov 2024 11:48:45 -0800 Subject: [PATCH 04/15] Update script command handler --- .../GenerateScript/GenerateScriptCommandHandler.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs b/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs index 9564b22b0..854de7601 100644 --- a/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs +++ b/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs @@ -201,15 +201,14 @@ exit 1 private string MigrateGithubRepoScript(string githubSourceOrg, string githubTargetOrg, string repo, string ghesApiUrl, string awsBucketName, string awsRegion, bool noSslVerify, bool wait, bool skipReleases, bool lockSourceRepo, bool keepArchive, string repoVisibility, string targetApiUrl, bool useGithubStorage) { - var ghesRepoOptions = ghesApiUrl.HasValue() ? GetGhesRepoOptions(ghesApiUrl, awsBucketName, awsRegion, noSslVerify, keepArchive) : null; - var useGithubStorageOption = useGithubStorage ? " --use-github-storage true" : string.Empty; + var ghesRepoOptions = ghesApiUrl.HasValue() ? GetGhesRepoOptions(ghesApiUrl, awsBucketName, awsRegion, noSslVerify, keepArchive, useGithubStorage) : null; - return $"gh gei migrate-repo{(targetApiUrl.HasValue() ? $" --target-api-url \"{targetApiUrl}\"" : string.Empty)} --github-source-org \"{githubSourceOrg}\" --source-repo \"{repo}\" --github-target-org \"{githubTargetOrg}\" --target-repo \"{repo}\"{(!string.IsNullOrEmpty(ghesRepoOptions) ? $" {ghesRepoOptions}" : string.Empty)}{(_log.Verbose ? " --verbose" : string.Empty)}{(wait ? string.Empty : " --queue-only")}{(skipReleases ? " --skip-releases" : string.Empty)}{(lockSourceRepo ? " --lock-source-repo" : string.Empty)} --target-repo-visibility {repoVisibility}{useGithubStorageOption}"; + return $"gh gei migrate-repo{(targetApiUrl.HasValue() ? $" --target-api-url \"{targetApiUrl}\"" : string.Empty)} --github-source-org \"{githubSourceOrg}\" --source-repo \"{repo}\" --github-target-org \"{githubTargetOrg}\" --target-repo \"{repo}\"{(!string.IsNullOrEmpty(ghesRepoOptions) ? $" {ghesRepoOptions}" : string.Empty)}{(_log.Verbose ? " --verbose" : string.Empty)}{(wait ? string.Empty : " --queue-only")}{(skipReleases ? " --skip-releases" : string.Empty)}{(lockSourceRepo ? " --lock-source-repo" : string.Empty)} --target-repo-visibility {repoVisibility}"; } - private string GetGhesRepoOptions(string ghesApiUrl, string awsBucketName, string awsRegion, bool noSslVerify, bool keepArchive) + private string GetGhesRepoOptions(string ghesApiUrl, string awsBucketName, string awsRegion, bool noSslVerify, bool keepArchive, bool useGithubStorage) { - return $"--ghes-api-url \"{ghesApiUrl}\"{(awsBucketName.HasValue() ? $" --aws-bucket-name \"{awsBucketName}\"" : "")}{(awsRegion.HasValue() ? $" --aws-region \"{awsRegion}\"" : "")}{(noSslVerify ? " --no-ssl-verify" : string.Empty)}{(keepArchive ? " --keep-archive" : string.Empty)}"; + return $"--ghes-api-url \"{ghesApiUrl}\"{(awsBucketName.HasValue() ? $" --aws-bucket-name \"{awsBucketName}\"" : "")}{(awsRegion.HasValue() ? $" --aws-region \"{awsRegion}\"" : "")}{(noSslVerify ? " --no-ssl-verify" : string.Empty)}{(keepArchive ? " --keep-archive" : string.Empty)}{useGithubStorage ? " --use-github-storage" : string.Empty}"; } private string WaitForMigrationScript(string targetApiUrl, string repoMigrationKey = null) => $"gh gei wait-for-migration{(targetApiUrl.HasValue() ? $" --target-api-url \"{targetApiUrl}\"" : string.Empty)} --migration-id $RepoMigrations[\"{repoMigrationKey}\"]"; From 2805a72cf56df8cc38de72179974505fb319f3d0 Mon Sep 17 00:00:00 2001 From: bbsadmin Date: Mon, 4 Nov 2024 12:25:09 -0800 Subject: [PATCH 05/15] Code review --- .../GhesToGithub.cs | 45 +++++++++++++------ .../GenerateScriptCommandArgs.cs | 17 ++++++- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs b/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs index f96bdd20b..9f6efe396 100644 --- a/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs +++ b/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs @@ -25,9 +25,11 @@ public sealed class GhesToGithub : IDisposable private readonly GithubClient _sourceGithubClient; private readonly GithubApi _sourceGithubApi; private readonly BlobServiceClient _blobServiceClient; - private readonly Dictionary _tokens; private readonly DateTime _startTime; private readonly ArchiveUploader _archiveUploader; + private readonly string _sourceGithubToken; + private readonly string _targetGithubToken; + private readonly string _azureStorageConnectionString; public GhesToGithub(ITestOutputHelper output) { @@ -36,15 +38,9 @@ public GhesToGithub(ITestOutputHelper output) var logger = new OctoLogger(_ => { }, x => _output.WriteLine(x), _ => { }, _ => { }); - var sourceGithubToken = Environment.GetEnvironmentVariable("GHES_PAT"); - var targetGithubToken = Environment.GetEnvironmentVariable("GHEC_PAT"); - var azureStorageConnectionString = Environment.GetEnvironmentVariable($"AZURE_STORAGE_CONNECTION_STRING_GHES_{TestHelper.GetOsName().ToUpper()}"); - _tokens = new Dictionary - { - ["GH_SOURCE_PAT"] = sourceGithubToken, - ["GH_PAT"] = targetGithubToken, - ["AZURE_STORAGE_CONNECTION_STRING"] = azureStorageConnectionString - }; + _sourceGithubToken = Environment.GetEnvironmentVariable("GHES_PAT"); + _targetGithubToken = Environment.GetEnvironmentVariable("GHEC_PAT"); + _azureStorageConnectionString = Environment.GetEnvironmentVariable($"AZURE_STORAGE_CONNECTION_STRING_GHES_{TestHelper.GetOsName().ToUpper()}"); _versionClient = new HttpClient(); _archiveUploader = new ArchiveUploader(_targetGithubClient, logger); @@ -57,7 +53,7 @@ public GhesToGithub(ITestOutputHelper output) _targetGithubClient = new GithubClient(logger, _targetGithubHttpClient, new VersionChecker(_versionClient, logger), new RetryPolicy(logger), new DateTimeProvider(), targetGithubToken); _targetGithubApi = new GithubApi(_targetGithubClient, "https://api.github.com", new RetryPolicy(logger), _archiveUploader); - _blobServiceClient = new BlobServiceClient(azureStorageConnectionString); + _blobServiceClient = new BlobServiceClient(_azureStorageConnectionString); _sourceHelper = new TestHelper(_output, _sourceGithubApi, _sourceGithubClient) { GithubApiBaseUrl = GHES_API_URL }; _targetHelper = new TestHelper(_output, _targetGithubApi, _targetGithubClient, _blobServiceClient); @@ -73,11 +69,34 @@ public async Task Basic(bool useGithubStorage) const string repo1 = "repo-1"; const string repo2 = "repo-2"; + var tokens = new Dictionary { }; + + if (useGithubStorage) + { + tokens = new Dictionary + { + ["GH_SOURCE_PAT"] = _sourceGithubToken, + ["GH_PAT"] = _targetGithubToken, + }; + } + else + { + tokens = new Dictionary + { + ["GH_SOURCE_PAT"] = _sourceGithubToken, + ["GH_PAT"] = _targetGithubToken, + ["AZURE_STORAGE_CONNECTION_STRING"] = _azureStorageConnectionString + }; + } + var retryPolicy = new RetryPolicy(null); await retryPolicy.Retry(async () => { - await _targetHelper.ResetBlobContainers(); + if (!useGithubStorage) + { + await _targetHelper.ResetBlobContainers(); + } await _sourceHelper.ResetGithubTestEnvironment(githubSourceOrg); await _targetHelper.ResetGithubTestEnvironment(githubTargetOrg); @@ -93,7 +112,7 @@ await retryPolicy.Retry(async () => command += " --use-github-storage true"; } - await _targetHelper.RunGeiCliMigration(command, _tokens); + await _targetHelper.RunGeiCliMigration(command, tokens); _targetHelper.AssertNoErrorInLogs(_startTime); diff --git a/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs b/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs index 09c1ce759..9123381c5 100644 --- a/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs +++ b/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs @@ -27,9 +27,17 @@ public class GenerateScriptCommandArgs : CommandArgs public override void Validate(OctoLogger log) { - if (AwsBucketName.HasValue() && GhesApiUrl.IsNullOrWhiteSpace()) + if (AwsBucketName.HasValue()) { - throw new OctoshiftCliException("--ghes-api-url must be specified when --aws-bucket-name is specified."); + if (GhesApiUrl.IsNullOrWhiteSpace()) + { + throw new OctoshiftCliException("--ghes-api-url must be specified when --aws-bucket-name is specified."); + } + + if (UseGithubStorage) + { + throw new OctoshiftCliException("The --use-github-storage flag was provided with an AWS S3 Bucket name. Archive cannot be uploaded to both locations."); + } } if (NoSslVerify && GhesApiUrl.IsNullOrWhiteSpace()) @@ -46,6 +54,11 @@ public override void Validate(OctoLogger log) { throw new OctoshiftCliException("--ghes-api-url is invalid. Please check URL before trying again."); } + + if (UseGithubStorage) + { + throw new OctoshiftCliException("--ghes-api-url must be specified when --use-github-storage is specified."); + } } } } From 28c6d2b04a25f86b9ab85d3390366392b14d7879 Mon Sep 17 00:00:00 2001 From: bbsadmin Date: Mon, 4 Nov 2024 12:33:19 -0800 Subject: [PATCH 06/15] Fix builder errors --- src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs | 4 ++-- .../Commands/GenerateScript/GenerateScriptCommandHandler.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs b/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs index 9f6efe396..876a74e96 100644 --- a/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs +++ b/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs @@ -46,11 +46,11 @@ public GhesToGithub(ITestOutputHelper output) _archiveUploader = new ArchiveUploader(_targetGithubClient, logger); _sourceGithubHttpClient = new HttpClient(); - _sourceGithubClient = new GithubClient(logger, _sourceGithubHttpClient, new VersionChecker(_versionClient, logger), new RetryPolicy(logger), new DateTimeProvider(), sourceGithubToken); + _sourceGithubClient = new GithubClient(logger, _sourceGithubHttpClient, new VersionChecker(_versionClient, logger), new RetryPolicy(logger), new DateTimeProvider(), _sourceGithubToken); _sourceGithubApi = new GithubApi(_sourceGithubClient, GHES_API_URL, new RetryPolicy(logger), _archiveUploader); _targetGithubHttpClient = new HttpClient(); - _targetGithubClient = new GithubClient(logger, _targetGithubHttpClient, new VersionChecker(_versionClient, logger), new RetryPolicy(logger), new DateTimeProvider(), targetGithubToken); + _targetGithubClient = new GithubClient(logger, _targetGithubHttpClient, new VersionChecker(_versionClient, logger), new RetryPolicy(logger), new DateTimeProvider(), _targetGithubToken); _targetGithubApi = new GithubApi(_targetGithubClient, "https://api.github.com", new RetryPolicy(logger), _archiveUploader); _blobServiceClient = new BlobServiceClient(_azureStorageConnectionString); diff --git a/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs b/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs index 854de7601..914b97179 100644 --- a/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs +++ b/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs @@ -208,7 +208,7 @@ private string MigrateGithubRepoScript(string githubSourceOrg, string githubTarg private string GetGhesRepoOptions(string ghesApiUrl, string awsBucketName, string awsRegion, bool noSslVerify, bool keepArchive, bool useGithubStorage) { - return $"--ghes-api-url \"{ghesApiUrl}\"{(awsBucketName.HasValue() ? $" --aws-bucket-name \"{awsBucketName}\"" : "")}{(awsRegion.HasValue() ? $" --aws-region \"{awsRegion}\"" : "")}{(noSslVerify ? " --no-ssl-verify" : string.Empty)}{(keepArchive ? " --keep-archive" : string.Empty)}{useGithubStorage ? " --use-github-storage" : string.Empty}"; + return $"--ghes-api-url \"{ghesApiUrl}\"{(awsBucketName.HasValue() ? $" --aws-bucket-name \"{awsBucketName}\"" : "")}{(awsRegion.HasValue() ? $" --aws-region \"{awsRegion}\"" : "")}{(noSslVerify ? " --no-ssl-verify" : string.Empty)}{(keepArchive ? " --keep-archive" : string.Empty)}{(useGithubStorage ? " --use-github-storage" : string.Empty)}"; } private string WaitForMigrationScript(string targetApiUrl, string repoMigrationKey = null) => $"gh gei wait-for-migration{(targetApiUrl.HasValue() ? $" --target-api-url \"{targetApiUrl}\"" : string.Empty)} --migration-id $RepoMigrations[\"{repoMigrationKey}\"]"; From fa98bc7e027c8785b413ffbbd80511048ec7f7a5 Mon Sep 17 00:00:00 2001 From: bbsadmin Date: Mon, 4 Nov 2024 12:46:32 -0800 Subject: [PATCH 07/15] Fix linter errors --- src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs b/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs index 876a74e96..23e0b5f27 100644 --- a/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs +++ b/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs @@ -71,23 +71,18 @@ public async Task Basic(bool useGithubStorage) var tokens = new Dictionary { }; - if (useGithubStorage) - { - tokens = new Dictionary + tokens = useGithubStorage + ? new Dictionary { ["GH_SOURCE_PAT"] = _sourceGithubToken, ["GH_PAT"] = _targetGithubToken, - }; - } - else - { - tokens = new Dictionary + } + : new Dictionary { ["GH_SOURCE_PAT"] = _sourceGithubToken, ["GH_PAT"] = _targetGithubToken, ["AZURE_STORAGE_CONNECTION_STRING"] = _azureStorageConnectionString }; - } var retryPolicy = new RetryPolicy(null); From f94482bb8d30a5cc6391ef0400ea8fcae392b7c9 Mon Sep 17 00:00:00 2001 From: bbsadmin Date: Mon, 4 Nov 2024 14:59:52 -0800 Subject: [PATCH 08/15] Fix CI --- .../GhesToGithub.cs | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs b/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs index 23e0b5f27..4ccd2f73f 100644 --- a/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs +++ b/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs @@ -25,10 +25,9 @@ public sealed class GhesToGithub : IDisposable private readonly GithubClient _sourceGithubClient; private readonly GithubApi _sourceGithubApi; private readonly BlobServiceClient _blobServiceClient; + private readonly Dictionary _tokens; private readonly DateTime _startTime; private readonly ArchiveUploader _archiveUploader; - private readonly string _sourceGithubToken; - private readonly string _targetGithubToken; private readonly string _azureStorageConnectionString; public GhesToGithub(ITestOutputHelper output) @@ -38,19 +37,24 @@ public GhesToGithub(ITestOutputHelper output) var logger = new OctoLogger(_ => { }, x => _output.WriteLine(x), _ => { }, _ => { }); - _sourceGithubToken = Environment.GetEnvironmentVariable("GHES_PAT"); - _targetGithubToken = Environment.GetEnvironmentVariable("GHEC_PAT"); + var sourceGithubToken = Environment.GetEnvironmentVariable("GHES_PAT"); + var targetGithubToken = Environment.GetEnvironmentVariable("GHEC_PAT"); _azureStorageConnectionString = Environment.GetEnvironmentVariable($"AZURE_STORAGE_CONNECTION_STRING_GHES_{TestHelper.GetOsName().ToUpper()}"); + _tokens = new Dictionary + { + ["GH_SOURCE_PAT"] = sourceGithubToken, + ["GH_PAT"] = targetGithubToken, + }; _versionClient = new HttpClient(); _archiveUploader = new ArchiveUploader(_targetGithubClient, logger); _sourceGithubHttpClient = new HttpClient(); - _sourceGithubClient = new GithubClient(logger, _sourceGithubHttpClient, new VersionChecker(_versionClient, logger), new RetryPolicy(logger), new DateTimeProvider(), _sourceGithubToken); + _sourceGithubClient = new GithubClient(logger, _sourceGithubHttpClient, new VersionChecker(_versionClient, logger), new RetryPolicy(logger), new DateTimeProvider(), sourceGithubToken); _sourceGithubApi = new GithubApi(_sourceGithubClient, GHES_API_URL, new RetryPolicy(logger), _archiveUploader); _targetGithubHttpClient = new HttpClient(); - _targetGithubClient = new GithubClient(logger, _targetGithubHttpClient, new VersionChecker(_versionClient, logger), new RetryPolicy(logger), new DateTimeProvider(), _targetGithubToken); + _targetGithubClient = new GithubClient(logger, _targetGithubHttpClient, new VersionChecker(_versionClient, logger), new RetryPolicy(logger), new DateTimeProvider(), targetGithubToken); _targetGithubApi = new GithubApi(_targetGithubClient, "https://api.github.com", new RetryPolicy(logger), _archiveUploader); _blobServiceClient = new BlobServiceClient(_azureStorageConnectionString); @@ -69,23 +73,13 @@ public async Task Basic(bool useGithubStorage) const string repo1 = "repo-1"; const string repo2 = "repo-2"; - var tokens = new Dictionary { }; - - tokens = useGithubStorage - ? new Dictionary - { - ["GH_SOURCE_PAT"] = _sourceGithubToken, - ["GH_PAT"] = _targetGithubToken, - } - : new Dictionary - { - ["GH_SOURCE_PAT"] = _sourceGithubToken, - ["GH_PAT"] = _targetGithubToken, - ["AZURE_STORAGE_CONNECTION_STRING"] = _azureStorageConnectionString - }; - var retryPolicy = new RetryPolicy(null); + if (!useGithubStorage) + { + _tokens["AZURE_STORAGE_CONNECTION_STRING"] = _azureStorageConnectionString; + } + await retryPolicy.Retry(async () => { if (!useGithubStorage) @@ -107,7 +101,7 @@ await retryPolicy.Retry(async () => command += " --use-github-storage true"; } - await _targetHelper.RunGeiCliMigration(command, tokens); + await _targetHelper.RunGeiCliMigration(command, _tokens); _targetHelper.AssertNoErrorInLogs(_startTime); From 5f929e1bd4456e743f3e1196722e282c76a58e3f Mon Sep 17 00:00:00 2001 From: bbsadmin Date: Mon, 4 Nov 2024 15:59:29 -0800 Subject: [PATCH 09/15] fix bug --- src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs | 2 +- .../GenerateScript/GenerateScriptCommandArgs.cs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs b/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs index 4ccd2f73f..948fa83da 100644 --- a/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs +++ b/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs @@ -98,7 +98,7 @@ await retryPolicy.Retry(async () => var command = $"generate-script --github-source-org {githubSourceOrg} --github-target-org {githubTargetOrg} --ghes-api-url {GHES_API_URL} --download-migration-logs"; if (useGithubStorage) { - command += " --use-github-storage true"; + command += " --use-github-storage"; } await _targetHelper.RunGeiCliMigration(command, _tokens); diff --git a/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs b/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs index 9123381c5..e3e0e9832 100644 --- a/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs +++ b/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs @@ -45,6 +45,11 @@ public override void Validate(OctoLogger log) throw new OctoshiftCliException("--ghes-api-url must be specified when --no-ssl-verify is specified."); } + if (!GhesApiUrl.HasValue() && UseGithubStorage) + { + throw new OctoshiftCliException("--ghes-api-url must be specified when --use-github-storage is specified."); + } + if (GhesApiUrl.HasValue()) { var result = Uri.TryCreate(GhesApiUrl, UriKind.Absolute, out var uriResult) @@ -54,11 +59,6 @@ public override void Validate(OctoLogger log) { throw new OctoshiftCliException("--ghes-api-url is invalid. Please check URL before trying again."); } - - if (UseGithubStorage) - { - throw new OctoshiftCliException("--ghes-api-url must be specified when --use-github-storage is specified."); - } } } } From cb24bd98a4b2c4502955096b0b90b32272ea4b7e Mon Sep 17 00:00:00 2001 From: bbsadmin Date: Mon, 4 Nov 2024 16:58:52 -0800 Subject: [PATCH 10/15] Fix logic for conditional in command args --- src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs b/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs index e3e0e9832..20537a93b 100644 --- a/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs +++ b/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs @@ -45,7 +45,7 @@ public override void Validate(OctoLogger log) throw new OctoshiftCliException("--ghes-api-url must be specified when --no-ssl-verify is specified."); } - if (!GhesApiUrl.HasValue() && UseGithubStorage) + if (GhesApiUrl.IsNullOrWhiteSpace() && UseGithubStorage) { throw new OctoshiftCliException("--ghes-api-url must be specified when --use-github-storage is specified."); } From bc2cc766a5ea5d922be88195fdc95c21ff262c11 Mon Sep 17 00:00:00 2001 From: bbsadmin Date: Mon, 4 Nov 2024 17:01:23 -0800 Subject: [PATCH 11/15] Add release notes --- releasenotes/v1.8.1.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/releasenotes/v1.8.1.md b/releasenotes/v1.8.1.md index 687ac5d31..41d953644 100644 --- a/releasenotes/v1.8.1.md +++ b/releasenotes/v1.8.1.md @@ -1 +1,2 @@ -Add `--use-github-storage` to gh [gei|bbs2gh] migrate-repo command to support uploading to a GitHub owned storage \ No newline at end of file +Add `--use-github-storage` to gh [gei|bbs2gh] migrate-repo command to support uploading to a GitHub owned storage +Add `--use-github-storage` to gh gei migrate-repo command to support uploading to a GitHub owned storage \ No newline at end of file From 12e358eb055736cb04f0bcb1bd595ba10db05e5d Mon Sep 17 00:00:00 2001 From: bbsadmin Date: Mon, 4 Nov 2024 17:47:19 -0800 Subject: [PATCH 12/15] Fix unit tests --- .../GenerateScriptCommandHandlerTests.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandHandlerTests.cs b/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandHandlerTests.cs index 2a5a718c5..f594c012f 100644 --- a/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandHandlerTests.cs +++ b/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandHandlerTests.cs @@ -1106,11 +1106,13 @@ exit 1 public async Task Sequential_Github_Single_Repo_With_UseGithubStorage() { // Arrange + var GHES_API_URL = "https://foo.com/api/v3"; + _mockGithubApi .Setup(m => m.GetRepos(SOURCE_ORG)) .ReturnsAsync(new[] { (REPO, "private") }); - var expected = $"Exec {{ gh gei migrate-repo --github-source-org \"{SOURCE_ORG}\" --source-repo \"{REPO}\" --github-target-org \"{TARGET_ORG}\" --target-repo \"{REPO}\" --target-repo-visibility private --use-github-storage true }}"; + 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 \"{GHES_API_URL}\" --use-github-storage --target-repo-visibility private }}"; // Act var args = new GenerateScriptCommandArgs @@ -1119,7 +1121,8 @@ public async Task Sequential_Github_Single_Repo_With_UseGithubStorage() GithubTargetOrg = TARGET_ORG, Output = new FileInfo("unit-test-output"), Sequential = true, - UseGithubStorage = true + UseGithubStorage = true, + GhesApiUrl = GHES_API_URL, }; await _handler.Handle(args); @@ -1138,7 +1141,7 @@ public async Task Parallel_Github_Single_Repo_With_UseGithubStorage() .ReturnsAsync(new[] { (REPO, "private") }); var expected = new StringBuilder(); - expected.AppendLine($"$MigrationID = ExecAndGetMigrationID {{ gh gei migrate-repo --github-source-org \"{SOURCE_ORG}\" --source-repo \"{REPO}\" --github-target-org \"{TARGET_ORG}\" --target-repo \"{REPO}\" --queue-only --target-repo-visibility private --use-github-storage true }}"); + 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 \"https://foo.com/api/v3\" --use-github-storage --queue-only --target-repo-visibility private }}"); expected.AppendLine($"$RepoMigrations[\"{REPO}\"] = $MigrationID"); expected.Append($"if ($RepoMigrations[\"{REPO}\"]) {{ gh gei wait-for-migration --migration-id $RepoMigrations[\"{REPO}\"] }}"); @@ -1148,7 +1151,8 @@ public async Task Parallel_Github_Single_Repo_With_UseGithubStorage() GithubSourceOrg = SOURCE_ORG, GithubTargetOrg = TARGET_ORG, Output = new FileInfo("unit-test-output"), - UseGithubStorage = true + UseGithubStorage = true, + GhesApiUrl = "https://foo.com/api/v3", }; await _handler.Handle(args); @@ -1159,6 +1163,7 @@ public async Task Parallel_Github_Single_Repo_With_UseGithubStorage() } + [Fact] public async Task Validates_Env_Vars_Blob_Storage_Not_Validated_When_GHES_3_8() { From 978ed3b342db092a78c5751197943b2befe70050 Mon Sep 17 00:00:00 2001 From: bbsadmin Date: Mon, 4 Nov 2024 18:03:42 -0800 Subject: [PATCH 13/15] Add tests for command unit tests --- .../GenerateScriptCommandTests.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandTests.cs b/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandTests.cs index c7bc43c30..d77beac6f 100644 --- a/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandTests.cs +++ b/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandTests.cs @@ -87,5 +87,40 @@ public void It_Uses_Github_Source_Pat_When_Provided() _mockGithubApiFactory.Verify(m => m.Create(It.IsAny(), args.GithubSourcePat), Times.Once); } + + [Fact] + public void UseGithubStorage_Without_Ghes_Api_Url_Throws() + { + var args = new GenerateScriptCommandArgs + { + GithubSourceOrg = "foo", + GithubTargetOrg = "bar", + UseGithubStorage = true + }; + + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*--use-github-storage*"); + } + + + [Fact] + public void UseGithubStorage_And_Aws_Bucket_Name_Throws() + { + var args = new GenerateScriptCommandArgs + { + GithubSourceOrg = "foo", + GithubTargetOrg = "bar", + AwsBucketName = "aws", + GhesApiUrl = "https://github.contoso.com", + UseGithubStorage = true + }; + + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*--use-github-storage flag was provided with an AWS S3 Bucket name*"); + } } } From 255e5ef6d07db714f6e2b4ccae233efca2edd27b Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Mon, 4 Nov 2024 18:23:33 -0800 Subject: [PATCH 14/15] Update releasenotes/v1.8.1.md Co-authored-by: Arin Ghazarian --- releasenotes/v1.8.1.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/releasenotes/v1.8.1.md b/releasenotes/v1.8.1.md index 41d953644..3485c7b1c 100644 --- a/releasenotes/v1.8.1.md +++ b/releasenotes/v1.8.1.md @@ -1,2 +1,2 @@ -Add `--use-github-storage` to gh [gei|bbs2gh] migrate-repo command to support uploading to a GitHub owned storage -Add `--use-github-storage` to gh gei migrate-repo command to support uploading to a GitHub owned storage \ No newline at end of file +Add `--use-github-storage` to `gh [gei|bbs2gh] migrate-repo` command to support uploading to a GitHub owned storage +Add `--use-github-storage` to `gh gei generate-script` command to support uploading to a GitHub owned storage \ No newline at end of file From f4e0d8b6dbeefafa134ae11027d53fa0e52484da Mon Sep 17 00:00:00 2001 From: bbsadmin Date: Wed, 6 Nov 2024 10:19:16 -0800 Subject: [PATCH 15/15] Move tests --- .../GenerateScriptCommandArgsTests.cs | 35 +++++++++++++++++++ .../GenerateScriptCommandTests.cs | 35 ------------------- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandArgsTests.cs b/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandArgsTests.cs index 40933f515..981b0ce5c 100644 --- a/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandArgsTests.cs +++ b/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandArgsTests.cs @@ -72,5 +72,40 @@ public void It_Throws_When_Invalid_URL_Provided() .Should() .Throw(); } + + [Fact] + public void UseGithubStorage_Without_Ghes_Api_Url_Throws() + { + var args = new GenerateScriptCommandArgs + { + GithubSourceOrg = "foo", + GithubTargetOrg = "bar", + UseGithubStorage = true + }; + + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*--use-github-storage*"); + } + + + [Fact] + public void UseGithubStorage_And_Aws_Bucket_Name_Throws() + { + var args = new GenerateScriptCommandArgs + { + GithubSourceOrg = "foo", + GithubTargetOrg = "bar", + AwsBucketName = "aws", + GhesApiUrl = "https://github.contoso.com", + UseGithubStorage = true + }; + + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*--use-github-storage flag was provided with an AWS S3 Bucket name*"); + } } } diff --git a/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandTests.cs b/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandTests.cs index d77beac6f..c7bc43c30 100644 --- a/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandTests.cs +++ b/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandTests.cs @@ -87,40 +87,5 @@ public void It_Uses_Github_Source_Pat_When_Provided() _mockGithubApiFactory.Verify(m => m.Create(It.IsAny(), args.GithubSourcePat), Times.Once); } - - [Fact] - public void UseGithubStorage_Without_Ghes_Api_Url_Throws() - { - var args = new GenerateScriptCommandArgs - { - GithubSourceOrg = "foo", - GithubTargetOrg = "bar", - UseGithubStorage = true - }; - - FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) - .Should() - .ThrowExactly() - .WithMessage("*--use-github-storage*"); - } - - - [Fact] - public void UseGithubStorage_And_Aws_Bucket_Name_Throws() - { - var args = new GenerateScriptCommandArgs - { - GithubSourceOrg = "foo", - GithubTargetOrg = "bar", - AwsBucketName = "aws", - GhesApiUrl = "https://github.contoso.com", - UseGithubStorage = true - }; - - FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) - .Should() - .ThrowExactly() - .WithMessage("*--use-github-storage flag was provided with an AWS S3 Bucket name*"); - } } }