Skip to content

Commit 1a7dac2

Browse files
committed
Merge external PR #1400: Add --target-api-url support to add-team-to-repo command
# Conflicts: # RELEASENOTES.md
2 parents a06667b + 815043d commit 1a7dac2

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

RELEASENOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+
- Added `--target-api-url` as an optional arg to the `add-team-to-repo` command

src/OctoshiftCLI.Tests/ado2gh/Commands/AddTeamToRepo/AddTeamToRepoCommandTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ public void Should_Have_Options()
3333
var command = new AddTeamToRepoCommand();
3434
Assert.NotNull(command);
3535
Assert.Equal("add-team-to-repo", command.Name);
36-
Assert.Equal(6, command.Options.Count);
36+
Assert.Equal(7, command.Options.Count);
3737

3838
TestHelpers.VerifyCommandOption(command.Options, "github-org", true);
3939
TestHelpers.VerifyCommandOption(command.Options, "github-repo", true);
4040
TestHelpers.VerifyCommandOption(command.Options, "team", true);
4141
TestHelpers.VerifyCommandOption(command.Options, "role", true);
4242
TestHelpers.VerifyCommandOption(command.Options, "github-pat", false);
4343
TestHelpers.VerifyCommandOption(command.Options, "verbose", false);
44+
TestHelpers.VerifyCommandOption(command.Options, "target-api-url", false);
4445
}
4546

4647
[Fact]

src/ado2gh/Commands/AddTeamToRepo/AddTeamToRepoCommand.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public AddTeamToRepoCommand() : base(
2121
AddOption(Role.FromAmong("pull", "push", "admin", "maintain", "triage"));
2222
AddOption(GithubPat);
2323
AddOption(Verbose);
24+
AddOption(TargetApiUrl);
2425
}
2526

2627
public Option<string> GithubOrg { get; } = new("--github-org")
@@ -42,7 +43,10 @@ public AddTeamToRepoCommand() : base(
4243
};
4344
public Option<string> GithubPat { get; } = new("--github-pat");
4445
public Option<bool> Verbose { get; } = new("--verbose");
45-
46+
public Option<string> TargetApiUrl { get; } = new("--target-api-url")
47+
{
48+
Description = "The URL of the target API, if not migrating to github.com. Defaults to https://api.github.com"
49+
};
4650
public override AddTeamToRepoCommandHandler BuildHandler(AddTeamToRepoCommandArgs args, IServiceProvider sp)
4751
{
4852
if (args is null)
@@ -57,7 +61,7 @@ public override AddTeamToRepoCommandHandler BuildHandler(AddTeamToRepoCommandArg
5761

5862
var log = sp.GetRequiredService<OctoLogger>();
5963
var targetGithubApiFactory = sp.GetRequiredService<ITargetGithubApiFactory>();
60-
var githubApi = targetGithubApiFactory.Create(targetPersonalAccessToken: args.GithubPat);
64+
var githubApi = targetGithubApiFactory.Create(apiUrl: args.TargetApiUrl, targetPersonalAccessToken: args.GithubPat);
6165

6266
return new AddTeamToRepoCommandHandler(log, githubApi);
6367
}

src/ado2gh/Commands/AddTeamToRepo/AddTeamToRepoCommandArgs.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ public class AddTeamToRepoCommandArgs : CommandArgs
1010
public string Role { get; set; }
1111
[Secret]
1212
public string GithubPat { get; set; }
13+
public string TargetApiUrl { get; set; }
1314
}
1415
}

