Skip to content

Add support for --target-api-url to rewire-pipeline command #1366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

markphip
Copy link

Add support for --target-api-url to the rewire-pipeline command so that the command can be used when migrating repositories to GHEC with Data Residency

  • Did you write/update appropriate tests
  • Release notes updated (if appropriate)
  • Appropriate logging output
  • Issue linked
  • Docs updated (or issue created)
  • New package licenses are added to ThirdPartyNotices.txt (if applicable)

Fixes Issue #1365

@Copilot Copilot AI review requested due to automatic review settings June 20, 2025 22:37
@markphip
Copy link
Author

The code for this was written for me by Copilot Agent mode in VS but I was able to test and verify that it worked as exptected.

Copy link

@Copilot 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

Adds a new --target-api-url option to the rewire-pipeline command, passes it through the handler into the ADO API call, and updates AdoApi.ChangePipelineRepo to construct repo URLs against a custom API endpoint when provided.

  • Introduce TargetApiUrl option in CLI command and args model
  • Wire args.TargetApiUrl through RewirePipelineCommandHandler into the API call
  • Extend AdoApi.ChangePipelineRepo to branch on targetApiUrl for URL construction and update tests

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/ado2gh/Commands/RewirePipeline/RewirePipelineCommand.cs Add --target-api-url option without a default value
src/ado2gh/Commands/RewirePipeline/RewirePipelineCommandArgs.cs Add TargetApiUrl property
src/ado2gh/Commands/RewirePipeline/RewirePipelineCommandHandler.cs Pass args.TargetApiUrl to ChangePipelineRepo
src/OctoshiftCLI.Tests/ado2gh/Commands/RewirePipeline/RewirePipelineCommandHandlerTests.cs Update happy-path to expect null and add a test for non-null URL
src/Octoshift/Services/AdoApi.cs Implement targetApiUrl logic for building repo URLs
Comments suppressed due to low confidence (1)

src/ado2gh/Commands/RewirePipeline/RewirePipelineCommand.cs:56

  • [nitpick] The CLI option description mentions a default of https://api.github.com, but no default is actually set on the option. Consider specifying a default value on the Option<string> itself to ensure consistent behavior when the flag is omitted.
        public Option<string> TargetApiUrl { get; } = new("--target-api-url")

string apiUrl, webUrl, cloneUrl, branchesUrl, refsUrl, manageUrl;
if (!string.IsNullOrWhiteSpace(targetApiUrl))
{
var apiUri = new Uri(targetApiUrl.TrimEnd('/'));
Copy link
Preview

Copilot AI Jun 20, 2025

Choose a reason for hiding this comment

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

Consider validating the targetApiUrl string (e.g. with Uri.TryCreate) before constructing a Uri, and provide a clear error message if it's invalid, to avoid runtime UriFormatException.

Suggested change
var apiUri = new Uri(targetApiUrl.TrimEnd('/'));
if (!Uri.TryCreate(targetApiUrl.TrimEnd('/'), UriKind.Absolute, out var apiUri))
{
throw new ArgumentException($"The provided targetApiUrl '{targetApiUrl}' is not a valid absolute URI.", nameof(targetApiUrl));
}

Copilot uses AI. Check for mistakes.

Copy link

github-actions bot commented Jun 20, 2025

Unit Test Results

  1 files    1 suites   20s ⏱️
889 tests 889 ✅ 0 💤 0 ❌
890 runs  890 ✅ 0 💤 0 ❌

Results for commit e1646a1.

♻️ This comment has been updated with latest results.

orgName = githubOrg,
refsUrl = $"https://api.github.com/repos/{githubOrg.EscapeDataString()}/{githubRepo.EscapeDataString()}/git/refs",
refsUrl,
safeRepository = $"{githubOrg.EscapeDataString()}/{githubRepo.EscapeDataString()}",
shortName = githubRepo,
reportBuildStatus = true
},
id = $"{githubOrg}/{githubRepo}",
type = "GitHub",
Copy link
Author

Choose a reason for hiding this comment

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

Even though this worked for me, I am not 100% certain this does not need to be a different value if the repository is on GHES or GHEC with Data Residency

{
var url = $"{_adoBaseUrl}/{adoOrg.EscapeDataString()}/{teamProject.EscapeDataString()}/_apis/build/definitions/{pipelineId}?api-version=6.0";

var response = await _client.GetAsync(url);
var data = JObject.Parse(response);

// Determine base URLs
string apiUrl, webUrl, cloneUrl, branchesUrl, refsUrl, manageUrl;
if (!string.IsNullOrWhiteSpace(targetApiUrl))
Copy link
Collaborator

@dylan-smith dylan-smith Jun 20, 2025

Choose a reason for hiding this comment

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

Use our extension method HasValue() to do this check

Suggested change
if (!string.IsNullOrWhiteSpace(targetApiUrl))
if (targetApiUrl.HasValue())

@dylan-smith
Copy link
Collaborator

There'll need to be some unit tests for the changes in AdoApi

Copy link

Code Coverage

Package Line Rate Branch Rate Complexity Health
bbs2gh 82% 76% 669
Octoshift 87% 76% 1414
gei 81% 73% 596
ado2gh 84% 78% 633
Summary 84% (7255 / 8591) 76% (1694 / 2242) 3312

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.

2 participants