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

Add --git-archive-path and --metadata-archive-path options #1294

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -124,6 +128,7 @@ public void It_Throws_When_Aws_Bucket_Name_Provided_With_AzureStorageConnectionS
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*--use-github-storage flag*");
}

[Fact]
public void No_Ssl_Verify_Without_Ghes_Api_Url_Throws()
{
Expand Down Expand Up @@ -159,5 +164,79 @@ public void Keep_Archive_Without_Ghes_Api_Url_Throws()
.ThrowExactly<OctoshiftCliException>()
.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<OctoshiftCliException>()
.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<OctoshiftCliException>()
.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<OctoshiftCliException>()
.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<OctoshiftCliException>()
.WithMessage("*--metadata-archive-url and --metadata-archive-path may not be used together*");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
18 changes: 13 additions & 5 deletions src/gei/Commands/MigrateRepo/MigrateRepoCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public MigrateRepoCommand() : base(
AddOption(GithubTargetOrg);
AddOption(TargetRepo);
AddOption(TargetApiUrl);

AddOption(GhesApiUrl);
AddOption(AzureStorageConnectionString);
AddOption(AwsBucketName);
Expand All @@ -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);
Expand Down Expand Up @@ -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<string> 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<string> 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<bool> SkipReleases { get; } = new("--skip-releases")
{
Description = "Skip releases when migrating."
Expand Down Expand Up @@ -171,7 +179,7 @@ public override MigrateRepoCommandHandler BuildHandler(MigrateRepoCommandArgs ar
AwsApi awsApi = null;
HttpDownloadService httpDownloadService = null;

if (args.GhesApiUrl.HasValue())
if (args.GhesApiUrl.HasValue() || (args.GitArchivePath.HasValue() && args.MetadataArchivePath.HasValue()))
{
var sourceGithubApiFactory = sp.GetRequiredService<ISourceGithubApiFactory>();
var awsApiFactory = sp.GetRequiredService<AwsApiFactory>();
Expand Down
17 changes: 17 additions & 0 deletions src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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())
Expand Down
Loading
Loading