Skip to content

Commit

Permalink
Merge pull request #1096 from Sarmad93/new-parameters-on-ListYourRepo…
Browse files Browse the repository at this point in the history
…sitory

added new parameters to RepositoryRequest.cs
  • Loading branch information
haacked committed Feb 11, 2016
2 parents 660df9d + 2366c99 commit ee71652
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 1 deletion.
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
}
}

0 comments on commit ee71652

Please sign in to comment.