diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 8b1378917..dde66af18 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -1 +1 @@ - +- Added `--target-api-url` as an optional arg to the `add-team-to-repo` diff --git a/src/OctoshiftCLI.Tests/ado2gh/Commands/AddTeamToRepo/AddTeamToRepoCommandTests.cs b/src/OctoshiftCLI.Tests/ado2gh/Commands/AddTeamToRepo/AddTeamToRepoCommandTests.cs index a0f421e12..d3f38687e 100644 --- a/src/OctoshiftCLI.Tests/ado2gh/Commands/AddTeamToRepo/AddTeamToRepoCommandTests.cs +++ b/src/OctoshiftCLI.Tests/ado2gh/Commands/AddTeamToRepo/AddTeamToRepoCommandTests.cs @@ -33,7 +33,7 @@ public void Should_Have_Options() var command = new AddTeamToRepoCommand(); Assert.NotNull(command); Assert.Equal("add-team-to-repo", command.Name); - Assert.Equal(6, command.Options.Count); + Assert.Equal(7, command.Options.Count); TestHelpers.VerifyCommandOption(command.Options, "github-org", true); TestHelpers.VerifyCommandOption(command.Options, "github-repo", true); @@ -41,6 +41,7 @@ public void Should_Have_Options() TestHelpers.VerifyCommandOption(command.Options, "role", true); TestHelpers.VerifyCommandOption(command.Options, "github-pat", false); TestHelpers.VerifyCommandOption(command.Options, "verbose", false); + TestHelpers.VerifyCommandOption(command.Options, "target-api-url", false); } [Fact] diff --git a/src/ado2gh/Commands/AddTeamToRepo/AddTeamToRepoCommand.cs b/src/ado2gh/Commands/AddTeamToRepo/AddTeamToRepoCommand.cs index 3afa0563a..9c86d9553 100644 --- a/src/ado2gh/Commands/AddTeamToRepo/AddTeamToRepoCommand.cs +++ b/src/ado2gh/Commands/AddTeamToRepo/AddTeamToRepoCommand.cs @@ -21,6 +21,7 @@ public AddTeamToRepoCommand() : base( AddOption(Role.FromAmong("pull", "push", "admin", "maintain", "triage")); AddOption(GithubPat); AddOption(Verbose); + AddOption(TargetApiUrl); } public Option GithubOrg { get; } = new("--github-org") @@ -42,7 +43,10 @@ public AddTeamToRepoCommand() : base( }; public Option GithubPat { get; } = new("--github-pat"); public Option Verbose { get; } = new("--verbose"); - + public Option TargetApiUrl { get; } = new("--target-api-url") + { + Description = "The URL of the target API, if not migrating to github.com. Defaults to https://api.github.com" + }; public override AddTeamToRepoCommandHandler BuildHandler(AddTeamToRepoCommandArgs args, IServiceProvider sp) { if (args is null) @@ -57,7 +61,7 @@ public override AddTeamToRepoCommandHandler BuildHandler(AddTeamToRepoCommandArg var log = sp.GetRequiredService(); var targetGithubApiFactory = sp.GetRequiredService(); - var githubApi = targetGithubApiFactory.Create(targetPersonalAccessToken: args.GithubPat); + var githubApi = targetGithubApiFactory.Create(apiUrl: args.TargetApiUrl, targetPersonalAccessToken: args.GithubPat); return new AddTeamToRepoCommandHandler(log, githubApi); } diff --git a/src/ado2gh/Commands/AddTeamToRepo/AddTeamToRepoCommandArgs.cs b/src/ado2gh/Commands/AddTeamToRepo/AddTeamToRepoCommandArgs.cs index a230c54ae..57b8ebebb 100644 --- a/src/ado2gh/Commands/AddTeamToRepo/AddTeamToRepoCommandArgs.cs +++ b/src/ado2gh/Commands/AddTeamToRepo/AddTeamToRepoCommandArgs.cs @@ -10,5 +10,6 @@ public class AddTeamToRepoCommandArgs : CommandArgs public string Role { get; set; } [Secret] public string GithubPat { get; set; } + public string TargetApiUrl { get; set; } } } diff --git a/src/ado2gh/Commands/GenerateScript/GenerateScriptCommandHandler.cs b/src/ado2gh/Commands/GenerateScript/GenerateScriptCommandHandler.cs index 335993d0a..874dc4615 100644 --- a/src/ado2gh/Commands/GenerateScript/GenerateScriptCommandHandler.cs +++ b/src/ado2gh/Commands/GenerateScript/GenerateScriptCommandHandler.cs @@ -166,8 +166,8 @@ private async Task GenerateSequentialScript(IDictionary AppendLine(content, Exec(LockAdoRepoScript(adoOrg, adoTeamProject, adoRepo.Name))); AppendLine(content, Exec(MigrateRepoScript(adoOrg, adoTeamProject, adoRepo.Name, githubOrg, githubRepo, true, adoServerUrl, targetApiUrl))); AppendLine(content, Exec(DisableAdoRepoScript(adoOrg, adoTeamProject, adoRepo.Name))); - AppendLine(content, Exec(AddMaintainersToGithubRepoScript(adoTeamProject, githubOrg, githubRepo))); - AppendLine(content, Exec(AddAdminsToGithubRepoScript(adoTeamProject, githubOrg, githubRepo))); + AppendLine(content, Exec(AddMaintainersToGithubRepoScript(adoTeamProject, githubOrg, githubRepo, targetApiUrl))); + AppendLine(content, Exec(AddAdminsToGithubRepoScript(adoTeamProject, githubOrg, githubRepo, targetApiUrl))); AppendLine(content, Exec(DownloadMigrationLogScript(githubOrg, githubRepo, targetApiUrl))); foreach (var adoPipeline in await _adoInspectorService.GetPipelines(adoOrg, adoTeamProject, adoRepo.Name)) @@ -275,8 +275,8 @@ private async Task GenerateParallelScript(IDictionary ap { AppendLine(content, " ExecBatch @("); AppendLine(content, " " + Wrap(DisableAdoRepoScript(adoOrg, adoTeamProject, adoRepo.Name))); - AppendLine(content, " " + Wrap(AddMaintainersToGithubRepoScript(adoTeamProject, githubOrg, githubRepo))); - AppendLine(content, " " + Wrap(AddAdminsToGithubRepoScript(adoTeamProject, githubOrg, githubRepo))); + AppendLine(content, " " + Wrap(AddMaintainersToGithubRepoScript(adoTeamProject, githubOrg, githubRepo, targetApiUrl))); + AppendLine(content, " " + Wrap(AddAdminsToGithubRepoScript(adoTeamProject, githubOrg, githubRepo, targetApiUrl))); AppendLine(content, " " + Wrap(DownloadMigrationLogScript(githubOrg, githubRepo, targetApiUrl))); appIds.TryGetValue(adoOrg, out var appId); @@ -360,14 +360,14 @@ private string CreateGithubAdminsTeamScript(string adoTeamProject, string github ? $"gh ado2gh create-team{(targetApiUrl.HasValue() ? $" --target-api-url \"{targetApiUrl}\"" : string.Empty)} --github-org \"{githubOrg}\" --team-name \"{adoTeamProject.ReplaceInvalidCharactersWithDash()}-Admins\"{(_log.Verbose ? " --verbose" : string.Empty)}{(linkIdpGroups ? $" --idp-group \"{adoTeamProject.ReplaceInvalidCharactersWithDash()}-Admins\"" : string.Empty)}" : null; - private string AddMaintainersToGithubRepoScript(string adoTeamProject, string githubOrg, string githubRepo) => + private string AddMaintainersToGithubRepoScript(string adoTeamProject, string githubOrg, string githubRepo, string targetApiUrl) => _generateScriptOptions.CreateTeams - ? $"gh ado2gh add-team-to-repo --github-org \"{githubOrg}\" --github-repo \"{githubRepo}\" --team \"{adoTeamProject.ReplaceInvalidCharactersWithDash()}-Maintainers\" --role \"maintain\"{(_log.Verbose ? " --verbose" : string.Empty)}" + ? $"gh ado2gh add-team-to-repo{(targetApiUrl.HasValue() ? $" --target-api-url \"{targetApiUrl}\"" : string.Empty)} --github-org \"{githubOrg}\" --github-repo \"{githubRepo}\" --team \"{adoTeamProject.ReplaceInvalidCharactersWithDash()}-Maintainers\" --role \"maintain\"{(_log.Verbose ? " --verbose" : string.Empty)}" : null; - private string AddAdminsToGithubRepoScript(string adoTeamProject, string githubOrg, string githubRepo) => + private string AddAdminsToGithubRepoScript(string adoTeamProject, string githubOrg, string githubRepo, string targetApiUrl) => _generateScriptOptions.CreateTeams - ? $"gh ado2gh add-team-to-repo --github-org \"{githubOrg}\" --github-repo \"{githubRepo}\" --team \"{adoTeamProject.ReplaceInvalidCharactersWithDash()}-Admins\" --role \"admin\"{(_log.Verbose ? " --verbose" : string.Empty)}" + ? $"gh ado2gh add-team-to-repo{(targetApiUrl.HasValue() ? $" --target-api-url \"{targetApiUrl}\"" : string.Empty)} --github-org \"{githubOrg}\" --github-repo \"{githubRepo}\" --team \"{adoTeamProject.ReplaceInvalidCharactersWithDash()}-Admins\" --role \"admin\"{(_log.Verbose ? " --verbose" : string.Empty)}" : null; private string RewireAzurePipelineScript(string adoOrg, string adoTeamProject, string adoPipeline, string githubOrg, string githubRepo, string appId) =>