Skip to content

Commit

Permalink
added support for ref value in get contents api
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Heckathorne committed Feb 27, 2015
1 parent 20e372d commit fe74d7a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Octokit/Clients/IRepositoryContentsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public interface IRepositoryContentsClient
/// </summary>
/// <remarks>
/// If given a path to a single file, this method returns a collection containing only that file.
/// See the <a href="https://developer.github.com/v3/repos/contents/#get-contents">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
Expand All @@ -22,6 +23,22 @@ public interface IRepositoryContentsClient
/// </returns>
Task<IReadOnlyList<RepositoryContent>> GetContents(string owner, string name, string path);

/// <summary>
/// Returns the contents of a file or directory in a repository.
/// </summary>
/// <remarks>
/// If given a path to a single file, this method returns a collection containing only that file.
/// See the <a href="https://developer.github.com/v3/repos/contents/#get-contents">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="path">The content path</param>
/// <param name="reference">The name of the commit/branch/tag. Default: the repository’s default branch (usually master)</param>
/// <returns>
/// A collection of <see cref="RepositoryContent"/> representing the content at the specified path
/// </returns>
Task<IReadOnlyList<RepositoryContent>> GetContents(string owner, string name, string path, string reference);

/// <summary>
/// Gets the preferred README for the specified repository.
/// </summary>
Expand Down
27 changes: 27 additions & 0 deletions Octokit/Clients/RepositoryContentsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public RepositoryContentsClient(IApiConnection apiConnection) : base(apiConnecti
/// </summary>
/// <remarks>
/// If given a path to a single file, this method returns a collection containing only that file.
/// See the <a href="https://developer.github.com/v3/repos/contents/#get-contents">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
Expand All @@ -35,6 +36,32 @@ public async Task<IReadOnlyList<RepositoryContent>> GetContents(string owner, st
return await ApiConnection.GetAll<RepositoryContent>(url);
}

/// <summary>
/// Returns the contents of a file or directory in a repository.
/// </summary>
/// <remarks>
/// If given a path to a single file, this method returns a collection containing only that file.
/// See the <a href="https://developer.github.com/v3/repos/contents/#get-contents">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="path">The content path</param>
/// <param name="reference">The name of the commit/branch/tag. Default: the repository�s default branch (usually master)</param>
/// <returns>
/// A collection of <see cref="RepositoryContent"/> representing the content at the specified path
/// </returns>
public async Task<IReadOnlyList<RepositoryContent>> GetContents(string owner, string name, string path, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(path, "path");
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");

var url = ApiUrls.RepositoryContent(owner, name, path, reference);

return await ApiConnection.GetAll<RepositoryContent>(url);
}

/// <summary>
/// Gets the preferred README for the specified repository.
/// </summary>
Expand Down
13 changes: 13 additions & 0 deletions Octokit/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1434,5 +1434,18 @@ public static Uri RepositoryContent(string owner, string name, string path)
{
return "repos/{0}/{1}/contents/{2}".FormatUri(owner, name, path);
}

/// <summary>
/// Creates the relative <see cref="Uri"/> for getting the contents of the specified repository and path
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="path">The path of the contents to get</param>
/// <param name="reference">The name of the commit/branch/tag. Default: the repository’s default branch (usually master)</param>
/// <returns>The <see cref="Uri"/> for getting the contents of the specified repository and path</returns>
public static Uri RepositoryContent(string owner, string name, string path, string reference)
{
return "repos/{0}/{1}/contents/{2}?ref={3}".FormatUri(owner, name, path, reference);
}
}
}

0 comments on commit fe74d7a

Please sign in to comment.