diff --git a/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs b/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs index 6104bd4c2..c1da1e2fa 100644 --- a/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs +++ b/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs @@ -16,6 +16,10 @@ public class MigrateRepoCommandArgsTests private const string GITHUB_TARGET_PAT = "github-target-pat"; private const string AWS_BUCKET_NAME = "aws-bucket-name"; private const string GHES_API_URL = "foo-ghes-api.com"; + private const string GIT_ARCHIVE_URL = "http://host/git-archive.tar.gz"; + private const string METADATA_ARCHIVE_URL = "http://host/metadata-archive.tar.gz"; + private const string GIT_ARCHIVE_PATH = "./git-archive.tar.gz"; + private const string METADATA_ARCHIVE_PATH = "./metadata-archive.tar.gz"; [Fact] public void Defaults_TargetRepo_To_SourceRepo() @@ -124,6 +128,7 @@ public void It_Throws_When_Aws_Bucket_Name_Provided_With_AzureStorageConnectionS .ThrowExactly() .WithMessage("*--use-github-storage flag*"); } + [Fact] public void No_Ssl_Verify_Without_Ghes_Api_Url_Throws() { @@ -159,5 +164,79 @@ public void Keep_Archive_Without_Ghes_Api_Url_Throws() .ThrowExactly() .WithMessage("*--keep-archive*"); } + + [Fact] + public void GitArchivePath_Without_MetadataArchivePath_Throws() + { + var args = new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + GitArchivePath = GIT_ARCHIVE_PATH + }; + + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*you must provide both --git-archive-path --metadata-archive-path*"); + } + + [Fact] + public void MetadataArchivePath_Without_GitArchivePath_Throws() + { + var args = new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + MetadataArchivePath = METADATA_ARCHIVE_PATH + }; + + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*you must provide both --git-archive-path --metadata-archive-path*"); + } + + [Fact] + public void GitArchiveUrl_With_GitArchivePath_Throws() + { + var args = new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + GitArchiveUrl = GIT_ARCHIVE_URL, + GitArchivePath = GIT_ARCHIVE_PATH + }; + + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*--git-archive-url and --git-archive-path may not be used together*"); + } + + [Fact] + public void MetadataArchiveUrl_With_MetadataArchivePath_Throws() + { + var args = new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + MetadataArchiveUrl = METADATA_ARCHIVE_URL, + MetadataArchivePath = METADATA_ARCHIVE_PATH + }; + + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*--metadata-archive-url and --metadata-archive-path may not be used together*"); + } } } diff --git a/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandTests.cs b/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandTests.cs index df42dc8b9..be0fc095c 100644 --- a/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandTests.cs +++ b/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandTests.cs @@ -13,7 +13,7 @@ public void Should_Have_Options() command.Should().NotBeNull(); command.Name.Should().Be("migrate-repo"); - command.Options.Count.Should().Be(24); + command.Options.Count.Should().Be(26); TestHelpers.VerifyCommandOption(command.Options, "github-source-org", true); TestHelpers.VerifyCommandOption(command.Options, "source-repo", true); @@ -31,6 +31,8 @@ public void Should_Have_Options() TestHelpers.VerifyCommandOption(command.Options, "skip-releases", false); TestHelpers.VerifyCommandOption(command.Options, "git-archive-url", false, true); TestHelpers.VerifyCommandOption(command.Options, "metadata-archive-url", false, true); + TestHelpers.VerifyCommandOption(command.Options, "git-archive-path", false, true); + TestHelpers.VerifyCommandOption(command.Options, "metadata-archive-path", false, true); TestHelpers.VerifyCommandOption(command.Options, "queue-only", false); TestHelpers.VerifyCommandOption(command.Options, "target-repo-visibility", false); TestHelpers.VerifyCommandOption(command.Options, "github-source-pat", false); diff --git a/src/gei/Commands/MigrateRepo/MigrateRepoCommand.cs b/src/gei/Commands/MigrateRepo/MigrateRepoCommand.cs index 1009c37b7..af5b29c5c 100644 --- a/src/gei/Commands/MigrateRepo/MigrateRepoCommand.cs +++ b/src/gei/Commands/MigrateRepo/MigrateRepoCommand.cs @@ -21,7 +21,6 @@ public MigrateRepoCommand() : base( AddOption(GithubTargetOrg); AddOption(TargetRepo); AddOption(TargetApiUrl); - AddOption(GhesApiUrl); AddOption(AzureStorageConnectionString); AddOption(AwsBucketName); @@ -30,13 +29,12 @@ public MigrateRepoCommand() : base( AddOption(AwsSessionToken); AddOption(AwsRegion); AddOption(NoSslVerify); - AddOption(GitArchiveUrl); AddOption(MetadataArchiveUrl); - + AddOption(GitArchivePath); + AddOption(MetadataArchivePath); AddOption(SkipReleases); AddOption(LockSourceRepo); - AddOption(QueueOnly); AddOption(TargetRepoVisibility.FromAmong("public", "private", "internal")); AddOption(GithubSourcePat); @@ -120,6 +118,16 @@ public MigrateRepoCommand() : base( IsHidden = true, Description = "An authenticated SAS URL to an Azure Blob Storage container with a pre-generated metadata archive. Only used when an archive has been generated and uploaded prior to running a migration (not common). Must be passed in when also using --git-archive-url" }; + public Option GitArchivePath { get; } = new("--git-archive-path") + { + IsHidden = true, + Description = "Used to migrate an archive that is on disk, must be used with --metadata-archive-path" + }; + public Option MetadataArchivePath { get; } = new("--metadata-archive-path") + { + IsHidden = true, + Description = "Used to migrate an archive that is on disk, must be used with --git-archive-path" + }; public Option SkipReleases { get; } = new("--skip-releases") { Description = "Skip releases when migrating." diff --git a/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs b/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs index 73d02c8e3..2287af0fb 100644 --- a/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs +++ b/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs @@ -25,6 +25,8 @@ public class MigrateRepoCommandArgs : CommandArgs public bool NoSslVerify { get; set; } public string GitArchiveUrl { get; set; } public string MetadataArchiveUrl { get; set; } + public string GitArchivePath { get; set; } + public string MetadataArchivePath { get; set; } public bool SkipReleases { get; set; } public bool LockSourceRepo { get; set; } public bool QueueOnly { get; set; } @@ -41,11 +43,26 @@ public override void Validate(OctoLogger log) DefaultSourcePat(log); DefaultTargetRepo(log); + if (GitArchiveUrl.HasValue() && GitArchivePath.HasValue()) + { + throw new OctoshiftCliException("The options --git-archive-url and --git-archive-path may not be used together"); + } + + if (MetadataArchiveUrl.HasValue() && MetadataArchivePath.HasValue()) + { + throw new OctoshiftCliException("The options --metadata-archive-url and --metadata-archive-path may not be used together"); + } + if (string.IsNullOrWhiteSpace(GitArchiveUrl) != string.IsNullOrWhiteSpace(MetadataArchiveUrl)) { throw new OctoshiftCliException("When using archive urls, you must provide both --git-archive-url --metadata-archive-url"); } + if (string.IsNullOrWhiteSpace(GitArchivePath) != string.IsNullOrWhiteSpace(MetadataArchivePath)) + { + throw new OctoshiftCliException("When using archive files, you must provide both --git-archive-path --metadata-archive-path"); + } + if (GhesApiUrl.IsNullOrWhiteSpace()) { if (AwsBucketName.HasValue())