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

added new parameters to RepositoryRequest.cs #1096

Merged
merged 4 commits into from
Feb 11, 2016
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
41 changes: 41 additions & 0 deletions Octokit.Tests/Clients/RepositoriesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,47 @@ public void CanFilterBySortDirection()
Arg.Is<Dictionary<string, string>>(d =>
d["type"] == "member" && d["sort"] == "updated" && d["direction"] == "asc"));
}

[Fact]
public void CanFilterByVisibility()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoriesClient(connection);

var request = new RepositoryRequest
{
Visibility = RepositoryVisibility.Private
};
client.GetAllForCurrent(request);

connection.Received()
.GetAll<Repository>(
Arg.Is<Uri>(u => u.ToString() == "user/repos"),
Arg.Is<Dictionary<string, string>>(d =>
d["visibility"] == "private"));
}

[Fact]
public void CanFilterByAffiliation()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoriesClient(connection);

var request = new RepositoryRequest
{

Affiliation = RepositoryAffiliation.Owner,
Sort = RepositorySort.FullName
};

client.GetAllForCurrent(request);

connection.Received()
.GetAll<Repository>(
Arg.Is<Uri>(u => u.ToString() == "user/repos"),
Arg.Is<Dictionary<string, string>>(d =>
d["affiliation"] == "owner" && d["sort"] == "full_name"));
}
}

public class TheGetAllForUserMethod
Expand Down
2 changes: 1 addition & 1 deletion Octokit/Helpers/UriExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Octokit
public static class UriExtensions
{
/// <summary>
/// Merge a dictionary of valeus with an existing <see cref="Uri"/>
/// Merge a dictionary of values with an existing <see cref="Uri"/>
/// </summary>
/// <param name="uri">Original request Uri</param>
/// <param name="parameters">Collection of key-value pairs</param>
Expand Down
84 changes: 84 additions & 0 deletions Octokit/Models/Request/RepositoryRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ public class RepositoryRequest : RequestParameters
/// </value>
public SortDirection Direction { get; set; }

/// <summary>
/// Gets or sets the visibility property.
/// </summary>
/// <value>
/// The visibility.
/// </value>
public RepositoryVisibility Visibility { get; set; }

/// <summary>
/// Gets or sets the affiliation property.
/// </summary>
/// <value>
/// The affiliation.
/// </value>
public RepositoryAffiliation Affiliation { get; set; }

internal string DebuggerDisplay
{
get
Expand Down Expand Up @@ -103,4 +119,72 @@ public enum RepositorySort
[Parameter(Value = "full_name")]
FullName
}

/// <summary>
/// The properties that repositories can be visible by.
/// </summary>
public enum RepositoryVisibility
{
/// <summary>
/// Returns only public repositories
/// </summary>
Public,

/// <summary>
/// Returns only private repositories
/// </summary>
Private,

/// <summary>
/// Return both public and private repositories
/// </summary>
All,
}

/// <summary>
/// The properties that repositories can be affiliated by.
/// </summary>
public enum RepositoryAffiliation
{
/// <summary>
/// Repositories that are owned by the authenticated user
/// </summary>
Owner,

/// <summary>
/// Repositories that the user has been added to as a collaborator.
/// </summary>
Collaborator,

/// <summary>
/// Repositories that the user has access to through being a member of an organization.
/// This includes every repository on every team that the user is on.
/// </summary>
[Parameter(Value = "organization_member")]
OrganizationMember,

/// <summary>
/// Return repositories that are owned by authenticated user and added to as a collaborator.
/// </summary>
[Parameter(Value = "owner, collaborator")]
OwnerAndCollaborator,

/// <summary>
/// Return repositories that are owned by authenticated user or user is a organization member.
/// </summary>
[Parameter(Value = "owner, organization_member")]
OwnerAndOrganizationMember,

/// <summary>
/// Return repositories that user has been added as collaborator or user is a organization member.
/// </summary>
[Parameter(Value = "collaborator, organization_member")]
CollaboratorAndOrganizationMember,

/// <summary>
/// Returns all repositories where user is owner,collaborator or organization member.
/// </summary>
[Parameter(Value = "owner, collaborator, organization_member")]
All
}
}