diff --git a/Octokit.Tests.Integration/Clients/TeamsClientTests.cs b/Octokit.Tests.Integration/Clients/TeamsClientTests.cs index d68a68af08..1af5833f5d 100644 --- a/Octokit.Tests.Integration/Clients/TeamsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/TeamsClientTests.cs @@ -12,37 +12,32 @@ public class TeamsClientTests public class TheCreateMethod { [OrganizationTest] - public async Task FailsWhenNotAuthenticated() - { - var github = Helper.GetAnonymousClient(); - var newTeam = new NewTeam("Test"); - - var e = await Assert.ThrowsAsync(() => github.Organization.Team.Create(Helper.Organization, newTeam)); - - Assert.Equal(HttpStatusCode.Unauthorized, e.StatusCode); - } - - [OrganizationTest(Skip = "see https://github.com/octokit/octokit.net/issues/533 for the resolution to this failing test")] - public async Task FailsWhenAuthenticatedWithBadCredentials() - { - var github = Helper.GetBadCredentialsClient(); - - var newTeam = new NewTeam("Test"); - - var e = await Assert.ThrowsAsync(() => github.Organization.Team.Create(Helper.Organization, newTeam)); - Assert.Equal(HttpStatusCode.Unauthorized, e.StatusCode); - } - - [OrganizationTest] - public async Task SucceedsWhenAuthenticated() + public async Task CreatesTeam() { var github = Helper.GetAuthenticatedClient(); - var newTeam = new NewTeam(Guid.NewGuid().ToString()); + var teamName = Helper.MakeNameWithTimestamp("new-team"); + var teamDescription = Helper.MakeNameWithTimestamp("team description"); + using (var context = await github.CreateRepositoryContext(Helper.Organization, new NewRepository(Helper.MakeNameWithTimestamp("org-repo")))) + { + var newTeam = new NewTeam(teamName) + { + Description = teamDescription, + Privacy = TeamPrivacy.Closed + }; + newTeam.Maintainers.Add(Helper.UserName); + newTeam.RepoNames.Add(context.Repository.FullName); + + var team = await github.Organization.Team.Create(Helper.Organization, newTeam); - var team = await github.Organization.Team.Create(Helper.Organization, newTeam); + Assert.Equal(teamName, team.Name); + Assert.Equal(teamDescription, team.Description); + Assert.Equal(TeamPrivacy.Closed, team.Privacy); + Assert.Equal(1, team.MembersCount); + Assert.Equal(1, team.ReposCount); - Assert.Equal(newTeam.Name, team.Name); + await github.Organization.Team.Delete(team.Id); + } } } @@ -269,4 +264,35 @@ public async Task ReturnsCorrectCountOfPendingInvitationsWithStart() } } } + + public class TheUpdateMethod + { + private readonly IGitHubClient _github; + + public TheUpdateMethod() + { + _github = Helper.GetAuthenticatedClient(); + } + + [OrganizationTest] + public async Task UpdatesTeam() + { + using (var teamContext = await _github.CreateTeamContext(Helper.Organization, new NewTeam(Helper.MakeNameWithTimestamp("team-fixture")))) + { + var teamName = Helper.MakeNameWithTimestamp("updated-team"); + var teamDescription = Helper.MakeNameWithTimestamp("updated description"); + var update = new UpdateTeam(teamName) + { + Description = teamDescription, + Privacy = TeamPrivacy.Closed + }; + + var team = await _github.Organization.Team.Update(teamContext.TeamId, update); + + Assert.Equal(teamName, team.Name); + Assert.Equal(teamDescription, team.Description); + Assert.Equal(TeamPrivacy.Closed, team.Privacy); + } + } + } } diff --git a/Octokit/Models/Request/NewTeam.cs b/Octokit/Models/Request/NewTeam.cs index 155dbc90f7..9316c17694 100644 --- a/Octokit/Models/Request/NewTeam.cs +++ b/Octokit/Models/Request/NewTeam.cs @@ -23,8 +23,8 @@ public class NewTeam public NewTeam(string name) { Name = name; + Maintainers = new Collection(); RepoNames = new Collection(); - Permission = Permission.Pull; } /// @@ -33,28 +33,35 @@ public NewTeam(string name) public string Name { get; private set; } /// - /// Gets or sets the description of the team + /// The description of the team. /// - /// - /// The description. - /// public string Description { get; set; } /// - /// permission associated to this team + /// The logins of organization members to add as maintainers of the team /// - public Permission Permission { get; set; } + public Collection Maintainers { get; protected set; } /// - /// array of repo_names this team has permissions to + /// The full name (e.g., "organization-name/repository-name") of repositories to add the team to /// - public Collection RepoNames { get; private set; } + public Collection RepoNames { get; protected set; } + + /// + /// The level of privacy this team should have (default: Secret) + /// + public TeamPrivacy? Privacy { get; set; } + + /// + /// The permission that new repositories will be added to the team with when none is specified (default: Pull) + /// + public Permission? Permission { get; set; } internal string DebuggerDisplay { get { - return string.Format(CultureInfo.InvariantCulture, "Name: {0} Permission: {1}", Name, Permission); + return string.Format(CultureInfo.InvariantCulture, "Name: {0} Privacy: {1} Permission: {2}", Name, Privacy?.ToString() ?? "Default", Permission?.ToString() ?? "Default" ); } } } diff --git a/Octokit/Models/Request/UpdateTeam.cs b/Octokit/Models/Request/UpdateTeam.cs index 1ecbec9eb7..8590b8b49b 100644 --- a/Octokit/Models/Request/UpdateTeam.cs +++ b/Octokit/Models/Request/UpdateTeam.cs @@ -1,3 +1,4 @@ +using System; using System.Diagnostics; using System.Globalization; @@ -12,30 +13,41 @@ public class UpdateTeam /// /// Initializes a new instance of the class. /// - /// The team. - public UpdateTeam(string team) + /// The updated team name. + public UpdateTeam(string name) { - Name = team; + Name = name; } /// /// Initializes a new instance of the class. /// - /// The team. + /// The updated team name. /// The permission. - public UpdateTeam(string team, Permission permission) + [Obsolete("This constructor will be removed for housekeeping purposes")] + public UpdateTeam(string name, Permission permission) { - Name = team; + Name = name; Permission = permission; } /// - /// team name + /// The name of the team (required). /// - public string Name { get; set; } + public string Name { get; private set; } /// - /// permission for this team + /// The description of the team. + /// + public string Description { get; set; } + + /// + /// The level of privacy this team should have (default: Secret) + /// + public TeamPrivacy? Privacy { get; set; } + + /// + /// The permission that new repositories will be added to the team with when none is specified (default: Pull) /// public Permission? Permission { get; set; } @@ -43,7 +55,7 @@ internal string DebuggerDisplay { get { - return string.Format(CultureInfo.InvariantCulture, "Team: {0} Permission: {1}", Name, Permission.GetValueOrDefault()); + return string.Format(CultureInfo.InvariantCulture, "Team: {0} Privacy: {1} Permission: {2}", Name, Privacy?.ToString() ?? "Default", Permission?.ToString() ?? "Default"); } } } diff --git a/Octokit/Models/Response/Team.cs b/Octokit/Models/Response/Team.cs index 5a41d25bd3..d2966eacb4 100644 --- a/Octokit/Models/Response/Team.cs +++ b/Octokit/Models/Response/Team.cs @@ -12,11 +12,13 @@ public class Team { public Team() { } - public Team(string url, int id, string name, Permission permission, int membersCount, int reposCount, Organization organization, string ldapDistinguishedName) + public Team(string url, int id, string name, string description, TeamPrivacy privacy, Permission permission, int membersCount, int reposCount, Organization organization, string ldapDistinguishedName) { Url = url; Id = id; Name = name; + Description = description; + Privacy = privacy; Permission = permission; MembersCount = membersCount; ReposCount = reposCount; @@ -39,6 +41,16 @@ public Team(string url, int id, string name, Permission permission, int membersC /// public string Name { get; protected set; } + /// + /// team description + /// + public string Description { get; protected set; } + + /// + /// team privacy + /// + public StringEnum Privacy { get; protected set; } + /// /// permission attached to this team /// @@ -70,4 +82,22 @@ internal string DebuggerDisplay get { return string.Format(CultureInfo.InvariantCulture, "Name: {0} ", Name); } } } + + /// + /// Used to describe a team's privacy level. + /// + public enum TeamPrivacy + { + /// + /// Only visible to organization owners and members of the team. + /// + [Parameter(Value = "secret")] + Secret, + + /// + /// Visible to all members of the organization. + /// + [Parameter(Value = "closed")] + Closed + } }