Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing fields to Team response, and NewTeam/UpdateTeam requests #1669

Merged
merged 4 commits into from
Sep 11, 2017
Merged
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
78 changes: 52 additions & 26 deletions Octokit.Tests.Integration/Clients/TeamsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AuthorizationException>(() => github.Organization.Team.Create(Helper.Organization, newTeam));

Assert.Equal(HttpStatusCode.Unauthorized, e.StatusCode);
}

[OrganizationTest(Skip = "see https:/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<AuthorizationException>(() => 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);
}
}
}

Expand Down Expand Up @@ -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);
}
}
}
}
27 changes: 17 additions & 10 deletions Octokit/Models/Request/NewTeam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class NewTeam
public NewTeam(string name)
{
Name = name;
Maintainers = new Collection<string>();
RepoNames = new Collection<string>();
Permission = Permission.Pull;
}

/// <summary>
Expand All @@ -33,28 +33,35 @@ public NewTeam(string name)
public string Name { get; private set; }

/// <summary>
/// Gets or sets the description of the team
/// The description of the team.
/// </summary>
/// <value>
/// The description.
/// </value>
public string Description { get; set; }

/// <summary>
/// permission associated to this team
/// The logins of organization members to add as maintainers of the team
/// </summary>
public Permission Permission { get; set; }
public Collection<string> Maintainers { get; protected set; }

/// <summary>
/// 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
/// </summary>
public Collection<string> RepoNames { get; private set; }
public Collection<string> RepoNames { get; protected set; }

/// <summary>
/// The level of privacy this team should have (default: Secret)
/// </summary>
public TeamPrivacy? Privacy { get; set; }

/// <summary>
/// The permission that new repositories will be added to the team with when none is specified (default: Pull)
/// </summary>
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" );
}
}
}
Expand Down
32 changes: 22 additions & 10 deletions Octokit/Models/Request/UpdateTeam.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Diagnostics;
using System.Globalization;

Expand All @@ -12,38 +13,49 @@ public class UpdateTeam
/// <summary>
/// Initializes a new instance of the <see cref="UpdateTeam"/> class.
/// </summary>
/// <param name="team">The team.</param>
public UpdateTeam(string team)
/// <param name="name">The updated team name.</param>
public UpdateTeam(string name)
{
Name = team;
Name = name;
}

/// <summary>
/// Initializes a new instance of the <see cref="UpdateTeam"/> class.
/// </summary>
/// <param name="team">The team.</param>
/// <param name="name">The updated team name.</param>
/// <param name="permission">The permission.</param>
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;
}

/// <summary>
/// team name
/// The name of the team (required).
/// </summary>
public string Name { get; set; }
public string Name { get; private set; }

/// <summary>
/// permission for this team
/// The description of the team.
/// </summary>
public string Description { get; set; }

/// <summary>
/// The level of privacy this team should have (default: Secret)
/// </summary>
public TeamPrivacy? Privacy { get; set; }

/// <summary>
/// The permission that new repositories will be added to the team with when none is specified (default: Pull)
/// </summary>
public Permission? Permission { get; set; }

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");
}
}
}
Expand Down
32 changes: 31 additions & 1 deletion Octokit/Models/Response/Team.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,6 +41,16 @@ public Team(string url, int id, string name, Permission permission, int membersC
/// </summary>
public string Name { get; protected set; }

/// <summary>
/// team description
/// </summary>
public string Description { get; protected set; }

/// <summary>
/// team privacy
/// </summary>
public StringEnum<TeamPrivacy> Privacy { get; protected set; }

/// <summary>
/// permission attached to this team
/// </summary>
Expand Down Expand Up @@ -70,4 +82,22 @@ internal string DebuggerDisplay
get { return string.Format(CultureInfo.InvariantCulture, "Name: {0} ", Name); }
}
}

/// <summary>
/// Used to describe a team's privacy level.
/// </summary>
public enum TeamPrivacy
{
/// <summary>
/// Only visible to organization owners and members of the team.
/// </summary>
[Parameter(Value = "secret")]
Secret,

/// <summary>
/// Visible to all members of the organization.
/// </summary>
[Parameter(Value = "closed")]
Closed
}
}