Skip to content

Conversation

@brianaj
Copy link
Collaborator

@brianaj brianaj commented Dec 11, 2025

External PR from @AakashSuresh2003 (#1464) to add validation that detects when users accidentally provide URLs instead of names for org/repo/enterprise arguments.

This addresses issue #1180 by providing clear, user-friendly error messages when URL patterns are detected.

Changes:

  • Added IsUrl() extension method using .NET's Uri.TryCreate() for robust URL detection
  • Added validation to all command args classes that accept org/repo/enterprise names
  • Validation checks for http/https URLs and provides clear error messages
  • Comprehensive test coverage across gei, ado2gh, and shared commands

Key features:
✅ Uses standard .NET Uri.TryCreate() validation (not custom pattern matching)
✅ Only detects proper http/https URLs (no false positives)
✅ Clear error messages explaining expected format
✅ 47 new test cases covering all affected commands

Fixes #1180

All 1019 tests passing ✅

AakashSuresh2003 and others added 20 commits December 3, 2025 17:16
…tory, and enterprise name arguments and remove trailing blank lines from test files
Added validation for URL arguments and improved error messages for path options.
…o 1180-fix-url-validation

# Conflicts:
#	RELEASENOTES.md
@brianaj brianaj mentioned this pull request Dec 11, 2025
6 tasks
@github-actions
Copy link

github-actions bot commented Dec 12, 2025

Unit Test Results

    1 files      1 suites   10m 25s ⏱️
1 018 tests 1 018 ✅ 0 💤 0 ❌
1 019 runs  1 019 ✅ 0 💤 0 ❌

Results for commit 94d4c0a.

♻️ This comment has been updated with latest results.

@brianaj brianaj marked this pull request as ready for review December 12, 2025 04:49
@brianaj brianaj requested review from a team and Copilot December 12, 2025 04:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds validation to detect when users accidentally provide URLs instead of names for organization, repository, and enterprise arguments across multiple CLI commands. The implementation uses .NET's built-in Uri.TryCreate() method for robust URL detection and provides clear, actionable error messages.

Key Changes:

  • Added IsUrl() extension method to StringExtensions that validates http/https URLs using .NET's standard URI parsing
  • Implemented validation checks in 14 CommandArgs classes across gei, ado2gh, and shared commands
  • Added 47 comprehensive unit tests covering all validation scenarios

Reviewed changes

Copilot reviewed 29 out of 29 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Octoshift/Extensions/StringExtensions.cs Added IsUrl() extension method using Uri.TryCreate() for URL detection
src/gei/Commands/MigrateSecretAlerts/MigrateSecretAlertsCommandArgs.cs Added URL validation for source/target org and repo parameters
src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs Added URL validation for github-source-org, github-target-org, source-repo, and target-repo
src/gei/Commands/MigrateOrg/MigrateOrgCommandArgs.cs Added URL validation for github-source-org, github-target-org, and github-target-enterprise
src/gei/Commands/MigrateCodeScanningAlerts/MigrateCodeScanningAlertsCommandArgs.cs Added URL validation for source/target org and repo parameters
src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs Added URL validation for github-source-org and github-target-org
src/ado2gh/Commands/MigrateRepo/MigrateRepoCommandArgs.cs Added URL validation for github-org and github-repo parameters
src/ado2gh/Commands/IntegrateBoards/IntegrateBoardsCommandArgs.cs Added URL validation for github-org and github-repo parameters
src/Octoshift/Commands/RevokeMigratorRole/RevokeMigratorRoleCommandArgs.cs Added URL validation for github-org parameter
src/Octoshift/Commands/ReclaimMannequin/ReclaimMannequinCommandArgs.cs Added URL validation for github-org parameter
src/Octoshift/Commands/GrantMigratorRole/GrantMigratorRoleCommandArgs.cs Added URL validation for github-org parameter
src/Octoshift/Commands/GenerateMannequinCsv/GenerateMannequinCsvCommandArgs.cs Added URL validation for github-org parameter
src/Octoshift/Commands/DownloadLogs/DownloadLogsCommandArgs.cs Added URL validation for github-org and github-repo parameters
src/Octoshift/Commands/CreateTeam/CreateTeamCommandArgs.cs Added URL validation for github-org parameter
src/OctoshiftCLI.Tests/StringExtensionsTests.cs Added 14 test cases covering URL detection edge cases
src/OctoshiftCLI.Tests/gei/Commands/MigrateSecretAlerts/MigrateSecretAlertsCommandArgsTests.cs Added 4 test cases for URL validation in MigrateSecretAlerts command
src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs Added 4 test cases for URL validation in MigrateRepo command
src/OctoshiftCLI.Tests/gei/Commands/MigrateOrg/MigrateOrgCommandArgsTests.cs Added 3 test cases for URL validation in MigrateOrg command
src/OctoshiftCLI.Tests/gei/Commands/MigrateCodeScanningAlerts/MigrateCodeScanningAlertsCommandArgsTests.cs Added 4 test cases for URL validation in MigrateCodeScanningAlerts command
src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandArgsTests.cs Added 2 test cases for URL validation in GenerateScript command
src/OctoshiftCLI.Tests/ado2gh/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs Created new test file with 3 test cases for ado2gh MigrateRepo validation
src/OctoshiftCLI.Tests/ado2gh/Commands/IntegrateBoards/IntegrateBoardsCommandArgsTests.cs Created new test file with 3 test cases for IntegrateBoards validation
src/OctoshiftCLI.Tests/Octoshift/Commands/RevokeMigratorRole/RevokeMigratorRoleCommandArgsTests.cs Added 1 test case for URL validation in RevokeMigratorRole command
src/OctoshiftCLI.Tests/Octoshift/Commands/ReclaimMannequin/ReclaimMannequinCommandArgsTests.cs Added 1 test case for URL validation in ReclaimMannequin command
src/OctoshiftCLI.Tests/Octoshift/Commands/GrantMigratorRole/GrantMigratorRoleCommandArgsTests.cs Added 1 test case for URL validation in GrantMigratorRole command
src/OctoshiftCLI.Tests/Octoshift/Commands/GenerateMannequinCsv/GenerateMannequinCsvCommandArgsTests.cs Created new test file with 2 test cases for GenerateMannequinCsv validation
src/OctoshiftCLI.Tests/Octoshift/Commands/DownloadLogs/DownloadLogsCommandArgsTests.cs Created new test file with 3 test cases for DownloadLogs validation
src/OctoshiftCLI.Tests/Octoshift/Commands/CreateTeam/CreateTeamCommandArgsTests.cs Created new test file with 2 test cases for CreateTeam validation
RELEASENOTES.md Added user-friendly release note describing the new validation feature

{
if (GithubOrg.IsUrl())
{
throw new OctoshiftCliException("The --github-org option expects an organization name, not a URL. Please provide just the organization name (e.g., 'my-org' instead of 'https://github.com/my-org').");
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

The error message should use string interpolation ($"...") for consistency with similar error messages throughout the codebase. Even though no variables are currently being interpolated, using string interpolation maintains consistency with other validation error messages in this PR.

Suggested change
throw new OctoshiftCliException("The --github-org option expects an organization name, not a URL. Please provide just the organization name (e.g., 'my-org' instead of 'https://github.com/my-org').");
throw new OctoshiftCliException($"The --github-org option expects an organization name, not a URL. Please provide just the organization name (e.g., 'my-org' instead of 'https://github.com/my-org').");

Copilot uses AI. Check for mistakes.
Comment on lines +21 to +26
throw new OctoshiftCliException("The --github-org option expects an organization name, not a URL. Please provide just the organization name (e.g., 'my-org' instead of 'https://github.com/my-org').");
}

if (GithubRepo.IsUrl())
{
throw new OctoshiftCliException("The --github-repo option expects a repository name, not a URL. Please provide just the repository name (e.g., 'my-repo' instead of 'https://github.com/my-org/my-repo').");
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

The error messages should use string interpolation ($"...") for consistency with similar error messages throughout the codebase. Even though no variables are currently being interpolated, using string interpolation maintains consistency with other validation error messages in this PR.

Suggested change
throw new OctoshiftCliException("The --github-org option expects an organization name, not a URL. Please provide just the organization name (e.g., 'my-org' instead of 'https://github.com/my-org').");
}
if (GithubRepo.IsUrl())
{
throw new OctoshiftCliException("The --github-repo option expects a repository name, not a URL. Please provide just the repository name (e.g., 'my-repo' instead of 'https://github.com/my-org/my-repo').");
throw new OctoshiftCliException($"The --github-org option expects an organization name, not a URL. Please provide just the organization name (e.g., 'my-org' instead of 'https://github.com/my-org').");
}
if (GithubRepo.IsUrl())
{
throw new OctoshiftCliException($"The --github-repo option expects a repository name, not a URL. Please provide just the repository name (e.g., 'my-repo' instead of 'https://github.com/my-org/my-repo').");

Copilot uses AI. Check for mistakes.
{
if (GithubOrg.IsUrl())
{
throw new OctoshiftCliException("The --github-org option expects an organization name, not a URL. Please provide just the organization name (e.g., 'my-org' instead of 'https://github.com/my-org').");
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

The error message should use string interpolation ($"...") for consistency with similar error messages throughout the codebase. Even though no variables are currently being interpolated, using string interpolation maintains consistency with other validation error messages in this PR.

Suggested change
throw new OctoshiftCliException("The --github-org option expects an organization name, not a URL. Please provide just the organization name (e.g., 'my-org' instead of 'https://github.com/my-org').");
throw new OctoshiftCliException($"The --github-org option expects an organization name, not a URL. Please provide just the organization name (e.g., 'my-org' instead of 'https://github.com/my-org').");

Copilot uses AI. Check for mistakes.
@github-actions
Copy link

Code Coverage

Package Line Rate Branch Rate Complexity Health
ado2gh 72% 71% 726
Octoshift 83% 73% 1766
bbs2gh 83% 78% 663
gei 81% 73% 608
Summary 81% (7856 / 9735) 74% (1908 / 2593) 3763

@brianaj brianaj enabled auto-merge December 12, 2025 17:47
Copy link
Member

@dpmex4527 dpmex4527 left a comment

Choose a reason for hiding this comment

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

LGTM!

@brianaj brianaj merged commit 7d5682e into main Dec 12, 2025
40 checks passed
@brianaj brianaj deleted the brianaj/external-pr-1464 branch December 12, 2025 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Return a clear error message when the URL is provided for a repository, organization or enterprise, when the name should be provided

4 participants