Skip to content

Commit

Permalink
Merge pull request #957 from octokit/clean-up-some-fixes
Browse files Browse the repository at this point in the history
clean up some pending PRs
  • Loading branch information
shiftkey committed Nov 3, 2015
2 parents 5c07408 + 2b18d21 commit 7ac970a
Show file tree
Hide file tree
Showing 16 changed files with 275 additions and 11 deletions.
8 changes: 8 additions & 0 deletions Octokit.Reactive/Clients/IObservableMiscellaneousClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ public interface IObservableMiscellaneousClient
Justification = "Makes a network request")]
IObservable<Emoji> GetAllEmojis();

/// <summary>
/// Gets the rendered Markdown for an arbitrary markdown document.
/// </summary>
/// <param name="markdown">An arbitrary Markdown document</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>The rendered Markdown.</returns>
IObservable<string> RenderArbitraryMarkdown(NewArbitraryMarkdown markdown);

/// <summary>
/// Gets the rendered Markdown for the specified plain-text Markdown document.
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions Octokit.Reactive/Clients/ObservableMiscellaneousClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ public IObservable<Emoji> GetAllEmojis()
return _client.GetAllEmojis().ToObservable().SelectMany(e => e);
}

/// <summary>
/// Gets the rendered Markdown for an arbitrary markdown document.
/// </summary>
/// <param name="markdown">An arbitrary Markdown document</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>The rendered Markdown.</returns>
public IObservable<string> RenderArbitraryMarkdown(NewArbitraryMarkdown markdown)
{
return _client.RenderArbitraryMarkdown(markdown).ToObservable();
}

/// <summary>
/// Gets the rendered Markdown for the specified plain-text Markdown document.
/// </summary>
Expand Down
20 changes: 20 additions & 0 deletions Octokit.Tests/Clients/MiscellaneousClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,27 @@ public async Task RequestsTheEmojiEndpoint()
"text/plain");
}
}
public class TheRenderArbitrryMarkdownMethod
{
[Fact]
public async Task RequestsTheEmojiEndpoint()
{
IApiResponse<string> response = new ApiResponse<string>(new Response(), "<strong>Test</strong>");
var connection = Substitute.For<IConnection>();
var forTest = new NewArbitraryMarkdown("testMarkdown", "gfm", "testContext");
connection.Post<string>(Args.Uri,forTest, "text/html", "text/plain")
.Returns(Task.FromResult(response));
var client = new MiscellaneousClient(connection);

var html = await client.RenderArbitraryMarkdown(forTest);
Assert.Equal("<strong>Test</strong>", html);
connection.Received()
.Post<string>(Arg.Is<Uri>(u => u.ToString() == "markdown"),
forTest,
"text/html",
"text/plain");
}
}
public class TheGetEmojisMethod
{
[Fact]
Expand Down
75 changes: 75 additions & 0 deletions Octokit.Tests/Clients/SearchClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,81 @@ public void TestingTheCreatedQualifier_Between()
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+created:2014-01-01..2014-02-02"));
}

