Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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 `--ghes-api-url` as an optional arg to the `add-team-to-repo`
2 changes: 1 addition & 1 deletion src/Octoshift/Services/GithubApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public virtual async Task AddTeamSync(string org, string teamName, string groupI
await _client.PatchAsync(url, payload);
}

public virtual async Task AddTeamToRepo(string org, string repo, string teamSlug, string role)
public virtual async Task AddTeamToRepo(string org, string repo, string teamSlug, string role, string targetApiUrl = null)
{
var url = $"{_apiUrl}/orgs/{org.EscapeDataString()}/teams/{teamSlug.EscapeDataString()}/repos/{org.EscapeDataString()}/{repo.EscapeDataString()}";
Copy link

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

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

The targetApiUrl parameter is added but never used in the method implementation. The method still uses the instance field _apiUrl instead of the provided targetApiUrl parameter.

Suggested change
var url = $"{_apiUrl}/orgs/{org.EscapeDataString()}/teams/{teamSlug.EscapeDataString()}/repos/{org.EscapeDataString()}/{repo.EscapeDataString()}";
var apiUrl = string.IsNullOrEmpty(targetApiUrl) ? _apiUrl : targetApiUrl;
var url = $"{apiUrl}/orgs/{org.EscapeDataString()}/teams/{teamSlug.EscapeDataString()}/repos/{org.EscapeDataString()}/{repo.EscapeDataString()}";

Copilot uses AI. Check for mistakes.

Copy link
Author

Choose a reason for hiding this comment

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

Parameter removed

var payload = new { permission = role };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public async Task Happy_Path()
};
await _handler.Handle(args);

_mockGithubApi.Verify(x => x.AddTeamToRepo(GITHUB_ORG, GITHUB_REPO, teamSlug, role));
_mockGithubApi.Verify(x => x.AddTeamToRepo(GITHUB_ORG, GITHUB_REPO, teamSlug, role,null));
}
}
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 @@ -26,7 +26,7 @@ public async Task Handle(AddTeamToRepoCommandArgs args)
_log.LogInformation("Adding team to repo...");

var teamSlug = await _githubApi.GetTeamSlug(args.GithubOrg, args.Team);
await _githubApi.AddTeamToRepo(args.GithubOrg, args.GithubRepo, teamSlug, args.Role);
await _githubApi.AddTeamToRepo(args.GithubOrg, args.GithubRepo, teamSlug, args.Role, args.TargetApiUrl);

_log.LogSuccess("Successfully added team to repo");
}
Expand Down
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 @@ -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