Skip to content
Merged
Changes from all 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
95 changes: 53 additions & 42 deletions src/gei/Commands/MigrateRepoCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ public async Task Invoke(MigrateRepoCommandArgs args)

_log.Verbose = args.Verbose;

LogAndValidateOptions(args);
LogOptions(args);
ValidateOptions(args);

if (args.GhesApiUrl.HasValue())
{
Expand Down Expand Up @@ -356,112 +357,122 @@ private string GetAdoRepoUrl(string serverUrl, string org, string project, strin
return $"{serverUrl}/{org}/{project}/_git/{repo}".Replace(" ", "%20");
}

private void LogAndValidateOptions(MigrateRepoCommandArgs args)
private void LogOptions(MigrateRepoCommandArgs args)
{
_log.LogInformation("Migrating Repo...");
if (!string.IsNullOrWhiteSpace(args.GithubSourceOrg))
if (args.GithubSourceOrg.HasValue())
{
_log.LogInformation($"GITHUB SOURCE ORG: {args.GithubSourceOrg}");
}
if (!string.IsNullOrWhiteSpace(args.AdoServerUrl))
if (args.AdoServerUrl.HasValue())
{
_log.LogInformation($"ADO SERVER URL: {args.AdoServerUrl}");
}
if (!string.IsNullOrWhiteSpace(args.AdoSourceOrg))
if (args.AdoSourceOrg.HasValue())
{
_log.LogInformation($"ADO SOURCE ORG: {args.AdoSourceOrg}");
}
if (args.AdoTeamProject.HasValue())
{
_log.LogInformation($"ADO TEAM PROJECT: {args.AdoTeamProject}");
}
_log.LogInformation($"SOURCE REPO: {args.SourceRepo}");
_log.LogInformation($"GITHUB TARGET ORG: {args.GithubTargetOrg}");
_log.LogInformation($"TARGET REPO: {args.TargetRepo}");

if (!string.IsNullOrWhiteSpace(args.TargetApiUrl))
if (args.TargetApiUrl.HasValue())
{
_log.LogInformation($"TARGET API URL: {args.TargetApiUrl}");
}

if (args.Ssh)
{
_log.LogWarning("SSH mode is no longer supported. --ssh flag will be ignored");
}

if (args.Wait)
{
_log.LogInformation("WAIT: true");
}

if (args.GithubSourcePat is not null)
if (args.GithubSourcePat.HasValue())
{
_log.LogInformation("GITHUB SOURCE PAT: ***");
}

if (args.GithubTargetPat is not null)
if (args.GithubTargetPat.HasValue())
{
_log.LogInformation("GITHUB TARGET PAT: ***");

if (args.GithubSourcePat is null)
{
args.GithubSourcePat = args.GithubTargetPat;
_log.LogInformation("Since github-target-pat is provided, github-source-pat will also use its value.");
}
}

if (args.AdoPat is not null)
if (args.AdoPat.HasValue())
{
_log.LogInformation("ADO PAT: ***");
}

if (string.IsNullOrWhiteSpace(args.GithubSourceOrg) && string.IsNullOrWhiteSpace(args.AdoSourceOrg))
if (args.GhesApiUrl.HasValue())
{
throw new OctoshiftCliException("Must specify either --github-source-org or --ado-source-org");
_log.LogInformation($"GHES API URL: {args.GhesApiUrl}");
}

if (args.AdoServerUrl.HasValue() && !args.AdoSourceOrg.HasValue())
if (args.AzureStorageConnectionString.HasValue())
{
throw new OctoshiftCliException("Must specify --ado-source-org with the collection name when using --ado-server-url");
_log.LogInformation("AZURE STORAGE CONNECTION STRING: ***");
}

if (string.IsNullOrWhiteSpace(args.GithubSourceOrg) && !string.IsNullOrWhiteSpace(args.AdoSourceOrg) && string.IsNullOrWhiteSpace(args.AdoTeamProject))
if (args.NoSslVerify)
{
throw new OctoshiftCliException("When using --ado-source-org you must also provide --ado-team-project");
_log.LogInformation("SSL verification disabled");
}

if (string.IsNullOrWhiteSpace(args.TargetRepo))
if (args.SkipReleases)
{
_log.LogInformation($"Target repo name not provided, defaulting to same as source repo ({args.SourceRepo})");
args.TargetRepo = args.SourceRepo;
_log.LogInformation("SKIP RELEASES: true");
}

if (args.GhesApiUrl.HasValue())
if (args.GitArchiveUrl.HasValue())
{
_log.LogInformation($"GHES API URL: {args.GhesApiUrl}");
_log.LogInformation($"GIT ARCHIVE URL: {args.GitArchiveUrl}");
}

if (args.AzureStorageConnectionString.HasValue())
if (args.MetadataArchiveUrl.HasValue())
{
_log.LogInformation("AZURE STORAGE CONNECTION STRING: ***");
_log.LogInformation($"METADATA ARCHIVE URL: {args.MetadataArchiveUrl}");
}
}

if (args.NoSslVerify)
private void ValidateOptions(MigrateRepoCommandArgs args)
{
if (args.Ssh)
{
_log.LogInformation("SSL verification disabled");
_log.LogWarning("SSH mode is no longer supported. --ssh flag will be ignored");
}

if (args.SkipReleases)
if (args.GithubTargetPat.HasValue() && args.GithubSourcePat.IsNullOrWhiteSpace())
{
_log.LogInformation("SKIP RELEASES: true");
args.GithubSourcePat = args.GithubTargetPat;
_log.LogInformation("Since github-target-pat is provided, github-source-pat will also use its value.");
}

if (string.IsNullOrWhiteSpace(args.GitArchiveUrl) != string.IsNullOrWhiteSpace(args.MetadataArchiveUrl))
if (args.GithubSourceOrg.IsNullOrWhiteSpace() && args.AdoSourceOrg.IsNullOrWhiteSpace())
{
throw new OctoshiftCliException("When using archive urls, you must provide both --git-archive-url --metadata-archive-url");
throw new OctoshiftCliException("Must specify either --github-source-org or --ado-source-org");
}

if (!string.IsNullOrWhiteSpace(args.MetadataArchiveUrl))
if (args.AdoServerUrl.HasValue() && args.AdoSourceOrg.IsNullOrWhiteSpace())
{
_log.LogInformation($"GIT ARCHIVE URL: {args.GitArchiveUrl}");
_log.LogInformation($"METADATA ARCHIVE URL: {args.MetadataArchiveUrl}");
throw new OctoshiftCliException("Must specify --ado-source-org with the collection name when using --ado-server-url");
}

if (args.GithubSourceOrg.IsNullOrWhiteSpace() && args.AdoSourceOrg.HasValue() && args.AdoTeamProject.IsNullOrWhiteSpace())
{
throw new OctoshiftCliException("When using --ado-source-org you must also provide --ado-team-project");
}

if (args.TargetRepo.IsNullOrWhiteSpace())
{
_log.LogInformation($"Target repo name not provided, defaulting to same as source repo ({args.SourceRepo})");
args.TargetRepo = args.SourceRepo;
}

if (string.IsNullOrWhiteSpace(args.GitArchiveUrl) != string.IsNullOrWhiteSpace(args.MetadataArchiveUrl))
{
throw new OctoshiftCliException("When using archive urls, you must provide both --git-archive-url --metadata-archive-url");
}
}
}
Expand Down