From 55632eec5da55df2f25643a3d66d8e4f1be23da5 Mon Sep 17 00:00:00 2001 From: Jiaming Chen Date: Fri, 9 Oct 2015 14:58:24 -0700 Subject: [PATCH 1/6] added "Merged" in searchissues which allows search repos by merged date with existing syntax. it generates a CA1502 code excessive complexity warning and i suppressed it. --- Octokit/Models/Request/SearchIssuesRequest.cs | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) 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 From fc1b448479f8e66b1a6f149e39f2f2622416378b Mon Sep 17 00:00:00 2001 From: Jiaming Chen Date: Fri, 9 Oct 2015 16:04:31 -0700 Subject: [PATCH 2/6] added tests for the merged qualifier --- Octokit.Tests/Clients/SearchClientTests.cs | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) 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() { From e315a96783ade76c4c1e9c33be39886c01da1006 Mon Sep 17 00:00:00 2001 From: Jiaming Chen Date: Fri, 9 Oct 2015 16:50:59 -0700 Subject: [PATCH 3/6] comment out new tests. --- Octokit.Tests/Clients/SearchClientTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Octokit.Tests/Clients/SearchClientTests.cs b/Octokit.Tests/Clients/SearchClientTests.cs index aba21e545c..5ac525c0d5 100644 --- a/Octokit.Tests/Clients/SearchClientTests.cs +++ b/Octokit.Tests/Clients/SearchClientTests.cs @@ -1045,7 +1045,7 @@ 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] + /*[Fact] public void TestingTheMergedQualifier_GreaterThan() { var connection = Substitute.For(); @@ -1116,7 +1116,7 @@ public void TestingTheMergedQualifier_Between() 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() { From 7e6fbd45079e9ed4e10aa50594e623f9b46f1cbf Mon Sep 17 00:00:00 2001 From: Jiaming Chen Date: Fri, 9 Oct 2015 16:57:34 -0700 Subject: [PATCH 4/6] recovered tests --- Octokit.Tests/Clients/SearchClientTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Octokit.Tests/Clients/SearchClientTests.cs b/Octokit.Tests/Clients/SearchClientTests.cs index 5ac525c0d5..aba21e545c 100644 --- a/Octokit.Tests/Clients/SearchClientTests.cs +++ b/Octokit.Tests/Clients/SearchClientTests.cs @@ -1045,7 +1045,7 @@ 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] + [Fact] public void TestingTheMergedQualifier_GreaterThan() { var connection = Substitute.For(); @@ -1116,7 +1116,7 @@ public void TestingTheMergedQualifier_Between() 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() { From bc8c502926c7018bee66ae2017fca2c7935b387d Mon Sep 17 00:00:00 2001 From: Jiaming Chen Date: Sat, 10 Oct 2015 10:19:47 -0700 Subject: [PATCH 5/6] Merged property will be set according to MergedAt now. It is not always false any more. #867 --- Octokit/Models/Response/PullRequest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit/Models/Response/PullRequest.cs b/Octokit/Models/Response/PullRequest.cs index a52e5b052d..7c84b79f09 100644 --- a/Octokit/Models/Response/PullRequest.cs +++ b/Octokit/Models/Response/PullRequest.cs @@ -34,7 +34,7 @@ public PullRequest(Uri url, Uri htmlUrl, Uri diffUrl, Uri patchUrl, Uri issueUrl Base = @base; User = user; MergeCommitSha = mergeCommitSha; - Merged = merged; + Merged = merged || MergedAt.HasValue; Mergeable = mergeable; MergedBy = mergedBy; Comments = comments; From 7d4b525bde10443bc69dbbf80278fef3eac978c5 Mon Sep 17 00:00:00 2001 From: Jiaming Chen Date: Sat, 10 Oct 2015 11:26:10 -0700 Subject: [PATCH 6/6] removed merged property for PR. also removed related tests for that property. --- .../Clients/PullRequestsClientTests.cs | 2 -- Octokit/Models/Response/PullRequest.cs | 8 +------- 2 files changed, 1 insertion(+), 9 deletions(-) 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/Models/Response/PullRequest.cs b/Octokit/Models/Response/PullRequest.cs index 7c84b79f09..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 || MergedAt.HasValue; 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. ///