From 7bd0447bd62173195ab2c2d4f3993d834c69cd5a Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Sun, 19 Jul 2015 13:01:23 +0200 Subject: [PATCH 1/3] Changed repos to a specialized collection --- .../Clients/SearchClientTests.cs | 12 ++-- Octokit.Tests/Clients/SearchClientTests.cs | 12 ++-- Octokit/Models/Request/SearchCodeRequest.cs | 8 +-- Octokit/Models/Request/SearchIssuesRequest.cs | 60 +++++++++++++++++-- 4 files changed, 69 insertions(+), 23 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/SearchClientTests.cs b/Octokit.Tests.Integration/Clients/SearchClientTests.cs index c37bda62..301c73ef 100644 --- a/Octokit.Tests.Integration/Clients/SearchClientTests.cs +++ b/Octokit.Tests.Integration/Clients/SearchClientTests.cs @@ -47,9 +47,9 @@ public class SearchClientTests public async Task SearchForWordInCode() { var request = new SearchIssuesRequest("windows"); - request.Repos = new Collection { - "aspnet/dnx", - "aspnet/dnvm" + request.Repos = new RepositoryCollection { + { "aspnet", "dnx" }, + { "aspnet", "dnvm" } }; request.SortField = IssueSearchSort.Created; @@ -64,7 +64,7 @@ public class SearchClientTests public async Task SearchForOpenIssues() { var request = new SearchIssuesRequest("phone"); - request.Repos.Add("caliburn-micro/caliburn.micro"); + request.Repos.Add("caliburn-micro", "caliburn.micro"); request.State = ItemState.Open; var issues = await _gitHubClient.Search.SearchIssues(request); @@ -76,7 +76,7 @@ public class SearchClientTests public async Task SearchForAllIssuesWithouTaskUsingTerm() { var request = new SearchIssuesRequest(); - request.Repos.Add("caliburn-micro/caliburn.micro"); + request.Repos.Add("caliburn-micro", "caliburn.micro"); var issues = await _gitHubClient.Search.SearchIssues(request); @@ -91,7 +91,7 @@ public class SearchClientTests public async Task SearchForAllIssuesUsingTerm() { var request = new SearchIssuesRequest("phone"); - request.Repos.Add("caliburn-micro/caliburn.micro"); + request.Repos.Add("caliburn-micro", "caliburn.micro"); var issues = await _gitHubClient.Search.SearchIssues(request); diff --git a/Octokit.Tests/Clients/SearchClientTests.cs b/Octokit.Tests/Clients/SearchClientTests.cs index 1b9cc951..4547b400 100644 --- a/Octokit.Tests/Clients/SearchClientTests.cs +++ b/Octokit.Tests/Clients/SearchClientTests.cs @@ -1151,7 +1151,7 @@ namespace Octokit.Tests.Clients var connection = Substitute.For(); var client = new SearchClient(connection); var request = new SearchIssuesRequest("something"); - request.Repos.Add("octokit/octokit.net"); + request.Repos.Add("octokit", "octokit.net"); client.SearchIssues(request); @@ -1167,8 +1167,8 @@ namespace Octokit.Tests.Clients var client = new SearchClient(connection); var request = new SearchIssuesRequest("windows"); - request.Repos = new Collection { - "haha-business" + request.Repos = new RepositoryCollection { + { "haha-business", "some&name" } }; request.SortField = IssueSearchSort.Created; @@ -1184,7 +1184,7 @@ namespace Octokit.Tests.Clients var connection = Substitute.For(); var client = new SearchClient(connection); var request = new SearchIssuesRequest("something"); - request.Repos.Add("octokit/octokit.net"); + request.Repos.Add("octokit", "octokit.net"); request.User = "alfhenrik"; request.Labels = new[] { "bug" }; @@ -1512,8 +1512,8 @@ namespace Octokit.Tests.Clients var client = new SearchClient(connection); var request = new SearchCodeRequest("windows"); - request.Repos = new Collection { - "haha-business" + request.Repos = new RepositoryCollection { + { "haha-business", "some&name" } }; request.Order = SortDirection.Descending; diff --git a/Octokit/Models/Request/SearchCodeRequest.cs b/Octokit/Models/Request/SearchCodeRequest.cs index 95ddb1f5..570b5fb8 100644 --- a/Octokit/Models/Request/SearchCodeRequest.cs +++ b/Octokit/Models/Request/SearchCodeRequest.cs @@ -18,7 +18,7 @@ namespace Octokit { public SearchCodeRequest(string term) : base(term) { - Repos = new Collection(); + Repos = new RepositoryCollection(); } public SearchCodeRequest(string term, string owner, string name) @@ -27,9 +27,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - var repo = string.Format(CultureInfo.InvariantCulture, "{0}/{1}", owner, name); - - Repos.Add(repo); + Repos.Add(owner, name); } /// @@ -123,7 +121,7 @@ namespace Octokit /// https://help.github.com/articles/searching-code#users-organizations-and-repositories /// [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] - public Collection Repos { get; set; } + public RepositoryCollection Repos { get; set; } [SuppressMessage("Microsoft.Globalization", "CA1304:SpecifyCultureInfo", MessageId = "System.String.ToLower")] public override IReadOnlyList MergedQualifiers() diff --git a/Octokit/Models/Request/SearchIssuesRequest.cs b/Octokit/Models/Request/SearchIssuesRequest.cs index 12858eea..024e86a4 100644 --- a/Octokit/Models/Request/SearchIssuesRequest.cs +++ b/Octokit/Models/Request/SearchIssuesRequest.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using Octokit.Internal; using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Globalization; @@ -20,7 +21,7 @@ namespace Octokit /// public SearchIssuesRequest() { - Repos = new Collection(); + Repos = new RepositoryCollection(); } /// @@ -29,7 +30,7 @@ namespace Octokit /// The term to filter on public SearchIssuesRequest(string term) : base(term) { - Repos = new Collection(); + Repos = new RepositoryCollection(); } [Obsolete("this will be deprecated in a future version")] @@ -39,9 +40,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - var repo = string.Format(CultureInfo.InvariantCulture, "{0}/{1}", owner, name); - - Repos.Add(repo); + Repos.Add(owner, name); } /// @@ -196,7 +195,7 @@ namespace Octokit public string User { get; set; } [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] - public Collection Repos { get; set; } + public RepositoryCollection Repos { get; set; } public override IReadOnlyList MergedQualifiers() { @@ -337,4 +336,53 @@ namespace Octokit [Parameter(Value = "issue")] Issue } + + public class RepositoryCollection : IEnumerable + { + readonly ICollection _repositories = new List(); + + public IEnumerator GetEnumerator() + { + return _repositories.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public void Add(string owner, string name) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + _repositories.Add(GetRepositoryName(owner, name)); + } + + public void Clear() + { + _repositories.Clear(); + } + + public bool Contains(string owner, string name) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return _repositories.Contains(GetRepositoryName(owner, name)); + } + + public bool Remove(string owner, string name) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return _repositories.Remove(GetRepositoryName(owner, name)); + } + + private static string GetRepositoryName(string owner, string name) + { + return string.Format(CultureInfo.InvariantCulture, "{0}/{1}", owner, name); + } + } } From f98ff15211d4e2c712f4baa44e00b63e0c926a0b Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Sun, 19 Jul 2015 13:30:32 +0200 Subject: [PATCH 2/3] Added overloads with a single string --- .../Clients/SearchClientTests.cs | 2 +- Octokit.Tests/Clients/SearchClientTests.cs | 4 ++-- Octokit/Models/Request/SearchIssuesRequest.cs | 21 +++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/SearchClientTests.cs b/Octokit.Tests.Integration/Clients/SearchClientTests.cs index 301c73ef..ba6f4d89 100644 --- a/Octokit.Tests.Integration/Clients/SearchClientTests.cs +++ b/Octokit.Tests.Integration/Clients/SearchClientTests.cs @@ -76,7 +76,7 @@ public class SearchClientTests public async Task SearchForAllIssuesWithouTaskUsingTerm() { var request = new SearchIssuesRequest(); - request.Repos.Add("caliburn-micro", "caliburn.micro"); + request.Repos.Add("caliburn-micro/caliburn.micro"); var issues = await _gitHubClient.Search.SearchIssues(request); diff --git a/Octokit.Tests/Clients/SearchClientTests.cs b/Octokit.Tests/Clients/SearchClientTests.cs index 4547b400..359b7c60 100644 --- a/Octokit.Tests/Clients/SearchClientTests.cs +++ b/Octokit.Tests/Clients/SearchClientTests.cs @@ -1184,7 +1184,7 @@ namespace Octokit.Tests.Clients var connection = Substitute.For(); var client = new SearchClient(connection); var request = new SearchIssuesRequest("something"); - request.Repos.Add("octokit", "octokit.net"); + request.Repos.Add("octokit/octokit.net"); request.User = "alfhenrik"; request.Labels = new[] { "bug" }; @@ -1513,7 +1513,7 @@ namespace Octokit.Tests.Clients var request = new SearchCodeRequest("windows"); request.Repos = new RepositoryCollection { - { "haha-business", "some&name" } + "haha-business" }; request.Order = SortDirection.Descending; diff --git a/Octokit/Models/Request/SearchIssuesRequest.cs b/Octokit/Models/Request/SearchIssuesRequest.cs index 024e86a4..b93b88bd 100644 --- a/Octokit/Models/Request/SearchIssuesRequest.cs +++ b/Octokit/Models/Request/SearchIssuesRequest.cs @@ -359,6 +359,13 @@ namespace Octokit _repositories.Add(GetRepositoryName(owner, name)); } + public void Add(string nameWithOwner) + { + Ensure.ArgumentNotNullOrEmptyString(nameWithOwner, "nameWithOwner"); + + _repositories.Add(nameWithOwner); + } + public void Clear() { _repositories.Clear(); @@ -372,6 +379,13 @@ namespace Octokit return _repositories.Contains(GetRepositoryName(owner, name)); } + public bool Contains(string nameWithOwner) + { + Ensure.ArgumentNotNullOrEmptyString(nameWithOwner, "nameWithOwner"); + + return _repositories.Contains(nameWithOwner); + } + public bool Remove(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -380,6 +394,13 @@ namespace Octokit return _repositories.Remove(GetRepositoryName(owner, name)); } + public bool Remove(string nameWithOwner) + { + Ensure.ArgumentNotNullOrEmptyString(nameWithOwner, "nameWithOwner"); + + return _repositories.Remove(nameWithOwner); + } + private static string GetRepositoryName(string owner, string name) { return string.Format(CultureInfo.InvariantCulture, "{0}/{1}", owner, name); From 43feb744d8b76194d3253f301862bb8e42063486 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Mon, 20 Jul 2015 22:51:16 +0200 Subject: [PATCH 3/3] Changed collection to inherit from Collection --- Octokit/Models/Request/SearchIssuesRequest.cs | 59 +++---------------- 1 file changed, 7 insertions(+), 52 deletions(-) diff --git a/Octokit/Models/Request/SearchIssuesRequest.cs b/Octokit/Models/Request/SearchIssuesRequest.cs index b93b88bd..953eb75c 100644 --- a/Octokit/Models/Request/SearchIssuesRequest.cs +++ b/Octokit/Models/Request/SearchIssuesRequest.cs @@ -2,7 +2,6 @@ using System.Diagnostics; using Octokit.Internal; using System; -using System.Collections; using System.Collections.Generic; using System.Linq; using System.Globalization; @@ -337,72 +336,28 @@ namespace Octokit Issue } - public class RepositoryCollection : IEnumerable + public class RepositoryCollection : Collection { - readonly ICollection _repositories = new List(); - - public IEnumerator GetEnumerator() - { - return _repositories.GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - public void Add(string owner, string name) { - Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNullOrEmptyString(name, "name"); - - _repositories.Add(GetRepositoryName(owner, name)); - } - - public void Add(string nameWithOwner) - { - Ensure.ArgumentNotNullOrEmptyString(nameWithOwner, "nameWithOwner"); - - _repositories.Add(nameWithOwner); - } - - public void Clear() - { - _repositories.Clear(); + Add(GetRepositoryName(owner, name)); } public bool Contains(string owner, string name) { - Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNullOrEmptyString(name, "name"); - - return _repositories.Contains(GetRepositoryName(owner, name)); - } - - public bool Contains(string nameWithOwner) - { - Ensure.ArgumentNotNullOrEmptyString(nameWithOwner, "nameWithOwner"); - - return _repositories.Contains(nameWithOwner); + return Contains(GetRepositoryName(owner, name)); } public bool Remove(string owner, string name) { - Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNullOrEmptyString(name, "name"); - - return _repositories.Remove(GetRepositoryName(owner, name)); - } - - public bool Remove(string nameWithOwner) - { - Ensure.ArgumentNotNullOrEmptyString(nameWithOwner, "nameWithOwner"); - - return _repositories.Remove(nameWithOwner); + return Remove(GetRepositoryName(owner, name)); } private static string GetRepositoryName(string owner, string name) { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + return string.Format(CultureInfo.InvariantCulture, "{0}/{1}", owner, name); } }