Skip to content

Commit 4fb99ee

Browse files
authored
refactor LogAndValidateOptions (#595)
<!-- For the checkboxes below you must check each one to indicate that you either did the relevant task, or considered it and decided there was nothing that needed doing --> In `gei migrate-repo` the function `LogAndValidateOptions()` had gotten so large that `dotnet format` was starting to complain if you added anything new to it. Like in this other PR: #589 I refactored it into separate `LogOptions()` and `ValidateOptions()` functions, which I think is better even if our linter didn't complain. This is pre-req work for the lock-repo PR and issue #385 - [x] Did you write/update appropriate tests - [x] Release notes updated (if appropriate) - [x] Appropriate logging output - [x] Issue linked - [x] Docs updated (or issue created) <!-- For docs we should review the docs at: https://docs.github.com/en/early-access/github/migrating-with-github-enterprise-importer and the README.md in this repo If a doc update is required based on the changes in this PR, it is sufficient to create an issue and link to it here. The doc update can be made later/separately. The process to update the docs can be found here: https://github.com/github/docs-early-access#opening-prs The markdown files are here: https://github.com/github/docs-early-access/tree/main/content/github/migrating-with-github-enterprise-importer -->
1 parent d0681c1 commit 4fb99ee

File tree

1 file changed

+53
-42
lines changed

1 file changed

+53
-42
lines changed

src/gei/Commands/MigrateRepoCommand.cs

Lines changed: 53 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ public async Task Invoke(MigrateRepoCommandArgs args)
171171

172172
_log.Verbose = args.Verbose;
173173

174-
LogAndValidateOptions(args);
174+
LogOptions(args);
175+
ValidateOptions(args);
175176

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

359-
private void LogAndValidateOptions(MigrateRepoCommandArgs args)
360+
private void LogOptions(MigrateRepoCommandArgs args)
360361
{
361362
_log.LogInformation("Migrating Repo...");
362-
if (!string.IsNullOrWhiteSpace(args.GithubSourceOrg))
363+
if (args.GithubSourceOrg.HasValue())
363364
{
364365
_log.LogInformation($"GITHUB SOURCE ORG: {args.GithubSourceOrg}");
365366
}
366-
if (!string.IsNullOrWhiteSpace(args.AdoServerUrl))
367+
if (args.AdoServerUrl.HasValue())
367368
{
368369
_log.LogInformation($"ADO SERVER URL: {args.AdoServerUrl}");
369370
}
370-
if (!string.IsNullOrWhiteSpace(args.AdoSourceOrg))
371+
if (args.AdoSourceOrg.HasValue())
371372
{
372373
_log.LogInformation($"ADO SOURCE ORG: {args.AdoSourceOrg}");
374+
}
375+
if (args.AdoTeamProject.HasValue())
376+
{
373377
_log.LogInformation($"ADO TEAM PROJECT: {args.AdoTeamProject}");
374378
}
375379
_log.LogInformation($"SOURCE REPO: {args.SourceRepo}");
376380
_log.LogInformation($"GITHUB TARGET ORG: {args.GithubTargetOrg}");
377381
_log.LogInformation($"TARGET REPO: {args.TargetRepo}");
378382

379-
if (!string.IsNullOrWhiteSpace(args.TargetApiUrl))
383+
if (args.TargetApiUrl.HasValue())
380384
{
381385
_log.LogInformation($"TARGET API URL: {args.TargetApiUrl}");
382386
}
383387

384-
if (args.Ssh)
385-
{
386-
_log.LogWarning("SSH mode is no longer supported. --ssh flag will be ignored");
387-
}
388-
389388
if (args.Wait)
390389
{
391390
_log.LogInformation("WAIT: true");
392391
}
393392

394-
if (args.GithubSourcePat is not null)
393+
if (args.GithubSourcePat.HasValue())
395394
{
396395
_log.LogInformation("GITHUB SOURCE PAT: ***");
397396
}
398397

399-
if (args.GithubTargetPat is not null)
398+
if (args.GithubTargetPat.HasValue())
400399
{
401400
_log.LogInformation("GITHUB TARGET PAT: ***");
402-
403-
if (args.GithubSourcePat is null)
404-
{
405-
args.GithubSourcePat = args.GithubTargetPat;
406-
_log.LogInformation("Since github-target-pat is provided, github-source-pat will also use its value.");
407-
}
408401
}
409402

410-
if (args.AdoPat is not null)
403+
if (args.AdoPat.HasValue())
411404
{
412405
_log.LogInformation("ADO PAT: ***");
413406
}
414407

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

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

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

430-
if (string.IsNullOrWhiteSpace(args.TargetRepo))
423+
if (args.SkipReleases)
431424
{
432-
_log.LogInformation($"Target repo name not provided, defaulting to same as source repo ({args.SourceRepo})");
433-
args.TargetRepo = args.SourceRepo;
425+
_log.LogInformation("SKIP RELEASES: true");
434426
}
435427

436-
if (args.GhesApiUrl.HasValue())
428+
if (args.GitArchiveUrl.HasValue())
437429
{
438-
_log.LogInformation($"GHES API URL: {args.GhesApiUrl}");
430+
_log.LogInformation($"GIT ARCHIVE URL: {args.GitArchiveUrl}");
439431
}
440432

441-
if (args.AzureStorageConnectionString.HasValue())
433+
if (args.MetadataArchiveUrl.HasValue())
442434
{
443-
_log.LogInformation("AZURE STORAGE CONNECTION STRING: ***");
435+
_log.LogInformation($"METADATA ARCHIVE URL: {args.MetadataArchiveUrl}");
444436
}
437+
}
445438

446-
if (args.NoSslVerify)
439+
private void ValidateOptions(MigrateRepoCommandArgs args)
440+
{
441+
if (args.Ssh)
447442
{
448-
_log.LogInformation("SSL verification disabled");
443+
_log.LogWarning("SSH mode is no longer supported. --ssh flag will be ignored");
449444
}
450445

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

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

461-
if (!string.IsNullOrWhiteSpace(args.MetadataArchiveUrl))
457+
if (args.AdoServerUrl.HasValue() && args.AdoSourceOrg.IsNullOrWhiteSpace())
462458
{
463-
_log.LogInformation($"GIT ARCHIVE URL: {args.GitArchiveUrl}");
464-
_log.LogInformation($"METADATA ARCHIVE URL: {args.MetadataArchiveUrl}");
459+
throw new OctoshiftCliException("Must specify --ado-source-org with the collection name when using --ado-server-url");
460+
}
461+
462+
if (args.GithubSourceOrg.IsNullOrWhiteSpace() && args.AdoSourceOrg.HasValue() && args.AdoTeamProject.IsNullOrWhiteSpace())
463+
{
464+
throw new OctoshiftCliException("When using --ado-source-org you must also provide --ado-team-project");
465+
}
466+
467+
if (args.TargetRepo.IsNullOrWhiteSpace())
468+
{
469+
_log.LogInformation($"Target repo name not provided, defaulting to same as source repo ({args.SourceRepo})");
470+
args.TargetRepo = args.SourceRepo;
471+
}
472+
473+
if (string.IsNullOrWhiteSpace(args.GitArchiveUrl) != string.IsNullOrWhiteSpace(args.MetadataArchiveUrl))
474+
{
475+
throw new OctoshiftCliException("When using archive urls, you must provide both --git-archive-url --metadata-archive-url");
465476
}
466477
}
467478
}

0 commit comments

Comments
 (0)