src/ado2gh/Commands/GenerateScript/GenerateScriptCommandHandler.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ private async Task<string> GenerateSequentialScript(IDictionary<string, string>
166166
AppendLine(content, Exec(LockAdoRepoScript(adoOrg, adoTeamProject, adoRepo.Name)));
167167
AppendLine(content, Exec(MigrateRepoScript(adoOrg, adoTeamProject, adoRepo.Name, githubOrg, githubRepo, true, adoServerUrl, targetApiUrl)));
168168
AppendLine(content, Exec(DisableAdoRepoScript(adoOrg, adoTeamProject, adoRepo.Name)));
169-
AppendLine(content, Exec(AddMaintainersToGithubRepoScript(adoTeamProject, githubOrg, githubRepo)));
170-
AppendLine(content, Exec(AddAdminsToGithubRepoScript(adoTeamProject, githubOrg, githubRepo)));
169+
AppendLine(content, Exec(AddMaintainersToGithubRepoScript(adoTeamProject, githubOrg, githubRepo, targetApiUrl)));
170+
AppendLine(content, Exec(AddAdminsToGithubRepoScript(adoTeamProject, githubOrg, githubRepo, targetApiUrl)));
171171
AppendLine(content, Exec(DownloadMigrationLogScript(githubOrg, githubRepo, targetApiUrl)));
172172

173173
foreach (var adoPipeline in await _adoInspectorService.GetPipelines(adoOrg, adoTeamProject, adoRepo.Name))
@@ -275,8 +275,8 @@ private async Task<string> GenerateParallelScript(IDictionary<string, string> ap
275275
{
276276
AppendLine(content, " ExecBatch @(");
277277
AppendLine(content, " " + Wrap(DisableAdoRepoScript(adoOrg, adoTeamProject, adoRepo.Name)));
278-
AppendLine(content, " " + Wrap(AddMaintainersToGithubRepoScript(adoTeamProject, githubOrg, githubRepo)));
279-
AppendLine(content, " " + Wrap(AddAdminsToGithubRepoScript(adoTeamProject, githubOrg, githubRepo)));
278+
AppendLine(content, " " + Wrap(AddMaintainersToGithubRepoScript(adoTeamProject, githubOrg, githubRepo, targetApiUrl)));
279+
AppendLine(content, " " + Wrap(AddAdminsToGithubRepoScript(adoTeamProject, githubOrg, githubRepo, targetApiUrl)));
280280
AppendLine(content, " " + Wrap(DownloadMigrationLogScript(githubOrg, githubRepo, targetApiUrl)));
281281

282282
appIds.TryGetValue(adoOrg, out var appId);
@@ -360,14 +360,14 @@ private string CreateGithubAdminsTeamScript(string adoTeamProject, string github
360360
? $"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)}"
361361
: null;
362362

363-
private string AddMaintainersToGithubRepoScript(string adoTeamProject, string githubOrg, string githubRepo) =>
363+
private string AddMaintainersToGithubRepoScript(string adoTeamProject, string githubOrg, string githubRepo, string targetApiUrl) =>
364364
_generateScriptOptions.CreateTeams
365-
? $"gh ado2gh add-team-to-repo --github-org \"{githubOrg}\" --github-repo \"{githubRepo}\" --team \"{adoTeamProject.ReplaceInvalidCharactersWithDash()}-Maintainers\" --role \"maintain\"{(_log.Verbose ? " --verbose" : string.Empty)}"
365+
? $"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)}"
366366
: null;
367367

368-
private string AddAdminsToGithubRepoScript(string adoTeamProject, string githubOrg, string githubRepo) =>
368+
private string AddAdminsToGithubRepoScript(string adoTeamProject, string githubOrg, string githubRepo, string targetApiUrl) =>
369369
_generateScriptOptions.CreateTeams
370-
? $"gh ado2gh add-team-to-repo --github-org \"{githubOrg}\" --github-repo \"{githubRepo}\" --team \"{adoTeamProject.ReplaceInvalidCharactersWithDash()}-Admins\" --role \"admin\"{(_log.Verbose ? " --verbose" : string.Empty)}"
370+
? $"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)}"
371371
: null;
372372

373373
private string RewireAzurePipelineScript(string adoOrg, string adoTeamProject, string adoPipeline, string githubOrg, string githubRepo, string appId) =>

0 commit comments

Comments
 (0)