Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@

- Added `--target-api-url` as an optional arg to the `add-team-to-repo`
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ 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);
TestHelpers.VerifyCommandOption(command.Options, "team", true);
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]
Expand Down
8 changes: 6 additions & 2 deletions src/ado2gh/Commands/AddTeamToRepo/AddTeamToRepoCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public AddTeamToRepoCommand() : base(
AddOption(Role.FromAmong("pull", "push", "admin", "maintain", "triage"));
AddOption(GithubPat);
AddOption(Verbose);
AddOption(TargetApiUrl);
}

public Option<string> GithubOrg { get; } = new("--github-org")
Expand All @@ -42,7 +43,10 @@ public AddTeamToRepoCommand() : base(
};
public Option<string> GithubPat { get; } = new("--github-pat");
public Option<bool> Verbose { get; } = new("--verbose");

public Option<string> 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)
Expand All @@ -57,7 +61,7 @@ public override AddTeamToRepoCommandHandler BuildHandler(AddTeamToRepoCommandArg

var log = sp.GetRequiredService<OctoLogger>();
var targetGithubApiFactory = sp.GetRequiredService<ITargetGithubApiFactory>();
var githubApi = targetGithubApiFactory.Create(targetPersonalAccessToken: args.GithubPat);
var githubApi = targetGithubApiFactory.Create(apiUrl: args.TargetApiUrl, targetPersonalAccessToken: args.GithubPat);

return new AddTeamToRepoCommandHandler(log, githubApi);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public class AddTeamToRepoCommandArgs : CommandArgs
public string Role { get; set; }
[Secret]
public string GithubPat { get; set; }
public string TargetApiUrl { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ private async Task<string> GenerateSequentialScript(IDictionary<string, string>
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))
Expand Down Expand Up @@ -275,8 +275,8 @@ private async Task<string> GenerateParallelScript(IDictionary<string, string> 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);
Expand Down Expand Up @@ -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) =>
Expand Down
Loading