From 799077ef470b9b45f3c976d5e1e7b4dea0798fbf Mon Sep 17 00:00:00 2001 From: Aakash Date: Tue, 24 Jun 2025 16:56:24 +0530 Subject: [PATCH 1/7] Fix/1180-Add validation to prevent URLs in org and repo fields improve test targeting --- .../GenerateScriptCommandArgsTests.cs | 47 ++++++++++ .../MigrateOrg/MigrateOrgCommandArgsTests.cs | 65 ++++++++++++++ .../MigrateRepoCommandArgsTests.cs | 85 +++++++++++++++++++ .../GenerateScriptCommandArgs.cs | 9 ++ .../MigrateOrg/MigrateOrgCommandArgs.cs | 16 +++- .../MigrateRepo/MigrateRepoCommandArgs.cs | 22 ++++- 6 files changed, 242 insertions(+), 2 deletions(-) diff --git a/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandArgsTests.cs b/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandArgsTests.cs index 981b0ce5c..a60751adf 100644 --- a/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandArgsTests.cs +++ b/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandArgsTests.cs @@ -107,5 +107,52 @@ public void UseGithubStorage_And_Aws_Bucket_Name_Throws() .ThrowExactly() .WithMessage("*--use-github-storage flag was provided with an AWS S3 Bucket name*"); } + [Fact] + public void Throws_If_Url_Passed_In_GithubSourceOrg() + { + var args = new GenerateScriptCommandArgs + { + GithubSourceOrg = "https://github.com/foo", + GithubTargetOrg = "bar", + GhesApiUrl = "https://github.contoso.com" + }; + + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*GithubSourceOrg should be an org name, not a URL*"); + } + + [Fact] + public void Throws_If_Url_Passed_In_GithubTargetOrg() + { + var args = new GenerateScriptCommandArgs + { + GithubSourceOrg = "foo", + GithubTargetOrg = "https://github.com/bar", + GhesApiUrl = "https://github.contoso.com" + }; + + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*GithubTargetOrg should be an org name, not a URL*"); + } + + [Fact] + public void Throws_If_Url_Passed_In_Both_Source_And_Target_Org() + { + var args = new GenerateScriptCommandArgs + { + GithubSourceOrg = "https://github.com/foo", + GithubTargetOrg = "https://github.com/bar", + GhesApiUrl = "https://github.contoso.com" + }; + + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("GithubSourceOrg should be an org name, not a URL."); + } } } diff --git a/src/OctoshiftCLI.Tests/gei/Commands/MigrateOrg/MigrateOrgCommandArgsTests.cs b/src/OctoshiftCLI.Tests/gei/Commands/MigrateOrg/MigrateOrgCommandArgsTests.cs index e5508275b..afecc38b4 100644 --- a/src/OctoshiftCLI.Tests/gei/Commands/MigrateOrg/MigrateOrgCommandArgsTests.cs +++ b/src/OctoshiftCLI.Tests/gei/Commands/MigrateOrg/MigrateOrgCommandArgsTests.cs @@ -30,5 +30,70 @@ public void Source_Pat_Defaults_To_Target_Pat() args.GithubSourcePat.Should().Be(TARGET_PAT); } + [Fact] + public void Throws_If_Url_Passed_In_GithubSourceOrg() + { + var args = new MigrateOrgCommandArgs + { + GithubSourceOrg = "https://github.com/foo", + GithubTargetOrg = TARGET_ORG, + GithubTargetEnterprise = TARGET_ENTERPRISE, + GithubTargetPat = TARGET_PAT, + }; + + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*GithubSourceOrg should be an org name, not a URL*"); + } + + [Fact] + public void Throws_If_Url_Passed_In_GithubTargetOrg() + { + var args = new MigrateOrgCommandArgs + { + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = "https://github.com/foo", + GithubTargetEnterprise = TARGET_ENTERPRISE, + GithubTargetPat = TARGET_PAT, + }; + + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*GithubTargetOrg should be an org name, not a URL*"); + } + + [Fact] + public void Throws_If_Url_Passed_In_Both_Source_And_Target_Org() + { + var args = new MigrateOrgCommandArgs + { + GithubSourceOrg = "https://github.com/foo", + GithubTargetOrg = "https://github.com/bar", + GithubTargetEnterprise = TARGET_ENTERPRISE, + GithubTargetPat = TARGET_PAT, + }; + + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("GithubSourceOrg should be an org name, not a URL."); + } + [Fact] + public void Throws_If_Url_Passed_In_GithubTargetEnterprise() + { + var args = new MigrateOrgCommandArgs + { + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + GithubTargetEnterprise = "https://github.com/foo", + GithubTargetPat = TARGET_PAT, + }; + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*GithubTargetEnterprise should be an enterprise name, not a URL*"); + } } } diff --git a/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs b/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs index ae8b994b4..c506401f2 100644 --- a/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs +++ b/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs @@ -308,5 +308,90 @@ public void MetadataArchiveUrl_With_MetadataArchivePath_Throws() .ThrowExactly() .WithMessage("*--metadata-archive-url and --metadata-archive-path may not be used together*"); } + [Fact] + public void It_Throws_Error_When_Url_Provided_In_GithubSourceOrg() + { + var args = new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = "https://github.com/foo", + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + MetadataArchiveUrl = METADATA_ARCHIVE_URL, + MetadataArchivePath = METADATA_ARCHIVE_PATH + }; + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*GithubSourceOrg should be an org name, not a URL*"); + } + [Fact] + public void It_Throws_Error_When_Url_Provided_In_GithubTargetOrg() + { + var args = new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = "https://github.com/bar", + TargetRepo = TARGET_REPO, + MetadataArchiveUrl = METADATA_ARCHIVE_URL, + MetadataArchivePath = METADATA_ARCHIVE_PATH + }; + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*GithubTargetOrg should be an org name, not a URL*"); + } + [Fact] + public void It_Throws_Error_When_Url_Provided_In_Both_Source_And_Target_Org() + { + var args = new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = "https://github.com/foo", + GithubTargetOrg = "https://github.com/bar", + TargetRepo = TARGET_REPO, + MetadataArchiveUrl = METADATA_ARCHIVE_URL, + MetadataArchivePath = METADATA_ARCHIVE_PATH + }; + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*GithubSourceOrg should be an org name, not a URL*"); + } + [Fact] + public void It_Throws_Error_When_Url_Provided_In_SourceRepo() + { + var args = new MigrateRepoCommandArgs + { + SourceRepo = "https://github.com/foo", + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + MetadataArchiveUrl = METADATA_ARCHIVE_URL, + MetadataArchivePath = METADATA_ARCHIVE_PATH + }; + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*SourceRepo should be a repo name, not a URL*"); + } + [Fact] + public void It_Throws_Error_When_Url_Provided_In_TargetRepo() + { + var args = new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + TargetRepo = "https://github.com/bar", + MetadataArchiveUrl = METADATA_ARCHIVE_URL, + MetadataArchivePath = METADATA_ARCHIVE_PATH + }; + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*TargetRepo should be a repo name, not a URL*"); + } } } diff --git a/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs b/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs index 52bfd7f52..7bcb5d2a3 100644 --- a/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs +++ b/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs @@ -28,6 +28,15 @@ public class GenerateScriptCommandArgs : CommandArgs public override void Validate(OctoLogger log) { + if (GithubSourceOrg.HasValue() && Uri.IsWellFormedUriString(GithubSourceOrg, UriKind.Absolute)) + { + throw new OctoshiftCliException("GithubSourceOrg should be an org name, not a URL."); + } + + if (GithubTargetOrg.HasValue() && Uri.IsWellFormedUriString(GithubTargetOrg, UriKind.Absolute)) + { + throw new OctoshiftCliException("GithubTargetOrg should be an org name, not a URL."); + } if (AwsBucketName.HasValue()) { if (GhesApiUrl.IsNullOrWhiteSpace()) diff --git a/src/gei/Commands/MigrateOrg/MigrateOrgCommandArgs.cs b/src/gei/Commands/MigrateOrg/MigrateOrgCommandArgs.cs index 4b9a85ae8..3cc3c8f30 100644 --- a/src/gei/Commands/MigrateOrg/MigrateOrgCommandArgs.cs +++ b/src/gei/Commands/MigrateOrg/MigrateOrgCommandArgs.cs @@ -1,4 +1,5 @@ -using OctoshiftCLI.Commands; +using System; +using OctoshiftCLI.Commands; using OctoshiftCLI.Extensions; using OctoshiftCLI.Services; @@ -19,6 +20,19 @@ public class MigrateOrgCommandArgs : CommandArgs public override void Validate(OctoLogger log) { + if (GithubSourceOrg.HasValue() && Uri.IsWellFormedUriString(GithubSourceOrg, UriKind.Absolute)) + { + throw new OctoshiftCliException("GithubSourceOrg should be an org name, not a URL."); + } + + if (GithubTargetOrg.HasValue() && Uri.IsWellFormedUriString(GithubTargetOrg, UriKind.Absolute)) + { + throw new OctoshiftCliException("GithubTargetOrg should be an org name, not a URL."); + } + if(GithubTargetEnterprise.HasValue() && Uri.IsWellFormedUriString(GithubTargetEnterprise, UriKind.Absolute)) + { + throw new OctoshiftCliException("GithubTargetEnterprise should be an enterprise name, not a URL."); + } if (GithubTargetPat.HasValue() && GithubSourcePat.IsNullOrWhiteSpace()) { GithubSourcePat = GithubTargetPat; diff --git a/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs b/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs index 58b24171a..46228514e 100644 --- a/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs +++ b/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs @@ -1,4 +1,5 @@ -using OctoshiftCLI.Commands; +using System; +using OctoshiftCLI.Commands; using OctoshiftCLI.Extensions; using OctoshiftCLI.Services; @@ -44,6 +45,25 @@ public override void Validate(OctoLogger log) DefaultSourcePat(log); DefaultTargetRepo(log); + if (!string.IsNullOrWhiteSpace(GithubSourceOrg) && Uri.IsWellFormedUriString(GithubSourceOrg, UriKind.Absolute)) + { + throw new OctoshiftCliException("GithubSourceOrg should be an org name, not a URL."); + } + + if (!string.IsNullOrWhiteSpace(GithubTargetOrg) && Uri.IsWellFormedUriString(GithubTargetOrg, UriKind.Absolute)) + { + throw new OctoshiftCliException("GithubTargetOrg should be an org name, not a URL."); + } + + if (!string.IsNullOrWhiteSpace(SourceRepo) && Uri.IsWellFormedUriString(SourceRepo, UriKind.Absolute)) + { + throw new OctoshiftCliException("SourceRepo should be a repo name, not a URL."); + } + + if (!string.IsNullOrWhiteSpace(TargetRepo) && Uri.IsWellFormedUriString(TargetRepo, UriKind.Absolute)) + { + throw new OctoshiftCliException("TargetRepo should be a repo name, not a URL."); + } if (GitArchiveUrl.HasValue() && GitArchivePath.HasValue()) { throw new OctoshiftCliException("The options --git-archive-url and --git-archive-path may not be used together"); From ec5c2393e0fcb4e573d1846ced9de033abb27ebb Mon Sep 17 00:00:00 2001 From: Aakash Date: Tue, 24 Jun 2025 17:28:01 +0530 Subject: [PATCH 2/7] refactor: reduce Validate() complexity to resolve CA1502 warning --- .../MigrateRepoCommandArgsTests.cs | 10 ------ .../MigrateRepo/MigrateRepoCommandArgs.cs | 34 ++++++++----------- 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs b/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs index c506401f2..d3dca3e4b 100644 --- a/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs +++ b/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs @@ -317,8 +317,6 @@ public void It_Throws_Error_When_Url_Provided_In_GithubSourceOrg() GithubSourceOrg = "https://github.com/foo", GithubTargetOrg = TARGET_ORG, TargetRepo = TARGET_REPO, - MetadataArchiveUrl = METADATA_ARCHIVE_URL, - MetadataArchivePath = METADATA_ARCHIVE_PATH }; FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) .Should() @@ -334,8 +332,6 @@ public void It_Throws_Error_When_Url_Provided_In_GithubTargetOrg() GithubSourceOrg = SOURCE_ORG, GithubTargetOrg = "https://github.com/bar", TargetRepo = TARGET_REPO, - MetadataArchiveUrl = METADATA_ARCHIVE_URL, - MetadataArchivePath = METADATA_ARCHIVE_PATH }; FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) .Should() @@ -351,8 +347,6 @@ public void It_Throws_Error_When_Url_Provided_In_Both_Source_And_Target_Org() GithubSourceOrg = "https://github.com/foo", GithubTargetOrg = "https://github.com/bar", TargetRepo = TARGET_REPO, - MetadataArchiveUrl = METADATA_ARCHIVE_URL, - MetadataArchivePath = METADATA_ARCHIVE_PATH }; FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) .Should() @@ -368,8 +362,6 @@ public void It_Throws_Error_When_Url_Provided_In_SourceRepo() GithubSourceOrg = SOURCE_ORG, GithubTargetOrg = TARGET_ORG, TargetRepo = TARGET_REPO, - MetadataArchiveUrl = METADATA_ARCHIVE_URL, - MetadataArchivePath = METADATA_ARCHIVE_PATH }; FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) .Should() @@ -385,8 +377,6 @@ public void It_Throws_Error_When_Url_Provided_In_TargetRepo() GithubSourceOrg = SOURCE_ORG, GithubTargetOrg = TARGET_ORG, TargetRepo = "https://github.com/bar", - MetadataArchiveUrl = METADATA_ARCHIVE_URL, - MetadataArchivePath = METADATA_ARCHIVE_PATH }; FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) .Should() diff --git a/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs b/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs index 46228514e..dc0801aa6 100644 --- a/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs +++ b/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs @@ -45,25 +45,6 @@ public override void Validate(OctoLogger log) DefaultSourcePat(log); DefaultTargetRepo(log); - if (!string.IsNullOrWhiteSpace(GithubSourceOrg) && Uri.IsWellFormedUriString(GithubSourceOrg, UriKind.Absolute)) - { - throw new OctoshiftCliException("GithubSourceOrg should be an org name, not a URL."); - } - - if (!string.IsNullOrWhiteSpace(GithubTargetOrg) && Uri.IsWellFormedUriString(GithubTargetOrg, UriKind.Absolute)) - { - throw new OctoshiftCliException("GithubTargetOrg should be an org name, not a URL."); - } - - if (!string.IsNullOrWhiteSpace(SourceRepo) && Uri.IsWellFormedUriString(SourceRepo, UriKind.Absolute)) - { - throw new OctoshiftCliException("SourceRepo should be a repo name, not a URL."); - } - - if (!string.IsNullOrWhiteSpace(TargetRepo) && Uri.IsWellFormedUriString(TargetRepo, UriKind.Absolute)) - { - throw new OctoshiftCliException("TargetRepo should be a repo name, not a URL."); - } if (GitArchiveUrl.HasValue() && GitArchivePath.HasValue()) { 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) { 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."); } + ValidateOrgAndRepoNames(); return; } private void DefaultTargetRepo(OctoLogger log) @@ -135,5 +117,19 @@ private void DefaultSourcePat(OctoLogger log) log?.LogInformation("Since github-target-pat is provided, github-source-pat will also use its value."); } } + private void ValidateOrgAndRepoNames() + { + if (!string.IsNullOrWhiteSpace(GithubSourceOrg) && Uri.IsWellFormedUriString(GithubSourceOrg, UriKind.Absolute)) + throw new OctoshiftCliException("GithubSourceOrg should be an org name, not a URL."); + + if (!string.IsNullOrWhiteSpace(GithubTargetOrg) && Uri.IsWellFormedUriString(GithubTargetOrg, UriKind.Absolute)) + throw new OctoshiftCliException("GithubTargetOrg should be an org name, not a URL."); + + if (!string.IsNullOrWhiteSpace(SourceRepo) && Uri.IsWellFormedUriString(SourceRepo, UriKind.Absolute)) + throw new OctoshiftCliException("SourceRepo should be a repo name, not a URL."); + + if (!string.IsNullOrWhiteSpace(TargetRepo) && Uri.IsWellFormedUriString(TargetRepo, UriKind.Absolute)) + throw new OctoshiftCliException("TargetRepo should be a repo name, not a URL."); + } } } From 5e9d6fa32d779f0692e2966ed59a0fb009c86a9d Mon Sep 17 00:00:00 2001 From: Aakash Date: Tue, 24 Jun 2025 17:31:26 +0530 Subject: [PATCH 3/7] Fix: fixed the dotnet format --- .../Commands/MigrateRepo/MigrateRepoCommandArgs.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs b/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs index dc0801aa6..4f88161d2 100644 --- a/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs +++ b/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs @@ -120,16 +120,21 @@ private void DefaultSourcePat(OctoLogger log) private void ValidateOrgAndRepoNames() { if (!string.IsNullOrWhiteSpace(GithubSourceOrg) && Uri.IsWellFormedUriString(GithubSourceOrg, UriKind.Absolute)) + { throw new OctoshiftCliException("GithubSourceOrg should be an org name, not a URL."); - + } if (!string.IsNullOrWhiteSpace(GithubTargetOrg) && Uri.IsWellFormedUriString(GithubTargetOrg, UriKind.Absolute)) + { throw new OctoshiftCliException("GithubTargetOrg should be an org name, not a URL."); - + } if (!string.IsNullOrWhiteSpace(SourceRepo) && Uri.IsWellFormedUriString(SourceRepo, UriKind.Absolute)) + { throw new OctoshiftCliException("SourceRepo should be a repo name, not a URL."); - + } if (!string.IsNullOrWhiteSpace(TargetRepo) && Uri.IsWellFormedUriString(TargetRepo, UriKind.Absolute)) + { throw new OctoshiftCliException("TargetRepo should be a repo name, not a URL."); + } } } } From 28168b7143cc546d5cc5d21a3c475c70ac49f3ae Mon Sep 17 00:00:00 2001 From: Aakash Date: Tue, 24 Jun 2025 17:34:59 +0530 Subject: [PATCH 4/7] Fixed the dotnet format issue in the pipeline --- .../gei/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs b/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs index d3dca3e4b..c2691494f 100644 --- a/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs +++ b/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs @@ -351,7 +351,7 @@ public void It_Throws_Error_When_Url_Provided_In_Both_Source_And_Target_Org() FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) .Should() .ThrowExactly() - .WithMessage("*GithubSourceOrg should be an org name, not a URL*"); + .WithMessage("*GithubSourceOrg should be an org name, not a URL*"); } [Fact] public void It_Throws_Error_When_Url_Provided_In_SourceRepo() @@ -377,7 +377,7 @@ public void It_Throws_Error_When_Url_Provided_In_TargetRepo() GithubSourceOrg = SOURCE_ORG, GithubTargetOrg = TARGET_ORG, TargetRepo = "https://github.com/bar", - }; + }; FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) .Should() .ThrowExactly() From 16756fc6147c9f0da12e2de3a26743b7ee645b4e Mon Sep 17 00:00:00 2001 From: Aakash Date: Tue, 24 Jun 2025 17:38:49 +0530 Subject: [PATCH 5/7] Fix whitespace formatting --- src/gei/Commands/MigrateOrg/MigrateOrgCommandArgs.cs | 2 +- src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gei/Commands/MigrateOrg/MigrateOrgCommandArgs.cs b/src/gei/Commands/MigrateOrg/MigrateOrgCommandArgs.cs index 3cc3c8f30..00ffa3a43 100644 --- a/src/gei/Commands/MigrateOrg/MigrateOrgCommandArgs.cs +++ b/src/gei/Commands/MigrateOrg/MigrateOrgCommandArgs.cs @@ -29,7 +29,7 @@ public override void Validate(OctoLogger log) { throw new OctoshiftCliException("GithubTargetOrg should be an org name, not a URL."); } - if(GithubTargetEnterprise.HasValue() && Uri.IsWellFormedUriString(GithubTargetEnterprise, UriKind.Absolute)) + if (GithubTargetEnterprise.HasValue() && Uri.IsWellFormedUriString(GithubTargetEnterprise, UriKind.Absolute)) { throw new OctoshiftCliException("GithubTargetEnterprise should be an enterprise name, not a URL."); } diff --git a/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs b/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs index 4f88161d2..a1405e5ce 100644 --- a/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs +++ b/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs @@ -97,7 +97,7 @@ public override void Validate(OctoLogger log) { 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."); } - ValidateOrgAndRepoNames(); return; + ValidateOrgAndRepoNames(); return; } private void DefaultTargetRepo(OctoLogger log) From ffefaa1df4da34eaebbf9339e4946ece938b2204 Mon Sep 17 00:00:00 2001 From: Aakash Date: Tue, 24 Jun 2025 19:29:52 +0530 Subject: [PATCH 6/7] Refactor org/repo validation for clarity and consistency --- src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs b/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs index a1405e5ce..bd426dab6 100644 --- a/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs +++ b/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs @@ -97,7 +97,7 @@ public override void Validate(OctoLogger log) { 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."); } - ValidateOrgAndRepoNames(); return; + ValidateOrgAndRepoNames(); } private void DefaultTargetRepo(OctoLogger log) @@ -119,19 +119,19 @@ private void DefaultSourcePat(OctoLogger log) } private void ValidateOrgAndRepoNames() { - if (!string.IsNullOrWhiteSpace(GithubSourceOrg) && Uri.IsWellFormedUriString(GithubSourceOrg, UriKind.Absolute)) + if (GithubSourceOrg.HasValue() && Uri.IsWellFormedUriString(GithubSourceOrg, UriKind.Absolute)) { throw new OctoshiftCliException("GithubSourceOrg should be an org name, not a URL."); } - if (!string.IsNullOrWhiteSpace(GithubTargetOrg) && Uri.IsWellFormedUriString(GithubTargetOrg, UriKind.Absolute)) + if (GithubTargetOrg.HasValue() && Uri.IsWellFormedUriString(GithubTargetOrg, UriKind.Absolute)) { throw new OctoshiftCliException("GithubTargetOrg should be an org name, not a URL."); } - if (!string.IsNullOrWhiteSpace(SourceRepo) && Uri.IsWellFormedUriString(SourceRepo, UriKind.Absolute)) + if (SourceRepo.HasValue() && Uri.IsWellFormedUriString(SourceRepo, UriKind.Absolute)) { throw new OctoshiftCliException("SourceRepo should be a repo name, not a URL."); } - if (!string.IsNullOrWhiteSpace(TargetRepo) && Uri.IsWellFormedUriString(TargetRepo, UriKind.Absolute)) + if (TargetRepo.HasValue() && Uri.IsWellFormedUriString(TargetRepo, UriKind.Absolute)) { throw new OctoshiftCliException("TargetRepo should be a repo name, not a URL."); } From eb6d32ff045a32535784030f7b0acedf3c685dad Mon Sep 17 00:00:00 2001 From: AakashSureshCprime Date: Sun, 6 Jul 2025 20:04:11 +0530 Subject: [PATCH 7/7] refactor: Rename ValidateOrgAndRepoNames to ValidateNamesAreNotUrls --- src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs b/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs index bd426dab6..57e686322 100644 --- a/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs +++ b/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs @@ -97,7 +97,7 @@ public override void Validate(OctoLogger log) { 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."); } - ValidateOrgAndRepoNames(); + ValidateNamesAreNotUrls(); } private void DefaultTargetRepo(OctoLogger log) @@ -117,7 +117,7 @@ private void DefaultSourcePat(OctoLogger log) log?.LogInformation("Since github-target-pat is provided, github-source-pat will also use its value."); } } - private void ValidateOrgAndRepoNames() + private void ValidateNamesAreNotUrls() { if (GithubSourceOrg.HasValue() && Uri.IsWellFormedUriString(GithubSourceOrg, UriKind.Absolute)) {