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

Merged
merged 15 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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_FILE_PATH = "./git-archive.tar.gz";
private const string METADATA_ARCHIVE_FILE_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 GitArchiveFilePath_Without_MetadataArchiveFilePath_Throws()
{
var args = new MigrateRepoCommandArgs
{
SourceRepo = SOURCE_REPO,
GithubSourceOrg = SOURCE_ORG,
GithubTargetOrg = TARGET_ORG,
TargetRepo = TARGET_REPO,
GitArchiveFilePath = GIT_ARCHIVE_FILE_PATH
};

FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*you must provide both --git-archive-file-path --metadata-archive-file-path*");
}

[Fact]
public void MetadataArchiveFilePath_Without_GitArchiveFilePath_Throws()
{
var args = new MigrateRepoCommandArgs
{
SourceRepo = SOURCE_REPO,
GithubSourceOrg = SOURCE_ORG,
GithubTargetOrg = TARGET_ORG,
TargetRepo = TARGET_REPO,
MetadataArchiveFilePath = METADATA_ARCHIVE_FILE_PATH
};

FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*you must provide both --git-archive-file-path --metadata-archive-file-path*");
}

[Fact]
public void GitArchiveUrl_With_GitArchiveFilePath_Throws()
{
var args = new MigrateRepoCommandArgs
{
SourceRepo = SOURCE_REPO,
GithubSourceOrg = SOURCE_ORG,
GithubTargetOrg = TARGET_ORG,
TargetRepo = TARGET_REPO,
GitArchiveUrl = GIT_ARCHIVE_URL,
GitArchiveFilePath = GIT_ARCHIVE_FILE_PATH
};

FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*--git-archive-url and --git-archive-file-path may not be used together*");
}

[Fact]
public void MetadataArchiveUrl_With_MetadataArchiveFilePath_Throws()
{
var args = new MigrateRepoCommandArgs
{
SourceRepo = SOURCE_REPO,
GithubSourceOrg = SOURCE_ORG,
GithubTargetOrg = TARGET_ORG,
TargetRepo = TARGET_REPO,
MetadataArchiveUrl = METADATA_ARCHIVE_URL,
MetadataArchiveFilePath = METADATA_ARCHIVE_FILE_PATH
};

FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*--metadata-archive-url and --metadata-archive-file-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-file-path", false, true);
TestHelpers.VerifyCommandOption(command.Options, "metadata-archive-file-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
16 changes: 12 additions & 4 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(GitArchiveFilePath);
AddOption(MetadataArchiveFilePath);
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> GitArchiveFilePath { get; } = new("--git-archive-file-path")
jfine marked this conversation as resolved.
Show resolved Hide resolved
{
IsHidden = true,
Description = "Used to migrate an archive that is on disk, must be used with --metadata-archive-file-path"
};
public Option<string> MetadataArchiveFilePath { get; } = new("--metadata-archive-file-path")
jfine marked this conversation as resolved.
Show resolved Hide resolved
{
IsHidden = true,
Description = "Used to migrate an archive that is on disk, must be used with --git-archive-file-path"
};
public Option<bool> SkipReleases { get; } = new("--skip-releases")
{
Description = "Skip releases when migrating."
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 GitArchiveFilePath { get; set; }
public string MetadataArchiveFilePath { get; set; }
jfine marked this conversation as resolved.
Show resolved Hide resolved
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() && GitArchiveFilePath.HasValue())
{
throw new OctoshiftCliException("The options --git-archive-url and --git-archive-file-path may not be used together");
}

if (MetadataArchiveUrl.HasValue() && MetadataArchiveFilePath.HasValue())
{
throw new OctoshiftCliException("The options --metadata-archive-url and --metadata-archive-file-path may not be used together");
}
ArinGhazarian marked this conversation as resolved.
Show resolved Hide resolved

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(GitArchiveFilePath) != string.IsNullOrWhiteSpace(MetadataArchiveFilePath))
jfine marked this conversation as resolved.
Show resolved Hide resolved
{
throw new OctoshiftCliException("When using archive files, you must provide both --git-archive-file-path --metadata-archive-file-path");
}

if (GhesApiUrl.IsNullOrWhiteSpace())
{
if (AwsBucketName.HasValue())
Expand Down
Loading