mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-04 19:26:51 +00:00
Merge pull request #66 from octokit/haacked/get-readme-html
Implement method to get README html
This commit is contained in:
@@ -63,5 +63,13 @@ namespace Octokit.Reactive.Clients
|
||||
|
||||
return _client.GetReadme(owner, name).ToObservable();
|
||||
}
|
||||
|
||||
public IObservable<string> GetReadmeHtml(string owner, string name)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
return _client.GetReadmeHtml(owner, name).ToObservable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,5 +62,14 @@ namespace Octokit.Reactive
|
||||
/// <param name="owner">The owner of the repository.</param>
|
||||
/// <param name="name">The name of the repository.</param>
|
||||
/// <returns></returns>
|
||||
IObservable<Readme> GetReadme(string owner, string name); }
|
||||
IObservable<Readme> GetReadme(string owner, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Returns just the HTML portion of the README without the surrounding HTML document.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository.</param>
|
||||
/// <param name="name">The name of the repository.</param>
|
||||
/// <returns></returns>
|
||||
IObservable<string> GetReadmeHtml(string owner, string name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
using System;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Threading.Tasks;
|
||||
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
public static class ObservableExtensions
|
||||
{
|
||||
public static IObservable<string> GetReadmeAsHtml(this IObservableRepositoriesClient client,
|
||||
string owner,
|
||||
string name)
|
||||
{
|
||||
Ensure.ArgumentNotNull(client, "client");
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
return client.GetReadme(owner, name).SelectMany(r => r.GetHtmlContent().ToObservable());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,6 @@
|
||||
<Compile Include="IObservableOrganizationsClient.cs" />
|
||||
<Compile Include="IObservableSshKeysClient.cs" />
|
||||
<Compile Include="IObservableUsersClient.cs" />
|
||||
<Compile Include="ObservableExtensions.cs" />
|
||||
<Compile Include="ObservableGitHubClient.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -251,7 +251,7 @@ namespace Octokit.Tests.Integration
|
||||
public class TheGetReadmeMethod
|
||||
{
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsReadmeForOctokit()
|
||||
public async Task ReturnsReadmeForSeeGit()
|
||||
{
|
||||
var github = new GitHubClient("Octokit Test Runner")
|
||||
{
|
||||
@@ -265,6 +265,20 @@ namespace Octokit.Tests.Integration
|
||||
Assert.Contains(@"<div id=""readme""", readMeHtml);
|
||||
Assert.Contains("<p><strong>WARNING: This is some haacky code.", readMeHtml);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsReadmeHtmlForSeeGit()
|
||||
{
|
||||
var github = new GitHubClient("Octokit Test Runner")
|
||||
{
|
||||
Credentials = AutomationSettings.Current.GitHubCredentials
|
||||
};
|
||||
|
||||
// TODO: Change this to request github/Octokit.net once we make this OSS.
|
||||
var readmeHtml = await github.Repository.GetReadmeHtml("haacked", "seegit");
|
||||
Assert.True(readmeHtml.StartsWith("<div "));
|
||||
Assert.Contains("<p><strong>WARNING: This is some haacky code.", readmeHtml);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,5 +173,21 @@ namespace Octokit.Tests.Clients
|
||||
client.Received().GetHtml(Arg.Is<Uri>(u => u.ToString() == "https://github.example.com/readme"), null);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetReadmeHtmlMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task ReturnsReadmeHtml()
|
||||
{
|
||||
var client = Substitute.For<IApiConnection<Repository>>();
|
||||
client.GetHtml(Args.Uri, null).Returns(Task.FromResult("<html>README</html>"));
|
||||
var reposEndpoint = new RepositoriesClient(client);
|
||||
|
||||
var readme = await reposEndpoint.GetReadmeHtml("fake", "repo");
|
||||
|
||||
client.Received().GetHtml(Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/readme"), null);
|
||||
Assert.Equal("<html>README</html>", readme);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,5 +70,14 @@ namespace Octokit
|
||||
var readmeInfo = await Client.GetItem<ReadmeResponse>(endpoint, null);
|
||||
return new Readme(readmeInfo, Client);
|
||||
}
|
||||
|
||||
public async Task<string> GetReadmeHtml(string owner, string name)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
var endpoint = "/repos/{0}/{1}/readme".FormatUri(owner, name);
|
||||
return await Client.GetHtml(endpoint, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,11 +58,19 @@ namespace Octokit
|
||||
Task<IReadOnlyList<Repository>> GetAllForOrg(string organization);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the HTML rendered README.
|
||||
/// Returns the <see cref="Readme"/> associated with the specified repository.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository.</param>
|
||||
/// <param name="name">The name of the repository.</param>
|
||||
/// <returns></returns>
|
||||
Task<Readme> GetReadme(string owner, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Returns just the HTML portion of the README without the surrounding HTML document.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository.</param>
|
||||
/// <param name="name">The name of the repository.</param>
|
||||
/// <returns></returns>
|
||||
Task<string> GetReadmeHtml(string owner, string name);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user