Skip to content

Commit

Permalink
Merge pull request #270 from goalie7960/master
Browse files Browse the repository at this point in the history
Added GetBranches method
  • Loading branch information
shiftkey committed Jan 5, 2014
2 parents b0e519e + 3452356 commit a1e3e98
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 3 deletions.
15 changes: 15 additions & 0 deletions Octokit.Tests/Clients/RepositoriesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,5 +249,20 @@ public async Task ReturnsReadmeHtml()
Assert.Equal("<html>README</html>", readme);
}
}

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

client.GetAllBranches("owner", "name");

connection.Received()
.GetAll<Branch>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/branches"));
}
}
}
}
12 changes: 12 additions & 0 deletions Octokit/Clients/IRepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,17 @@ public interface IRepositoriesClient
/// See the <a href="http://developer.github.com/v3/repos/collaborators/">Collaborators API documentation</a> for more details
/// </remarks>
IRepoCollaboratorsClient RepoCollaborators { get; }

/// <summary>
/// Gets all the branches for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/#list-branches">API documentation</a> for more details
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns></returns>
Task<IReadOnlyList<Branch>> GetAllBranches(string owner, string name);
}
}
19 changes: 18 additions & 1 deletion Octokit/Clients/RepositoriesClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
#if NET_45
using System.Collections.Generic;
#endif
Expand Down Expand Up @@ -203,5 +203,22 @@ public Task<string> GetReadmeHtml(string owner, string name)
/// See the <a href="http://developer.github.com/v3/repos/collaborators/">Collaborators API documentation</a> for more details
/// </remarks>
public IRepoCollaboratorsClient RepoCollaborators { get; private set; }


/// <summary>
/// Gets all the branches for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/#list-branches">API documentation</a> for more details
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns></returns>
public Task<IReadOnlyList<Branch>> GetAllBranches(string owner, string name)
{
var endpoint = ApiUrls.RepoBranches(owner, name);
return ApiConnection.GetAll<Branch>(endpoint);
}
}
}
13 changes: 12 additions & 1 deletion Octokit/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -729,13 +729,24 @@ public static Uri TeamsUpdateOrDelete(int id)
/// use for update or deleting a team
/// </summary>
/// <param name="owner">owner of repo</param>
/// /// <param name="repo">name of repo</param>
/// <param name="repo">name of repo</param>
/// <returns></returns>
public static Uri RepoCollaborators(string owner, string repo)
{
return "repos/{0}/{1}/collaborators".FormatUri(owner, repo);
}

/// <summary>
/// returns the <see cref="Uri"/> for branches
/// </summary>
/// <param name="owner">owner of repo</param>
/// <param name="repo">name of repo</param>
/// <returns></returns>
public static Uri RepoBranches(string owner, string repo)
{
return "repos/{0}/{1}/branches".FormatUri(owner, repo);
}

/// <summary>
/// Creates the relative <see cref="Uri"/> for searching repositories
/// </summary>
Expand Down
21 changes: 21 additions & 0 deletions Octokit/Models/Response/Branch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Octokit
{
public class Branch
{
/// <summary>
/// Name of this <see cref="Branch"/>.
/// </summary>
public string Name { get; set; }

/// <summary>
/// The <see cref="GitReference"/> history for this <see cref="Branch"/>.
/// </summary>
public GitReference Commit { get; set; }
}
}
1 change: 1 addition & 0 deletions Octokit/Octokit-Mono.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<Compile Include="Models\Request\RequestParameters.cs" />
<Compile Include="Models\Request\StarredRequest.cs" />
<Compile Include="Models\Request\UpdateTeam.cs" />
<Compile Include="Models\Response\Branch.cs" />
<Compile Include="Models\Response\Commit.cs" />
<Compile Include="Models\Response\Activity.cs" />
<Compile Include="Models\Response\Blob.cs" />
Expand Down
1 change: 1 addition & 0 deletions Octokit/Octokit-MonoAndroid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
<Compile Include="Clients\IssuesLabelsClient.cs" />
<Compile Include="Models\Request\LabelUpdate.cs" />
<Compile Include="Models\Request\NewLabel.cs" />
<Compile Include="Models\Response\Branch.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
</Project>
1 change: 1 addition & 0 deletions Octokit/Octokit-Monotouch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@
<Compile Include="Clients\IssuesLabelsClient.cs" />
<Compile Include="Models\Request\LabelUpdate.cs" />
<Compile Include="Models\Request\NewLabel.cs" />
<Compile Include="Models\Response\Branch.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
1 change: 1 addition & 0 deletions Octokit/Octokit-netcore45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
<Compile Include="Models\Response\Application.cs" />
<Compile Include="Models\Response\Authorization.cs" />
<Compile Include="Models\Response\Blob.cs" />
<Compile Include="Models\Response\Branch.cs" />
<Compile Include="Models\Response\Commit.cs" />
<Compile Include="Models\Response\CommitStatus.cs" />
<Compile Include="Models\Response\EmailAddress.cs" />
Expand Down
3 changes: 2 additions & 1 deletion Octokit/Octokit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<Compile Include="Models\Request\NewTreeItem.cs" />
<Compile Include="Models\Request\NewTree.cs" />
<Compile Include="Clients\TreesClient.cs" />
<Compile Include="Models\Response\Branch.cs" />
<Compile Include="Models\Response\GistComment.cs" />
<Compile Include="Models\Response\Reference.cs" />
<Compile Include="Models\Response\TreeItem.cs" />
Expand Down Expand Up @@ -274,7 +275,7 @@
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. -->
<Target Name="BeforeBuild">
<PullDownComments />
<PullDownComments />
</Target>
<!--
<Target Name="AfterBuild">
Expand Down

0 comments on commit a1e3e98

Please sign in to comment.