Skip to content

Commit

Permalink
create team command changes
Browse files Browse the repository at this point in the history
  • Loading branch information
brianaj committed Feb 6, 2024
1 parent 300dc84 commit e2befc6
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Octoshift/Commands/CreateTeam/CreateTeamCommandArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public class CreateTeamCommandArgs : CommandArgs
public string IdpGroup { get; set; }
[Secret]
public string GithubPat { get; set; }
public string TargetApiUrl { get; set; }
}
8 changes: 6 additions & 2 deletions src/Octoshift/Commands/CreateTeam/CreateTeamCommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public CreateTeamCommandBase() : base(name: "create-team", description: "Creates
{
Description = "Personal access token of the GitHub target. Overrides GH_PAT environment variable."
};

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 virtual Option<bool> Verbose { get; } = new("--verbose") { IsRequired = false };

public override CreateTeamCommandHandler BuildHandler(CreateTeamCommandArgs args, IServiceProvider sp)
Expand All @@ -40,7 +43,7 @@ public override CreateTeamCommandHandler BuildHandler(CreateTeamCommandArgs args
var log = sp.GetRequiredService<OctoLogger>();
var githubApiFactory = sp.GetRequiredService<ITargetGithubApiFactory>();

var githubApi = githubApiFactory.Create(targetPersonalAccessToken: args.GithubPat);
var githubApi = githubApiFactory.Create(args.TargetApiUrl, args.GithubPat);

return new CreateTeamCommandHandler(log, githubApi);
}
Expand All @@ -52,5 +55,6 @@ protected void AddOptions()
AddOption(IdpGroup);
AddOption(GithubPat);
AddOption(Verbose);
AddOption(TargetApiUrl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,21 @@ public void It_Uses_Github_Source_Pat_When_Provided()

_mockGithubApiFactory.Verify(m => m.Create(It.IsAny<string>(), args.GithubPat), Times.Once);
}

[Fact]
public void It_Uses_Target_Api_Url_When_Provided()
{
var targetApiUrl = "https://api.github.com";

var args = new CreateTeamCommandArgs
{
GithubOrg = "foo",
TeamName = "blah",
TargetApiUrl = targetApiUrl
};

_command.BuildHandler(args, _serviceProvider);

_mockGithubApiFactory.Verify(m => m.Create(args.TargetApiUrl, null), Times.Once);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ public void Should_Have_Options()
var command = new CreateTeamCommand();
Assert.NotNull(command);
Assert.Equal("create-team", command.Name);
Assert.Equal(5, command.Options.Count);
Assert.Equal(6, command.Options.Count);

TestHelpers.VerifyCommandOption(command.Options, "github-org", true);
TestHelpers.VerifyCommandOption(command.Options, "team-name", true);
TestHelpers.VerifyCommandOption(command.Options, "idp-group", false);
TestHelpers.VerifyCommandOption(command.Options, "github-pat", false);
TestHelpers.VerifyCommandOption(command.Options, "verbose", false);
TestHelpers.VerifyCommandOption(command.Options, "target-api-url", false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ public void Should_Have_Options()
var command = new CreateTeamCommand();
Assert.NotNull(command);
Assert.Equal("create-team", command.Name);
Assert.Equal(5, command.Options.Count);
Assert.Equal(6, command.Options.Count);

TestHelpers.VerifyCommandOption(command.Options, "github-org", true);
TestHelpers.VerifyCommandOption(command.Options, "team-name", true);
TestHelpers.VerifyCommandOption(command.Options, "idp-group", false);
TestHelpers.VerifyCommandOption(command.Options, "github-pat", false);
TestHelpers.VerifyCommandOption(command.Options, "verbose", false);
TestHelpers.VerifyCommandOption(command.Options, "target-api-url", false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ public void Should_Have_Options()
var command = new CreateTeamCommand();
Assert.NotNull(command);
Assert.Equal("create-team", command.Name);
Assert.Equal(5, command.Options.Count);
Assert.Equal(6, command.Options.Count);

TestHelpers.VerifyCommandOption(command.Options, "github-org", true);
TestHelpers.VerifyCommandOption(command.Options, "team-name", true);
TestHelpers.VerifyCommandOption(command.Options, "idp-group", false);
TestHelpers.VerifyCommandOption(command.Options, "github-target-pat", false);
TestHelpers.VerifyCommandOption(command.Options, "verbose", false);
TestHelpers.VerifyCommandOption(command.Options, "target-api-url", false);
}
}

0 comments on commit e2befc6

Please sign in to comment.