[Fact]
public void TestingTheMergedQualifier_GreaterThan()
{
var connection = Substitute.For<IApiConnection>();
var client = new SearchClient(connection);
var request = new SearchIssuesRequest("something");
request.Merged = DateRange.GreaterThan(new DateTime(2014, 1, 1));

client.SearchIssues(request);

connection.Received().Get<SearchIssuesResult>(
Arg.Is<Uri>(u => u.ToString() == "search/issues"),
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+merged:>2014-01-01"));
}

[Fact]
public void TestingTheMergedQualifier_GreaterThanOrEquals()
{
var connection = Substitute.For<IApiConnection>();
var client = new SearchClient(connection);
var request = new SearchIssuesRequest("something");
request.Merged = DateRange.GreaterThanOrEquals(new DateTime(2014, 1, 1));

client.SearchIssues(request);

connection.Received().Get<SearchIssuesResult>(
Arg.Is<Uri>(u => u.ToString() == "search/issues"),
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+merged:>=2014-01-01"));
}

[Fact]
public void TestingTheMergedQualifier_LessThan()
{
var connection = Substitute.For<IApiConnection>();
var client = new SearchClient(connection);
var request = new SearchIssuesRequest("something");
request.Merged = DateRange.LessThan(new DateTime(2014, 1, 1));

client.SearchIssues(request);

connection.Received().Get<SearchIssuesResult>(
Arg.Is<Uri>(u => u.ToString() == "search/issues"),
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+merged:<2014-01-01"));
}

[Fact]
public void TestingTheMergedQualifier_LessThanOrEquals()
{
var connection = Substitute.For<IApiConnection>();
var client = new SearchClient(connection);
var request = new SearchIssuesRequest("something");
request.Merged = DateRange.LessThanOrEquals(new DateTime(2014, 1, 1));

client.SearchIssues(request);

connection.Received().Get<SearchIssuesResult>(
Arg.Is<Uri>(u => u.ToString() == "search/issues"),
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+merged:<=2014-01-01"));
}

[Fact]
public void TestingTheMergedQualifier_Between()
{
var connection = Substitute.For<IApiConnection>();
var client = new SearchClient(connection);
var request = new SearchIssuesRequest("something");
request.Merged = DateRange.Between(new DateTime(2014, 1, 1), new DateTime(2014, 2, 2));

client.SearchIssues(request);

connection.Received().Get<SearchIssuesResult>(
Arg.Is<Uri>(u => u.ToString() == "search/issues"),
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+merged:2014-01-01..2014-02-02"));
}

[Fact]
public void TestingTheUpdatedQualifier_GreaterThan()
{
Expand Down
8 changes: 8 additions & 0 deletions Octokit/Clients/IMiscellaneousClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ public interface IMiscellaneousClient
/// <returns>The rendered Markdown.</returns>
Task<string> RenderRawMarkdown(string markdown);

/// <summary>
/// Gets the rendered Markdown for an arbitrary markdown document.
/// </summary>
/// <param name="markdown">An arbitrary Markdown document</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>The rendered Markdown.</returns>
Task<string> RenderArbitraryMarkdown(NewArbitraryMarkdown markdown);

/// <summary>
/// List all templates available to pass as an option when creating a repository.
/// </summary>
Expand Down
14 changes: 14 additions & 0 deletions Octokit/Clients/MiscellaneousClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ public async Task<string> RenderRawMarkdown(string markdown)
return response.Body;
}

/// <summary>
/// Gets the rendered Markdown for an arbitrary markdown document.
/// </summary>
/// <param name="markdown">An arbitrary Markdown document</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>The rendered Markdown.</returns>
public async Task<string> RenderArbitraryMarkdown(NewArbitraryMarkdown markdown)
{
var endpoint = new Uri("markdown", UriKind.Relative);
var response = await _connection.Post<string>(endpoint, markdown, "text/html", "text/plain")
.ConfigureAwait(false);
return response.Body;
}

/// <summary>
/// List all templates available to pass as an option when creating a repository.
/// </summary>
Expand Down
100 changes: 100 additions & 0 deletions Octokit/Models/Request/NewArbitraryMarkDown.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;

namespace Octokit
{
/// <summary>
/// Used to create anarbitrary markdown
/// </summary>
/// <remarks>
/// API: https://developer.github.com/v3/markdown/#render-an-arbitrary-markdown-document
/// </remarks>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class NewArbitraryMarkdown
{
const string _markdown = "markdown";
const string _gfm = "gfm";

/// <summary>
/// Create an arbitrary markdown
/// </summary>
/// <param name="text">The Markdown text to render</param>
/// <param name="mode">The rendering mode. Can be either markdown by default or gfm</param>
/// <param name="context">
/// The repository context. Only taken into account when rendering as gfm
/// </param>
public NewArbitraryMarkdown(string text, string mode, string context)
{
Text = text;
Mode = GetMode(mode);
Context = context;
}

/// <summary>
/// Create an arbitrary markdown
/// </summary>
/// <param name="text">The Markdown text to render
/// </param>

public NewArbitraryMarkdown(string text)
:this(text,_markdown,null)
{
}

/// <summary>
/// Create an arbitrary markdown
/// </summary>
/// <param name="text">The Markdown text to render</param>
/// <param name="mode">The rendering mode. Can be either markdown by default or gfm</param>
/// </param>
public NewArbitraryMarkdown(string text, string mode)
: this(text, mode, null)
{
}

/// <summary>
/// Gets the markdown text
/// </summary>
/// <value>
/// The text.
/// </value>
public string Text { get; private set; }

/// <summary>
/// Gets the mode of the text
/// </summary>
/// <value>
/// The mode.
/// </value>
public string Mode { get; private set; }

/// <summary>
/// Gets the context of the markdown
/// </summary>
/// <value>
/// The context.
/// </value>
public string Context { get; private set; }

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "gfm")]
static string GetMode(string mode)
{
if (mode != _markdown && mode != _gfm)
{
throw (new FormatException("The mode must be either 'markdown' or 'gfm'"));
}
else
return mode;
}
internal string DebuggerDisplay
{
get
{
return String.Format(CultureInfo.InvariantCulture, "Text: {0}", Text);
}
}
}
}
22 changes: 19 additions & 3 deletions Octokit/Models/Request/SearchIssuesRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public SearchIssuesRequest(string term, string owner, string name)
}

/// <summary>
/// Optional Sort field. One of comments, created, or updated.
/// Optional Sort field. One of comments, created, updated or merged
/// If not provided, results are sorted by best match.
/// </summary>
/// <remarks>
Expand Down Expand Up @@ -177,6 +177,13 @@ public IEnumerable<string> Labels
/// </remarks>
public DateRange Updated { get; set; }

/// <summary>
/// Filters issues based on times when they were last merged
/// </summary>
/// <remarks>
/// https://help.github.com/articles/searching-issues/#search-based-on-when-a-pull-request-was-merged
/// </remarks>
public DateRange Merged { get; set; }
/// <summary>
/// Filters issues based on the quantity of comments.
/// </summary>
Expand All @@ -196,6 +203,7 @@ public IEnumerable<string> Labels
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public RepositoryCollection Repos { get; set; }

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
public override IReadOnlyList<string> MergedQualifiers()
{
var parameters = new List<string>();
Expand Down Expand Up @@ -261,7 +269,10 @@ public override IReadOnlyList<string> MergedQualifiers()
{
parameters.Add(String.Format(CultureInfo.InvariantCulture, "updated:{0}", Updated));
}

if (Merged != null)
{
parameters.Add(String.Format(CultureInfo.InvariantCulture, "merged:{0}", Merged));
}
if (Comments != null)
{
parameters.Add(String.Format(CultureInfo.InvariantCulture, "comments:{0}", Comments));
Expand Down Expand Up @@ -312,7 +323,12 @@ public enum IssueSearchSort
/// search by last updated
/// </summary>
[Parameter(Value = "updated")]
Updated
Updated,
/// <summary>
/// search by last merged
/// </summary>
[Parameter(Value = "merged")]
Merged
}

public enum IssueInQualifier
Expand Down
8 changes: 7 additions & 1 deletion Octokit/Models/Response/PullRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public PullRequest(int number)
Number = number;
}

public PullRequest(Uri url, Uri htmlUrl, Uri diffUrl, Uri patchUrl, Uri issueUrl, Uri statusesUrl, int number, ItemState state, string title, string body, DateTimeOffset createdAt, DateTimeOffset updatedAt, DateTimeOffset? closedAt, DateTimeOffset? mergedAt, GitReference head, GitReference @base, User user, string mergeCommitSha, bool merged, bool? mergeable, User mergedBy, int comments, int commits, int additions, int deletions, int changedFiles)
public PullRequest(Uri url, Uri htmlUrl, Uri diffUrl, Uri patchUrl, Uri issueUrl, Uri statusesUrl, int number, ItemState state, string title, string body, DateTimeOffset createdAt, DateTimeOffset updatedAt, DateTimeOffset? closedAt, DateTimeOffset? mergedAt, GitReference head, GitReference @base, User user, User assignee, string mergeCommitSha, bool merged, bool? mergeable, User mergedBy, int comments, int commits, int additions, int deletions, int changedFiles)
{
Url = url;
HtmlUrl = htmlUrl;
Expand All @@ -33,6 +33,7 @@ public PullRequest(Uri url, Uri htmlUrl, Uri diffUrl, Uri patchUrl, Uri issueUrl
Head = head;
Base = @base;
User = user;
Assignee = assignee;
MergeCommitSha = mergeCommitSha;
Merged = merged;
Mergeable = mergeable;
Expand Down Expand Up @@ -129,6 +130,11 @@ public PullRequest(Uri url, Uri htmlUrl, Uri diffUrl, Uri patchUrl, Uri issueUrl
/// </summary>
public User User { get; protected set; }

/// <summary>
/// The user who is assigned the pull request.
/// </summary>
public User Assignee { get; protected set; }

/// <summary>
/// The SHA of the merge commit.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion Octokit/Octokit-Mono.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<Compile Include="Models\Request\LabelUpdate.cs" />
<Compile Include="Models\Request\MergePullRequest.cs" />
<Compile Include="Models\Request\MilestoneUpdate.cs" />
<Compile Include="Models\Request\NewArbitraryMarkDown.cs" />
<Compile Include="Models\Request\NewBlob.cs" />
<Compile Include="Models\Request\NewCommit.cs" />
<Compile Include="Models\Request\NewCommitStatus.cs" />
Expand Down Expand Up @@ -405,4 +406,4 @@
<Compile Include="Models\Common\Committer.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
1 change: 1 addition & 0 deletions Octokit/Octokit-MonoAndroid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@
<Compile Include="Http\IApiInfoProvider.cs" />
<Compile Include="Models\Response\Meta.cs" />
<Compile Include="Models\Common\Committer.cs" />
<Compile Include="Models\Request\NewArbitraryMarkDown.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
</Project>
Loading

0 comments on commit 7ac970a

Please sign in to comment.