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

Require the Bitbucket Server URL, project and repo name to always be passed for bbs2gh migrate-repo #1057

Merged
merged 2 commits into from
Jul 10, 2023
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
1 change: 1 addition & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- __BREAKING CHANGE__: Require the Bitbucket Server URL, project key and repo to always be provided for `bbs2gh migrate-repo`, even if using the upload-and-migrate (`--archive-path`) or migrate-only (`--archive-url`) flows
- Drop support for deprecated `AWS_ACCESS_KEY` and `AWS_SECRET_KEY` environment variables in `gh gei` and `gh bbs2gh`. The AWS S3 credentials can now be configured using the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` variables or command line arguments.
- Increase timeouts in archive uploads to AWS to prevent timeouts during large uploads
Original file line number Diff line number Diff line change
Expand Up @@ -283,44 +283,6 @@ public void Errors_If_BbsServer_Url_Not_Provided_But_Smb_User_Is_Provided()
.WithMessage("*SSH*SMB*--bbs-server-url*");
}

[Fact]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now validate in the Args class that all 3 arguments are always provided

public void Errors_If_BbsServer_Url_Not_Provided_But_Bbs_Project_Is_Provided()
{
// Act
var args = new MigrateRepoCommandArgs
{
ArchivePath = ARCHIVE_PATH,
GithubOrg = GITHUB_ORG,
GithubRepo = GITHUB_REPO,
BbsProject = BBS_PROJECT
};

// Assert
args.Invoking(x => x.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*--bbs-project*--bbs-server-url*");
}

[Fact]
public void Errors_If_BbsServer_Url_Not_Provided_But_Bbs_Repo_Is_Provided()
{
// Act
var args = new MigrateRepoCommandArgs
{
ArchivePath = ARCHIVE_PATH,
GithubOrg = GITHUB_ORG,
GithubRepo = GITHUB_REPO,
BbsRepo = BBS_REPO
};

// Assert
args.Invoking(x => x.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*--bbs-repo*--bbs-server-url*");
}

[Fact]
public void It_Throws_If_Github_Org_Is_Provided_But_Github_Repo_Is_Not()
{
Expand Down Expand Up @@ -573,7 +535,7 @@ public void Errors_If_Archive_Url_And_Archive_Path_Are_Passed()
}

[Fact]
public void Errors_If_BbsServer_Url_And_Archive_Url_Are_Passed()
public void Allows_BbsServer_Url_And_Archive_Url_To_Be_Passed_Together()
{
// Act
var args = new MigrateRepoCommandArgs
Expand All @@ -587,12 +549,11 @@ public void Errors_If_BbsServer_Url_And_Archive_Url_Are_Passed()
// Assert
args.Invoking(x => x.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*--bbs-server-url*--archive-url*");
.NotThrow();
}

[Fact]
public void Errors_If_BbsServer_Url_And_Archive_Path_Are_Passed()
public void Allows_BbsServer_Url_And_Archive_Path_To_Be_Passed_Together()
{
// Act
var args = new MigrateRepoCommandArgs
Expand All @@ -606,8 +567,7 @@ public void Errors_If_BbsServer_Url_And_Archive_Path_Are_Passed()
// Assert
args.Invoking(x => x.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*--bbs-server-url*--archive-path*");
.NotThrow();
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public void Should_Have_Options()
command.Name.Should().Be("migrate-repo");
command.Options.Count.Should().Be(31);

TestHelpers.VerifyCommandOption(command.Options, "bbs-server-url", false);
TestHelpers.VerifyCommandOption(command.Options, "bbs-project", false);
TestHelpers.VerifyCommandOption(command.Options, "bbs-repo", false);
TestHelpers.VerifyCommandOption(command.Options, "bbs-server-url", true);
TestHelpers.VerifyCommandOption(command.Options, "bbs-project", true);
TestHelpers.VerifyCommandOption(command.Options, "bbs-repo", true);
TestHelpers.VerifyCommandOption(command.Options, "bbs-username", false);
TestHelpers.VerifyCommandOption(command.Options, "bbs-password", false);
TestHelpers.VerifyCommandOption(command.Options, "archive-url", false);
Expand Down
15 changes: 12 additions & 3 deletions src/bbs2gh/Commands/MigrateRepo/MigrateRepoCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,24 @@ public MigrateRepoCommand() : base(

public Option<string> BbsServerUrl { get; } = new(
name: "--bbs-server-url",
description: "The full URL of the Bitbucket Server/Data Center to migrate from. E.g. http://bitbucket.contoso.com:7990");
description: "The full URL of the Bitbucket Server/Data Center to migrate from. E.g. http://bitbucket.contoso.com:7990")
{
IsRequired = true
};

public Option<string> BbsProject { get; } = new(
name: "--bbs-project",
description: "The Bitbucket project to migrate.");
description: "The Bitbucket project to migrate.")
{
IsRequired = true
};

public Option<string> BbsRepo { get; } = new(
name: "--bbs-repo",
description: "The Bitbucket repository to migrate.");
description: "The Bitbucket repository to migrate.")
{
IsRequired = true
};

public Option<string> BbsUsername { get; } = new(
name: "--bbs-username",
Expand Down
18 changes: 2 additions & 16 deletions src/bbs2gh/Commands/MigrateRepo/MigrateRepoCommandArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,6 @@ public override void Validate(OctoLogger log)
throw new OctoshiftCliException("Either --bbs-server-url, --archive-path, or --archive-url must be specified.");
}

if (BbsServerUrl.HasValue() && ArchiveUrl.HasValue())
{
throw new OctoshiftCliException("Only one of --bbs-server-url or --archive-url can be specified.");
}

if (BbsServerUrl.HasValue() && ArchivePath.HasValue())
{
throw new OctoshiftCliException("Only one of --bbs-server-url or --archive-path can be specified.");
}

if (ArchivePath.HasValue() && ArchiveUrl.HasValue())
{
throw new OctoshiftCliException("Only one of --archive-path or --archive-url can be specified.");
Expand Down Expand Up @@ -127,23 +117,19 @@ private void ValidateNoGenerateOptions()
throw new OctoshiftCliException("--no-ssl-verify can only be provided with --bbs-server-url.");
}

if (BbsProject.HasValue() || BbsRepo.HasValue())
{
throw new OctoshiftCliException("--bbs-project and --bbs-repo can only be provided with --bbs-server-url.");
}

if (new[] { SshUser, SshPrivateKey, ArchiveDownloadHost, SmbUser, SmbPassword, SmbDomain }.Any(obj => obj.HasValue()))
{
throw new OctoshiftCliException("SSH or SMB download options can only be provided with --bbs-server-url.");
}
}

public bool ShouldGenerateArchive() => BbsServerUrl.HasValue();
public bool ShouldGenerateArchive() => BbsServerUrl.HasValue() && !ArchivePath.HasValue() && !ArchiveUrl.HasValue();

public bool ShouldDownloadArchive() => SshUser.HasValue() || SmbUser.HasValue();

public bool ShouldUploadArchive() => ArchiveUrl.IsNullOrWhiteSpace() && GithubOrg.HasValue();

// NOTE: ArchiveUrl doesn't necessarily refer to the value passed in by the user to the CLI - it is set during CLI runtime when an archive is uploaded to blob storage
public bool ShouldImportArchive() => ArchiveUrl.HasValue() || GithubOrg.HasValue();

private void ValidateGenerateOptions()
Expand Down