diff --git a/Octokit.Tests.Integration/Clients/PullRequestsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestsClientTests.cs index 003d9bcb63..99768d1251 100644 --- a/Octokit.Tests.Integration/Clients/PullRequestsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/PullRequestsClientTests.cs @@ -35,9 +35,7 @@ public async Task CanCreate() var newPullRequest = new NewPullRequest("a pull request", branchName, "master"); var result = await _fixture.Create(Helper.UserName, _context.RepositoryName, newPullRequest); - Assert.Equal("a pull request", result.Title); - Assert.False(result.Merged); } [IntegrationTest] diff --git a/Octokit.Tests/Clients/SearchClientTests.cs b/Octokit.Tests/Clients/SearchClientTests.cs index 47b478756f..aba21e545c 100644 --- a/Octokit.Tests/Clients/SearchClientTests.cs +++ b/Octokit.Tests/Clients/SearchClientTests.cs @@ -1045,7 +1045,78 @@ public void TestingTheCreatedQualifier_Between() Arg.Is(u => u.ToString() == "search/issues"), Arg.Is>(d => d["q"] == "something+created:2014-01-01..2014-02-02")); } + [Fact] + public void TestingTheMergedQualifier_GreaterThan() + { + var connection = Substitute.For(); + 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( + Arg.Is(u => u.ToString() == "search/issues"), + Arg.Is>(d => d["q"] == "something+merged:>2014-01-01")); + } + + [Fact] + public void TestingTheMergedQualifier_GreaterThanOrEquals() + { + var connection = Substitute.For(); + 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( + Arg.Is(u => u.ToString() == "search/issues"), + Arg.Is>(d => d["q"] == "something+merged:>=2014-01-01")); + } + + [Fact] + public void TestingTheMergedQualifier_LessThan() + { + var connection = Substitute.For(); + 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( + Arg.Is(u => u.ToString() == "search/issues"), + Arg.Is>(d => d["q"] == "something+merged:<2014-01-01")); + } + [Fact] + public void TestingTheMergedQualifier_LessThanOrEquals() + { + var connection = Substitute.For(); + 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( + Arg.Is(u => u.ToString() == "search/issues"), + Arg.Is>(d => d["q"] == "something+merged:<=2014-01-01")); + } + [Fact] + public void TestingTheMergedQualifier_Between() + { + var connection = Substitute.For(); + 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( + Arg.Is(u => u.ToString() == "search/issues"), + Arg.Is>(d => d["q"] == "something+merged:2014-01-01..2014-02-02")); + } [Fact] public void TestingTheUpdatedQualifier_GreaterThan() { diff --git a/Octokit/Models/Request/SearchIssuesRequest.cs b/Octokit/Models/Request/SearchIssuesRequest.cs index f9a5a332b7..31c7e3e1e4 100644 --- a/Octokit/Models/Request/SearchIssuesRequest.cs +++ b/Octokit/Models/Request/SearchIssuesRequest.cs @@ -43,7 +43,7 @@ public SearchIssuesRequest(string term, string owner, string name) } /// - /// 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. /// /// @@ -177,6 +177,13 @@ public IEnumerable Labels /// public DateRange Updated { get; set; } + /// + /// Filters issues based on times when they were last merged + /// + /// + /// https://help.github.com/articles/searching-issues/#search-based-on-when-a-pull-request-was-merged + /// + public DateRange Merged { get; set; } /// /// Filters issues based on the quantity of comments. /// @@ -196,6 +203,7 @@ public IEnumerable Labels [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public RepositoryCollection Repos { get; set; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] public override IReadOnlyList MergedQualifiers() { var parameters = new List(); @@ -261,7 +269,10 @@ public override IReadOnlyList 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)); @@ -312,7 +323,12 @@ public enum IssueSearchSort /// search by last updated /// [Parameter(Value = "updated")] - Updated + Updated, + /// + /// search by last merged + /// + [Parameter(Value = "merged")] + Merged } public enum IssueInQualifier diff --git a/Octokit/Models/Response/PullRequest.cs b/Octokit/Models/Response/PullRequest.cs index a52e5b052d..efc46b0755 100644 --- a/Octokit/Models/Response/PullRequest.cs +++ b/Octokit/Models/Response/PullRequest.cs @@ -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, string mergeCommitSha, bool? mergeable, User mergedBy, int comments, int commits, int additions, int deletions, int changedFiles) { Url = url; HtmlUrl = htmlUrl; @@ -34,7 +34,6 @@ public PullRequest(Uri url, Uri htmlUrl, Uri diffUrl, Uri patchUrl, Uri issueUrl Base = @base; User = user; MergeCommitSha = mergeCommitSha; - Merged = merged; Mergeable = mergeable; MergedBy = mergedBy; Comments = comments; @@ -134,11 +133,6 @@ public PullRequest(Uri url, Uri htmlUrl, Uri diffUrl, Uri patchUrl, Uri issueUrl /// public string MergeCommitSha { get; protected set; } - /// - /// Whether or not the pull request has been merged. - /// - public bool Merged { get; protected set; } - /// /// Whether or not the pull request can be merged. ///