Skip to content

Fixed the Validation for bbs-shared-home and archive-path #1327

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

Closed
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions src/Octoshift/Services/FileSystemProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ public virtual async Task CopySourceToTargetStreamAsync(Stream source, Stream ta
await source.CopyToAsync(target);
}
}

public virtual bool DirectoryExists(string path) => Directory.Exists(path);
}
21 changes: 20 additions & 1 deletion src/bbs2gh/Commands/MigrateRepo/MigrateRepoCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public async Task Handle(MigrateRepoCommandArgs args)
}

ValidateOptions(args);

var exportId = 0L;
var migrationSourceId = "";

Expand Down Expand Up @@ -384,5 +383,25 @@ private void ValidateUploadOptions(MigrateRepoCommandArgs args)
throw new OctoshiftCliException("Either --aws-region or AWS_REGION environment variable must be set.");
}
}
// Validate BbsSharedHome
if (!string.IsNullOrEmpty(args.BbsSharedHome))
{
if (args.ShouldUploadArchive() && args.ArchivePath.IsNullOrWhiteSpace())
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're already in ValidateUploadOptions there is not need to check for ShouldUploadArchive:

Suggested change
// Validate BbsSharedHome
if (!string.IsNullOrEmpty(args.BbsSharedHome))
{
if (args.ShouldUploadArchive() && args.ArchivePath.IsNullOrWhiteSpace())
if (args.BbsSharedHome.HasValue())
{
if (args.ArchivePath.IsNullOrWhiteSpace())

{
if (args.BbsSharedHome.HasValue() && !_fileSystemProvider.DirectoryExists(args.BbsSharedHome))
{
throw new OctoshiftCliException($"Invalid --bbs-shared-home path: '{args.BbsSharedHome}'. Directory does not exist.");
}
}
}

// Validate ArchivePath
if (!string.IsNullOrEmpty(args.ArchivePath))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change
// Validate ArchivePath
if (!string.IsNullOrEmpty(args.ArchivePath))
if (args.ArchivePath.HasValue())

{
if (!_fileSystemProvider.FileExists(args.ArchivePath))
{
throw new OctoshiftCliException($"Invalid --archive-path: '{args.ArchivePath}'. File does not exist.");
}
}
}
}
Loading