Skip to content

Commit ec5c239

Browse files
refactor: reduce Validate() complexity to resolve CA1502 warning
1 parent 799077e commit ec5c239

File tree

2 files changed

+15
-29
lines changed

2 files changed

+15
-29
lines changed

src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,6 @@ public void It_Throws_Error_When_Url_Provided_In_GithubSourceOrg()
317317
GithubSourceOrg = "https://github.com/foo",
318318
GithubTargetOrg = TARGET_ORG,
319319
TargetRepo = TARGET_REPO,
320-
MetadataArchiveUrl = METADATA_ARCHIVE_URL,
321-
MetadataArchivePath = METADATA_ARCHIVE_PATH
322320
};
323321
FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object))
324322
.Should()
@@ -334,8 +332,6 @@ public void It_Throws_Error_When_Url_Provided_In_GithubTargetOrg()
334332
GithubSourceOrg = SOURCE_ORG,
335333
GithubTargetOrg = "https://github.com/bar",
336334
TargetRepo = TARGET_REPO,
337-
MetadataArchiveUrl = METADATA_ARCHIVE_URL,
338-
MetadataArchivePath = METADATA_ARCHIVE_PATH
339335
};
340336
FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object))
341337
.Should()
@@ -351,8 +347,6 @@ public void It_Throws_Error_When_Url_Provided_In_Both_Source_And_Target_Org()
351347
GithubSourceOrg = "https://github.com/foo",
352348
GithubTargetOrg = "https://github.com/bar",
353349
TargetRepo = TARGET_REPO,
354-
MetadataArchiveUrl = METADATA_ARCHIVE_URL,
355-
MetadataArchivePath = METADATA_ARCHIVE_PATH
356350
};
357351
FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object))
358352
.Should()
@@ -368,8 +362,6 @@ public void It_Throws_Error_When_Url_Provided_In_SourceRepo()
368362
GithubSourceOrg = SOURCE_ORG,
369363
GithubTargetOrg = TARGET_ORG,
370364
TargetRepo = TARGET_REPO,
371-
MetadataArchiveUrl = METADATA_ARCHIVE_URL,
372-
MetadataArchivePath = METADATA_ARCHIVE_PATH
373365
};
374366
FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object))
375367
.Should()
@@ -385,8 +377,6 @@ public void It_Throws_Error_When_Url_Provided_In_TargetRepo()
385377
GithubSourceOrg = SOURCE_ORG,
386378
GithubTargetOrg = TARGET_ORG,
387379
TargetRepo = "https://github.com/bar",
388-
MetadataArchiveUrl = METADATA_ARCHIVE_URL,
389-
MetadataArchivePath = METADATA_ARCHIVE_PATH
390380
};
391381
FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object))
392382
.Should()

src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,6 @@ public override void Validate(OctoLogger log)
4545
DefaultSourcePat(log);
4646
DefaultTargetRepo(log);
4747

48-
if (!string.IsNullOrWhiteSpace(GithubSourceOrg) && Uri.IsWellFormedUriString(GithubSourceOrg, UriKind.Absolute))
49-
{
50-
throw new OctoshiftCliException("GithubSourceOrg should be an org name, not a URL.");
51-
}
52-
53-
if (!string.IsNullOrWhiteSpace(GithubTargetOrg) && Uri.IsWellFormedUriString(GithubTargetOrg, UriKind.Absolute))
54-
{
55-
throw new OctoshiftCliException("GithubTargetOrg should be an org name, not a URL.");
56-
}
57-
58-
if (!string.IsNullOrWhiteSpace(SourceRepo) && Uri.IsWellFormedUriString(SourceRepo, UriKind.Absolute))
59-
{
60-
throw new OctoshiftCliException("SourceRepo should be a repo name, not a URL.");
61-
}
62-
63-
if (!string.IsNullOrWhiteSpace(TargetRepo) && Uri.IsWellFormedUriString(TargetRepo, UriKind.Absolute))
64-
{
65-
throw new OctoshiftCliException("TargetRepo should be a repo name, not a URL.");
66-
}
6748
if (GitArchiveUrl.HasValue() && GitArchivePath.HasValue())
6849
{
6950
throw new OctoshiftCliException("The options --git-archive-url and --git-archive-path may not be used together");
@@ -116,6 +97,7 @@ public override void Validate(OctoLogger log)
11697
{
11798
throw new OctoshiftCliException("The --use-github-storage flag was provided with a connection string for an Azure storage account. Archive cannot be uploaded to both locations.");
11899
}
100+
ValidateOrgAndRepoNames(); return;
119101
}
120102

121103
private void DefaultTargetRepo(OctoLogger log)
@@ -135,5 +117,19 @@ private void DefaultSourcePat(OctoLogger log)
135117
log?.LogInformation("Since github-target-pat is provided, github-source-pat will also use its value.");
136118
}
137119
}
120+
private void ValidateOrgAndRepoNames()
121+
{
122+
if (!string.IsNullOrWhiteSpace(GithubSourceOrg) && Uri.IsWellFormedUriString(GithubSourceOrg, UriKind.Absolute))
123+
throw new OctoshiftCliException("GithubSourceOrg should be an org name, not a URL.");
124+
125+
if (!string.IsNullOrWhiteSpace(GithubTargetOrg) && Uri.IsWellFormedUriString(GithubTargetOrg, UriKind.Absolute))
126+
throw new OctoshiftCliException("GithubTargetOrg should be an org name, not a URL.");
127+
128+
if (!string.IsNullOrWhiteSpace(SourceRepo) && Uri.IsWellFormedUriString(SourceRepo, UriKind.Absolute))
129+
throw new OctoshiftCliException("SourceRepo should be a repo name, not a URL.");
130+
131+
if (!string.IsNullOrWhiteSpace(TargetRepo) && Uri.IsWellFormedUriString(TargetRepo, UriKind.Absolute))
132+
throw new OctoshiftCliException("TargetRepo should be a repo name, not a URL.");
133+
}
138134
}
139135
}

0 commit comments

Comments
 (0)