From 1053a2045df8bb47c863e23401e382a97dd7f49c Mon Sep 17 00:00:00 2001 From: Colby Williams Date: Fri, 21 Jun 2024 14:09:43 -0500 Subject: [PATCH 1/2] [FEAT]: Search based on repository custom property (#2936) search based on repository custom property --- Octokit.Tests/Clients/SearchClientTests.cs | 23 +++++++ .../Models/SearchRepositoryRequestTests.cs | 10 ++- .../Request/SearchRepositoriesRequest.cs | 67 +++++++++++++------ 3 files changed, 78 insertions(+), 22 deletions(-) diff --git a/Octokit.Tests/Clients/SearchClientTests.cs b/Octokit.Tests/Clients/SearchClientTests.cs index 2ade8ef144..47c2a7600e 100644 --- a/Octokit.Tests/Clients/SearchClientTests.cs +++ b/Octokit.Tests/Clients/SearchClientTests.cs @@ -738,6 +738,29 @@ public void TestingTheTopicsQualifierWithTwoOrLessTopics() Assert.Contains("topics:<=2", request.MergedQualifiers()); } + + [Fact] + public void TestingTheCustomPropertiesQualifier() + { + var request = new SearchRepositoriesRequest("github"); + request.CustomProperties = new Dictionary { { "custom", "value" } }; + + Assert.Contains("props.custom:value", request.MergedQualifiers()); + } + + [Fact] + public void TestingMultipleCustomPropertiesQualifiers() + { + var request = new SearchRepositoriesRequest("github"); + request.CustomProperties = new Dictionary { + { "custom_one", "value_one" }, + { "custom_two", "value_two" } + }; + + var merged = request.MergedQualifiers(); + Assert.Contains("props.custom_one:value_one", merged); + Assert.Contains("props.custom_two:value_two", merged); + } } public class TheSearchIssuesMethod diff --git a/Octokit.Tests/Models/SearchRepositoryRequestTests.cs b/Octokit.Tests/Models/SearchRepositoryRequestTests.cs index e9441131d6..d1ed6e552f 100644 --- a/Octokit.Tests/Models/SearchRepositoryRequestTests.cs +++ b/Octokit.Tests/Models/SearchRepositoryRequestTests.cs @@ -1,4 +1,4 @@ -using System; +using System.Collections.Generic; using Octokit; using Octokit.Tests.Helpers; using Xunit; @@ -41,5 +41,13 @@ public void LicenseUsesParameterTranslation() var result = request.MergedQualifiers(); Assert.Contains(result, x => string.Equals(x, "license:apache-2.0")); } + + [Fact] + public void CustomPropertiesPrependsProps() + { + var request = new SearchRepositoriesRequest() { CustomProperties = new Dictionary { { "name", "value" } } }; + var result = request.MergedQualifiers(); + Assert.Contains(result, x => string.Equals(x, "props.name:value")); + } } } diff --git a/Octokit/Models/Request/SearchRepositoriesRequest.cs b/Octokit/Models/Request/SearchRepositoriesRequest.cs index 3a13b9dba3..114962bda4 100644 --- a/Octokit/Models/Request/SearchRepositoriesRequest.cs +++ b/Octokit/Models/Request/SearchRepositoriesRequest.cs @@ -10,7 +10,7 @@ namespace Octokit { /// /// Searching Repositories - /// http://developer.github.com/v3/search/#search-repositories + /// https://docs.github.com/rest/search/search#search-repositories /// [DebuggerDisplay("{DebuggerDisplay,nq}")] public class SearchRepositoriesRequest : BaseSearchRequest @@ -33,7 +33,7 @@ public SearchRepositoriesRequest(string term) } /// - /// For https://help.github.com/articles/searching-repositories#sorting + /// For https://docs.github.com/search-github/getting-started-with-searching-on-github/sorting-search-results /// Optional Sort field. One of stars, forks, or updated. If not provided, results are sorted by best match. /// public RepoSearchSort? SortField { get; set; } @@ -46,9 +46,9 @@ public override string Sort private IEnumerable _inQualifier; /// - /// The in qualifier limits what fields are searched. With this qualifier you can restrict the search to just the repository name, description, README, or any combination of these. + /// The in qualifier limits what fields are searched. With this qualifier you can restrict the search to just the repository name, description, README, or any combination of these. /// Without the qualifier, only the name and description are searched. - /// https://help.github.com/articles/searching-repositories#search-in + /// https://docs.github.com/search-github/searching-on-github/searching-for-repositories#search-by-repository-name-description-or-contents-of-the-readme-file /// public IEnumerable In { @@ -65,74 +65,83 @@ public IEnumerable In /// /// Filters repositories based on the number of forks, and/or whether forked repositories should be included in the results at all. - /// https://help.github.com/articles/searching-repositories#forks + /// https://docs.github.com/search-github/searching-on-github/searching-for-repositories#search-by-number-of-forks /// public Range Forks { get; set; } /// /// Filters repositories based whether forked repositories should be included in the results at all. /// Defaults to ExcludeForks - /// https://help.github.com/articles/searching-repositories#forks + /// https://docs.github.com/search-github/searching-on-github/searching-in-forks /// public ForkQualifier? Fork { get; set; } /// /// The size qualifier finds repository's that match a certain size (in kilobytes). - /// https://help.github.com/articles/searching-repositories#size + /// https://docs.github.com/search-github/searching-on-github/searching-for-repositories#search-by-repository-size /// public Range Size { get; set; } /// /// Searches repositories based on the language they’re written in. - /// https://help.github.com/articles/searching-repositories#languages + /// https://docs.github.com/search-github/searching-on-github/searching-for-repositories#search-by-language /// public Language? Language { get; set; } /// /// Searches repositories based on the number of stars. - /// https://help.github.com/articles/searching-repositories#stars + /// https://docs.github.com/search-github/searching-on-github/searching-for-repositories#search-by-number-of-stars /// public Range Stars { get; set; } /// /// Limits searches to a specific user or repository. - /// https://help.github.com/articles/searching-repositories#users-organizations-and-repositories + /// https://docs.github.com/search-github/searching-on-github/searching-for-repositories#search-within-a-users-or-organizations-repositories /// public string User { get; set; } /// /// Filters repositories based on times of creation. - /// https://help.github.com/articles/searching-repositories#created-and-last-updated + /// https://docs.github.com/search-github/searching-on-github/searching-for-repositories#search-by-when-a-repository-was-created-or-last-updated /// public DateRange Created { get; set; } /// /// Filters repositories based on when they were last updated. - /// https://help.github.com/articles/searching-repositories#created-and-last-updated + /// https://docs.github.com/search-github/searching-on-github/searching-for-repositories#search-by-when-a-repository-was-created-or-last-updated /// public DateRange Updated { get; set; } /// /// Filters repositories based on license - /// https://help.github.com/articles/searching-repositories#search-by-license + /// https://docs.github.com/search-github/searching-on-github/searching-for-repositories#search-by-license /// public RepoSearchLicense? License { get; set; } /// /// Filters whether archived repositories should be included (true) or not (false). + /// https://docs.github.com/search-github/searching-on-github/searching-for-repositories#search-based-on-whether-a-repository-is-archived /// public bool? Archived { get; set; } /// /// Filters on whether repositories are tagged with the given topic. + /// https://docs.github.com/search-github/searching-on-github/searching-for-repositories#search-by-topic /// public string Topic { get; set; } /// /// Filters on the number of topics that a repository is associated with. + /// https://docs.github.com/search-github/searching-on-github/searching-for-repositories#search-by-number-of-topics /// public Range Topics { get; set; } + /// + /// Filters on repositories based on custom properties. + /// https://docs.github.com/search-github/searching-on-github/searching-for-repositories#search-based-on-repository-custom-property + /// + public IDictionary CustomProperties { get; set; } + public override IReadOnlyList MergedQualifiers() { var parameters = new List(); @@ -200,6 +209,13 @@ public override IReadOnlyList MergedQualifiers() { parameters.Add(string.Format(CultureInfo.InvariantCulture, "license:{0}", License.ToParameter())); } + if (CustomProperties != null) + { + foreach (var customProperty in CustomProperties) + { + parameters.Add(string.Format(CultureInfo.InvariantCulture, "props.{0}:{1}", customProperty.Key, customProperty.Value)); + } + } return parameters; } @@ -214,8 +230,8 @@ internal string DebuggerDisplay } /// - /// https://help.github.com/articles/searching-repositories#search-in - /// The in qualifier limits what fields are searched. With this qualifier you can restrict the search to just the + /// https://docs.github.com/search-github/searching-on-github/searching-for-repositories#search-by-repository-name-description-or-contents-of-the-readme-file + /// The in qualifier limits what fields are searched. With this qualifier you can restrict the search to just the /// repository name, description, README, or any combination of these. /// public enum InQualifier @@ -226,6 +242,9 @@ public enum InQualifier [Parameter(Value = "description")] Description, + [Parameter(Value = "topics")] + Topics, + [Parameter(Value = "readme")] Readme } @@ -256,7 +275,7 @@ public Range(int minSize, int maxSize) } /// - /// Matches repositories with regards to the size + /// Matches repositories with regards to the size /// We will use the to see what operator will be applied to the size qualifier /// public Range(int size, SearchQualifierOperator op) @@ -323,7 +342,7 @@ public override string ToString() /// /// helper class in generating the date range values for the date qualifier e.g. - /// https://help.github.com/articles/searching-repositories#created-and-last-updated + /// https://docs.github.com/search-github/searching-on-github/searching-for-repositories#search-by-when-a-repository-was-created-or-last-updated /// [DebuggerDisplay("{DebuggerDisplay,nq}")] public class DateRange @@ -532,7 +551,7 @@ public override string ToString() /// /// Languages that can be searched on in GitHub - /// https://help.github.com/articles/searching-repositories#languages + /// https://docs.github.com/search-github/searching-on-github/searching-for-repositories#search-by-language /// public enum Language { @@ -897,7 +916,7 @@ public enum Language /// /// Licenses than can be searched on GitHub - /// https://help.github.com/articles/searching-repositories#search-by-license + /// https://docs.github.com/search-github/searching-on-github/searching-for-repositories#search-by-license /// public enum RepoSearchLicense { @@ -989,7 +1008,8 @@ public enum RepoSearchLicense /// /// sorting repositories by any of below - /// https://help.github.com/articles/searching-repositories#sorting + /// https://docs.github.com/rest/search/search?#search-repositories + /// https://docs.github.com/search-github/getting-started-with-searching-on-github/sorting-search-results /// public enum RepoSearchSort { @@ -1004,6 +1024,11 @@ public enum RepoSearchSort [Parameter(Value = "forks")] Forks, /// + /// search by number of help-wanted-issues + /// + [Parameter(Value = "help-wanted-issues")] + HelpWantedIssues, + /// /// search by last updated /// [Parameter(Value = "updated")] @@ -1011,7 +1036,7 @@ public enum RepoSearchSort } /// - /// https://help.github.com/articles/searching-repositories#forks + /// https://docs.github.com/search-github/searching-on-github/searching-in-forks /// Specifying whether forked repositories should be included in results or not. /// public enum ForkQualifier From bdc16944aefc06fd0da06077c394a87decbecc6a Mon Sep 17 00:00:00 2001 From: Lars Zweifel <132883445+lars-zweifel@users.noreply.github.com> Date: Fri, 21 Jun 2024 21:17:55 +0200 Subject: [PATCH 2/2] feat: added Missing APIOption overload for PackagesClient.GetAll* #2923 (#2934) feat: added Missing APIOption overload for PackagesClient.GetAll* #2923 added missing APIOption overload for PackagesClient and ObservablePackagesClient added overload for optional parameter packageVisibility to be a nonbreaking change extended PackagesClientTests.cs to be conform with RepositoriesClientTests.cs to take ApiOptions into account --- .../Clients/IObservablePackagesClient.cs | 102 +++++++++- .../Clients/ObservablePackagesClient.cs | 167 +++++++++++++++- Octokit.Tests/Clients/PackagesClientTests.cs | 12 +- Octokit/Clients/IPackagesClient.cs | 108 ++++++++++- Octokit/Clients/PackagesClient.cs | 178 +++++++++++++++++- 5 files changed, 540 insertions(+), 27 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservablePackagesClient.cs b/Octokit.Reactive/Clients/IObservablePackagesClient.cs index 6814cad88d..717ae04d1e 100644 --- a/Octokit.Reactive/Clients/IObservablePackagesClient.cs +++ b/Octokit.Reactive/Clients/IObservablePackagesClient.cs @@ -7,6 +7,27 @@ public interface IObservablePackagesClient { IObservablePackageVersionsClient PackageVersions { get; } + /// + /// List all packages for an organisations, readable by the current user + /// + /// + /// See the API documentation for more details + /// + /// Required: Organisation Name + /// Required: The type of package + IObservable GetAllForOrg(string org, PackageType packageType); + + /// + /// List all packages for an organisations, readable by the current user + /// + /// + /// See the API documentation for more details + /// + /// Required: Organisation Name + /// Required: The type of package + /// Options for changing the API response + IObservable GetAllForOrg(string org, PackageType packageType, ApiOptions options); + /// /// List all packages for an organisations, readable by the current user /// @@ -16,7 +37,19 @@ public interface IObservablePackagesClient /// Required: Organisation Name /// Required: The type of package /// Optional: The visibility of the package - IObservable GetAllForOrg(string org, PackageType packageType, PackageVisibility? packageVisibility = null); + IObservable GetAllForOrg(string org, PackageType packageType, PackageVisibility? packageVisibility); + + /// + /// List all packages for an organisations, readable by the current user + /// + /// + /// See the API documentation for more details + /// + /// Required: Organisation Name + /// Required: The type of package + /// Optional: The visibility of the package + /// Options for changing the API response + IObservable GetAllForOrg(string org, PackageType packageType, PackageVisibility? packageVisibility, ApiOptions options); /// /// Get a specific package for an Organization. @@ -51,6 +84,35 @@ public interface IObservablePackagesClient /// Required: The name of the package IObservable RestoreForOrg(string org, PackageType packageType, string packageName); + /// + /// Lists packages owned by the authenticated user within the user's namespace + /// + /// + /// See the API documentation for more details + /// + /// Required: The type of package + IObservable GetAllForActiveUser(PackageType packageType); + + /// + /// Lists packages owned by the authenticated user within the user's namespace + /// + /// + /// See the API documentation for more details + /// + /// Required: The type of package + /// Options for changing the API response + IObservable GetAllForActiveUser(PackageType packageType, ApiOptions options); + + /// + /// Lists packages owned by the authenticated user within the user's namespace + /// + /// + /// See the API documentation for more details + /// + /// Required: The type of package + /// Optional: The visibility of the package + IObservable GetAllForActiveUser(PackageType packageType, PackageVisibility? packageVisibility); + /// /// Lists packages owned by the authenticated user within the user's namespace /// @@ -59,7 +121,8 @@ public interface IObservablePackagesClient /// /// Required: The type of package /// Optional: The visibility of the package - IObservable GetAllForActiveUser(PackageType packageType, PackageVisibility? packageVisibility = null); + /// Options for changing the API response + IObservable GetAllForActiveUser(PackageType packageType, PackageVisibility? packageVisibility, ApiOptions options); /// /// Gets a specific package for a package owned by the authenticated user. @@ -91,6 +154,38 @@ public interface IObservablePackagesClient /// Required: The name of the package IObservable RestoreForActiveUser(PackageType packageType, string packageName); + /// + /// Lists packages owned by the authenticated user within the user's namespace + /// + /// + /// See the API documentation for more details + /// + /// Required: Username + /// Required: The type of package + IObservable GetAllForUser(string username, PackageType packageType); + + /// + /// Lists packages owned by the authenticated user within the user's namespace + /// + /// + /// See the API documentation for more details + /// + /// Required: Username + /// Required: The type of package + /// Options for changing the API response + IObservable GetAllForUser(string username, PackageType packageType, ApiOptions options); + + /// + /// Lists packages owned by the authenticated user within the user's namespace + /// + /// + /// See the API documentation for more details + /// + /// Required: Username + /// Required: The type of package + /// Optional: The visibility of the package + IObservable GetAllForUser(string username, PackageType packageType, PackageVisibility? packageVisibility); + /// /// Lists packages owned by the authenticated user within the user's namespace /// @@ -100,7 +195,8 @@ public interface IObservablePackagesClient /// Required: Username /// Required: The type of package /// Optional: The visibility of the package - IObservable GetAllForUser(string username, PackageType packageType, PackageVisibility? packageVisibility = null); + /// Options for changing the API response + IObservable GetAllForUser(string username, PackageType packageType, PackageVisibility? packageVisibility, ApiOptions options); /// /// Gets a specific package metadata for a public package owned by a user. diff --git a/Octokit.Reactive/Clients/ObservablePackagesClient.cs b/Octokit.Reactive/Clients/ObservablePackagesClient.cs index 662efb556b..a1e0981c91 100644 --- a/Octokit.Reactive/Clients/ObservablePackagesClient.cs +++ b/Octokit.Reactive/Clients/ObservablePackagesClient.cs @@ -20,6 +20,40 @@ public ObservablePackagesClient(IGitHubClient client) public IObservablePackageVersionsClient PackageVersions { get; private set; } + /// + /// List all packages for an organisations, readable by the current user + /// + /// + /// See the API documentation for more details + /// + /// Required: Organisation Name + /// Required: The type of package + public IObservable GetAllForOrg(string org, PackageType packageType) + { + Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); + Ensure.ArgumentNotNull(packageType, nameof(packageType)); + + return GetAllForOrg(org, packageType, (PackageVisibility?)null); + } + + /// + /// List all packages for an organisations, readable by the current user + /// + /// + /// See the API documentation for more details + /// + /// Required: Organisation Name + /// Required: The type of package + /// Options for changing the API response + public IObservable GetAllForOrg(string org, PackageType packageType, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); + Ensure.ArgumentNotNull(packageType, nameof(packageType)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return GetAllForOrg(org, packageType, null, options); + } + /// /// List all packages for an organisations, readable by the current user /// @@ -29,15 +63,34 @@ public ObservablePackagesClient(IGitHubClient client) /// Required: Organisation Name /// Required: The type of package /// Optional: The visibility of the package - public IObservable GetAllForOrg(string org, PackageType packageType, PackageVisibility? packageVisibility = null) + public IObservable GetAllForOrg(string org, PackageType packageType, PackageVisibility? packageVisibility) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); Ensure.ArgumentNotNull(packageType, nameof(packageType)); + return GetAllForOrg(org, packageType, packageVisibility, ApiOptions.None); + } + + /// + /// List all packages for an organisations, readable by the current user + /// + /// + /// See the API documentation for more details + /// + /// Required: Organisation Name + /// Required: The type of package + /// Optional: The visibility of the package + /// Options for changing the API response + public IObservable GetAllForOrg(string org, PackageType packageType, PackageVisibility? packageVisibility, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); + Ensure.ArgumentNotNull(packageType, nameof(packageType)); + Ensure.ArgumentNotNull(options, nameof(options)); + var route = ApiUrls.PackagesOrg(org); var parameters = ParameterBuilder.AddParameter("package_type", packageType).AddOptionalParameter("visibility", packageVisibility); - return _connection.GetAndFlattenAllPages(route, parameters); + return _connection.GetAndFlattenAllPages(route, parameters, options); } /// @@ -94,6 +147,51 @@ public IObservable RestoreForOrg(string org, PackageType packageType, stri return _client.RestoreForOrg(org, packageType, packageName).ToObservable(); } + /// + /// Lists packages owned by the authenticated user within the user's namespace + /// + /// + /// See the API documentation for more details + /// + /// Required: The type of package + public IObservable GetAllForActiveUser(PackageType packageType) + { + Ensure.ArgumentNotNull(packageType, nameof(packageType)); + + return GetAllForActiveUser(packageType, ApiOptions.None); + } + + /// + /// Lists packages owned by the authenticated user within the user's namespace + /// + /// + /// See the API documentation for more details + /// + /// Required: The type of package + /// Options for changing the API response + public IObservable GetAllForActiveUser(PackageType packageType, ApiOptions options) + { + Ensure.ArgumentNotNull(packageType, nameof(packageType)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return GetAllForActiveUser(packageType, null, options); + } + + /// + /// Lists packages owned by the authenticated user within the user's namespace + /// + /// + /// See the API documentation for more details + /// + /// Required: The type of package + /// Optional: The visibility of the package + public IObservable GetAllForActiveUser(PackageType packageType, PackageVisibility? packageVisibility) + { + Ensure.ArgumentNotNull(packageType, nameof(packageType)); + + return GetAllForActiveUser(packageType, packageVisibility, ApiOptions.None); + } + /// /// Lists packages owned by the authenticated user within the user's namespace /// @@ -102,12 +200,16 @@ public IObservable RestoreForOrg(string org, PackageType packageType, stri /// /// Required: The type of package /// Optional: The visibility of the package - public IObservable GetAllForActiveUser(PackageType packageType, PackageVisibility? packageVisibility = null) + /// Options for changing the API response + public IObservable GetAllForActiveUser(PackageType packageType, PackageVisibility? packageVisibility, ApiOptions options) { + Ensure.ArgumentNotNull(packageType, nameof(packageType)); + Ensure.ArgumentNotNull(options, nameof(options)); + var route = ApiUrls.PackagesActiveUser(); var parameters = ParameterBuilder.AddParameter("package_type", packageType).AddOptionalParameter("visibility", packageVisibility); - return _connection.GetAndFlattenAllPages(route, parameters); + return _connection.GetAndFlattenAllPages(route, parameters, options); } /// @@ -158,6 +260,57 @@ public IObservable RestoreForActiveUser(PackageType packageType, string pa return _client.RestoreForActiveUser(packageType, packageName).ToObservable(); } + /// + /// Lists packages owned by the authenticated user within the user's namespace + /// + /// + /// See the API documentation for more details + /// + /// Required: Username + /// Required: The type of package + public IObservable GetAllForUser(string username, PackageType packageType) + { + Ensure.ArgumentNotNullOrEmptyString(username, nameof(username)); + Ensure.ArgumentNotNull(packageType, nameof(packageType)); + + return GetAllForUser(username, packageType, ApiOptions.None); + } + + /// + /// Lists packages owned by the authenticated user within the user's namespace + /// + /// + /// See the API documentation for more details + /// + /// Required: Username + /// Required: The type of package + /// Options for changing the API response + public IObservable GetAllForUser(string username, PackageType packageType, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(username, nameof(username)); + Ensure.ArgumentNotNull(packageType, nameof(packageType)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return GetAllForUser(username, packageType, null, options); + } + + /// + /// Lists packages owned by the authenticated user within the user's namespace + /// + /// + /// See the API documentation for more details + /// + /// Required: Username + /// Required: The type of package + /// Optional: The visibility of the package + public IObservable GetAllForUser(string username, PackageType packageType, PackageVisibility? packageVisibility) + { + Ensure.ArgumentNotNullOrEmptyString(username, nameof(username)); + Ensure.ArgumentNotNull(packageType, nameof(packageType)); + + return GetAllForUser(username, packageType, packageVisibility, ApiOptions.None); + } + /// /// Lists packages owned by the authenticated user within the user's namespace /// @@ -167,15 +320,17 @@ public IObservable RestoreForActiveUser(PackageType packageType, string pa /// Required: Username /// Required: The type of package /// Optional: The visibility of the package - public IObservable GetAllForUser(string username, PackageType packageType, PackageVisibility? packageVisibility = null) + /// Options for changing the API response + public IObservable GetAllForUser(string username, PackageType packageType, PackageVisibility? packageVisibility, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(username, nameof(username)); Ensure.ArgumentNotNull(packageType, nameof(packageType)); + Ensure.ArgumentNotNull(options, nameof(options)); var route = ApiUrls.PackagesUser(username); var parameters = ParameterBuilder.AddParameter("package_type", packageType).AddOptionalParameter("visibility", packageVisibility); - return _connection.GetAndFlattenAllPages(route, parameters); + return _connection.GetAndFlattenAllPages(route, parameters, options); } /// diff --git a/Octokit.Tests/Clients/PackagesClientTests.cs b/Octokit.Tests/Clients/PackagesClientTests.cs index 2da109bf1f..7832ac6bf2 100644 --- a/Octokit.Tests/Clients/PackagesClientTests.cs +++ b/Octokit.Tests/Clients/PackagesClientTests.cs @@ -27,7 +27,7 @@ public async Task RequestsCorrectUrl() await client.GetAllForOrg("fake", PackageType.RubyGems); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "orgs/fake/packages"), Arg.Is>(d => d.ContainsKey("package_type"))); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "orgs/fake/packages"), Arg.Is>(d => d.ContainsKey("package_type")), Args.ApiOptions); } [Fact] @@ -39,7 +39,7 @@ public async Task RequestsCorrectUrlWithOptionalParameter() await client.GetAllForOrg("fake", PackageType.RubyGems, PackageVisibility.Public); var calls = connection.ReceivedCalls(); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "orgs/fake/packages"), Arg.Is>(d => d.ContainsKey("package_type") && d.ContainsKey("visibility"))); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "orgs/fake/packages"), Arg.Is>(d => d.ContainsKey("package_type") && d.ContainsKey("visibility")), Args.ApiOptions); } [Fact] @@ -141,7 +141,7 @@ public async Task RequestsCorrectUrl() await client.GetAllForActiveUser(PackageType.RubyGems); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "user/packages"), Arg.Is>(d => d.ContainsKey("package_type"))); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "user/packages"), Arg.Is>(d => d.ContainsKey("package_type")), Args.ApiOptions); } [Fact] @@ -153,7 +153,7 @@ public async Task RequestsCorrectUrlWithOptionalParameter() await client.GetAllForActiveUser(PackageType.RubyGems, PackageVisibility.Public); var calls = connection.ReceivedCalls(); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "user/packages"), Arg.Is>(d => d.ContainsKey("package_type") && d.ContainsKey("visibility"))); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "user/packages"), Arg.Is>(d => d.ContainsKey("package_type") && d.ContainsKey("visibility")), Args.ApiOptions); } } @@ -236,7 +236,7 @@ public async Task RequestsCorrectUrl() await client.GetAllForUser("fake", PackageType.RubyGems); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/packages"), Arg.Is>(d => d.ContainsKey("package_type"))); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/packages"), Arg.Is>(d => d.ContainsKey("package_type")), Args.ApiOptions); } [Fact] @@ -248,7 +248,7 @@ public async Task RequestsCorrectUrlWithOptionalParameter() await client.GetAllForUser("fake", PackageType.RubyGems, PackageVisibility.Public); var calls = connection.ReceivedCalls(); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/packages"), Arg.Is>(d => d.ContainsKey("package_type") && d.ContainsKey("visibility"))); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/fake/packages"), Arg.Is>(d => d.ContainsKey("package_type") && d.ContainsKey("visibility")), Args.ApiOptions); } [Fact] diff --git a/Octokit/Clients/IPackagesClient.cs b/Octokit/Clients/IPackagesClient.cs index 25dac896d0..5c657b87ea 100644 --- a/Octokit/Clients/IPackagesClient.cs +++ b/Octokit/Clients/IPackagesClient.cs @@ -7,6 +7,27 @@ public interface IPackagesClient { IPackageVersionsClient PackageVersions { get; } + /// + /// List all packages for an organisations, readable by the current user + /// + /// + /// See the API documentation for more details + /// + /// Required: Organisation Name + /// Required: The type of package + Task> GetAllForOrg(string org, PackageType packageType); + + /// + /// List all packages for an organisations, readable by the current user + /// + /// + /// See the API documentation for more details + /// + /// Required: Organisation Name + /// Required: The type of package + /// Options for changing the API response + Task> GetAllForOrg(string org, PackageType packageType, ApiOptions options); + /// /// List all packages for an organisations, readable by the current user /// @@ -16,8 +37,20 @@ public interface IPackagesClient /// Required: Organisation Name /// Required: The type of package /// Optional: The visibility of the package - [ExcludeFromPaginationApiOptionsConventionTest("No api options available according to the documentation")] - Task> GetAllForOrg(string org, PackageType packageType, PackageVisibility? packageVisibility = null); + Task> GetAllForOrg(string org, PackageType packageType, PackageVisibility? packageVisibility); + + /// + /// List all packages for an organisations, readable by the current user + /// + /// + /// See the API documentation for more details + /// The default page size on GitHub.com is 30. + /// + /// Required: Organisation Name + /// Required: The type of package + /// Optional: The visibility of the package + /// Options for changing the API response + Task> GetAllForOrg(string org, PackageType packageType, PackageVisibility? packageVisibility, ApiOptions options); /// /// Get a specific package for an Organization. @@ -59,9 +92,39 @@ public interface IPackagesClient /// See the API documentation for more details /// /// Required: The type of package + Task> GetAllForActiveUser(PackageType packageType); + + /// + /// Lists packages owned by the authenticated user within the user's namespace + /// + /// + /// See the API documentation for more details + /// + /// Required: The type of package + /// Options for changing the API response + Task> GetAllForActiveUser(PackageType packageType, ApiOptions options); + + /// + /// Lists packages owned by the authenticated user within the user's namespace + /// + /// + /// See the API documentation for more details + /// + /// Required: The type of package + /// Optional: The visibility of the package + Task> GetAllForActiveUser(PackageType packageType, PackageVisibility? packageVisibility); + + /// + /// Lists packages owned by the authenticated user within the user's namespace + /// + /// + /// See the API documentation for more details + /// The default page size on GitHub.com is 30. + /// + /// Required: The type of package /// Optional: The visibility of the package - [ExcludeFromPaginationApiOptionsConventionTest("No api options available according to the documentation")] - Task> GetAllForActiveUser(PackageType packageType, PackageVisibility? packageVisibility = null); + /// Options for changing the API response + Task> GetAllForActiveUser(PackageType packageType, PackageVisibility? packageVisibility, ApiOptions options); /// /// Gets a specific package for a package owned by the authenticated user. @@ -101,9 +164,42 @@ public interface IPackagesClient /// /// Required: Username /// Required: The type of package + Task> GetAllForUser(string username, PackageType packageType); + + /// + /// Lists packages owned by the authenticated user within the user's namespace + /// + /// + /// See the API documentation for more details + /// + /// Required: Username + /// Required: The type of package + /// Options for changing the API response + Task> GetAllForUser(string username, PackageType packageType, ApiOptions options); + + /// + /// Lists packages owned by the authenticated user within the user's namespace + /// + /// + /// See the API documentation for more details + /// + /// Required: Username + /// Required: The type of package + /// Optional: The visibility of the package + Task> GetAllForUser(string username, PackageType packageType, PackageVisibility? packageVisibility); + + /// + /// Lists packages owned by the authenticated user within the user's namespace + /// + /// + /// See the API documentation for more details + /// The default page size on GitHub.com is 30. + /// + /// Required: Username + /// Required: The type of package /// Optional: The visibility of the package - [ExcludeFromPaginationApiOptionsConventionTest("No api options available according to the documentation")] - Task> GetAllForUser(string username, PackageType packageType, PackageVisibility? packageVisibility = null); + /// Options for changing the API response + Task> GetAllForUser(string username, PackageType packageType, PackageVisibility? packageVisibility, ApiOptions options); /// /// Gets a specific package metadata for a public package owned by a user. diff --git a/Octokit/Clients/PackagesClient.cs b/Octokit/Clients/PackagesClient.cs index 91a6983315..9ace9828c5 100644 --- a/Octokit/Clients/PackagesClient.cs +++ b/Octokit/Clients/PackagesClient.cs @@ -19,6 +19,60 @@ public PackagesClient(IApiConnection apiConnection) : base(apiConnection) public IPackageVersionsClient PackageVersions { get; private set; } #region Organization + /// + /// List all packages for an organisations, readable by the current user + /// + /// + /// See the API documentation for more details + /// + /// Required: Organisation Name + /// Required: The type of package + [ManualRoute("GET", "/orgs/{org}/packages")] + public Task> GetAllForOrg(string org, PackageType packageType) + { + Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); + Ensure.ArgumentNotNull(packageType, nameof(packageType)); + + return GetAllForOrg(org, packageType, ApiOptions.None); + } + + /// + /// List all packages for an organisations, readable by the current user + /// + /// + /// See the API documentation for more details + /// + /// Required: Organisation Name + /// Required: The type of package + /// Options for changing the API response + [ManualRoute("GET", "/orgs/{org}/packages")] + public Task> GetAllForOrg(string org, PackageType packageType, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); + Ensure.ArgumentNotNull(packageType, nameof(packageType)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return GetAllForOrg(org, packageType, null, options); + } + + /// + /// List all packages for an organisations, readable by the current user + /// + /// + /// See the API documentation for more details + /// + /// Required: Organisation Name + /// Required: The type of package + /// Optional: The visibility of the package + [ManualRoute("GET", "/orgs/{org}/packages")] + public Task> GetAllForOrg(string org, PackageType packageType, PackageVisibility? packageVisibility) + { + Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); + Ensure.ArgumentNotNull(packageType, nameof(packageType)); + + return GetAllForOrg(org, packageType, packageVisibility, ApiOptions.None); + } + /// /// List all packages for an organisations, readable by the current user /// @@ -28,15 +82,18 @@ public PackagesClient(IApiConnection apiConnection) : base(apiConnection) /// Required: Organisation Name /// Required: The type of package /// Optional: The visibility of the package + /// Options for changing the API response [ManualRoute("GET", "/orgs/{org}/packages")] - public Task> GetAllForOrg(string org, PackageType packageType, PackageVisibility? packageVisibility = null) + public Task> GetAllForOrg(string org, PackageType packageType, PackageVisibility? packageVisibility, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); + Ensure.ArgumentNotNull(packageType, nameof(packageType)); + Ensure.ArgumentNotNull(options, nameof(options)); var route = ApiUrls.PackagesOrg(org); var parameters = ParameterBuilder.AddParameter("package_type", packageType).AddOptionalParameter("visibility", packageVisibility); - return ApiConnection.GetAll(route, parameters); + return ApiConnection.GetAll(route, parameters, options); } /// @@ -73,6 +130,7 @@ public Task DeleteForOrg(string org, PackageType packageType, string packageName { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); Ensure.ArgumentNotNullOrEmptyString(packageName, nameof(packageName)); + Ensure.ArgumentNotNull(packageType, nameof(packageType)); var route = ApiUrls.PackageOrg(org, packageType, packageName); @@ -101,6 +159,38 @@ public Task RestoreForOrg(string org, PackageType packageType, string packageNam #endregion #region Active User + /// + /// Lists packages owned by the authenticated user within the user's namespace + /// + /// + /// See the API documentation for more details + /// + /// Required: The type of package + [ManualRoute("GET", "/user/packages")] + public Task> GetAllForActiveUser(PackageType packageType) + { + Ensure.ArgumentNotNull(packageType, nameof(packageType)); + + return GetAllForActiveUser(packageType, (PackageVisibility?)null); + } + + /// + /// Lists packages owned by the authenticated user within the user's namespace + /// + /// + /// See the API documentation for more details + /// + /// Required: The type of package + /// Options for changing the API response + [ManualRoute("GET", "/user/packages")] + public Task> GetAllForActiveUser(PackageType packageType, ApiOptions options) + { + Ensure.ArgumentNotNull(packageType, nameof(packageType)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return GetAllForActiveUser(packageType, null, options); + } + /// /// Lists packages owned by the authenticated user within the user's namespace /// @@ -110,12 +200,32 @@ public Task RestoreForOrg(string org, PackageType packageType, string packageNam /// Required: The type of package /// Optional: The visibility of the package [ManualRoute("GET", "/user/packages")] - public Task> GetAllForActiveUser(PackageType packageType, PackageVisibility? packageVisibility = null) + public Task> GetAllForActiveUser(PackageType packageType, PackageVisibility? packageVisibility) { + Ensure.ArgumentNotNull(packageType, nameof(packageType)); + + return GetAllForActiveUser(packageType, packageVisibility, ApiOptions.None); + } + + /// + /// Lists packages owned by the authenticated user within the user's namespace + /// + /// + /// See the API documentation for more details + /// + /// Required: The type of package + /// Optional: The visibility of the package + /// Options for changing the API response + [ManualRoute("GET", "/user/packages")] + public Task> GetAllForActiveUser(PackageType packageType, PackageVisibility? packageVisibility, ApiOptions options) + { + Ensure.ArgumentNotNull(packageType, nameof(packageType)); + Ensure.ArgumentNotNull(options, nameof(options)); + var route = ApiUrls.PackagesActiveUser(); var parameters = ParameterBuilder.AddParameter("package_type", packageType).AddOptionalParameter("visibility", packageVisibility); - return ApiConnection.GetAll(route, parameters); + return ApiConnection.GetAll(route, parameters, options); } /// @@ -174,6 +284,59 @@ public Task RestoreForActiveUser(PackageType packageType, string packageName) #endregion #region Specific User + /// + /// Lists packages owned by the authenticated user within the user's namespace + /// + /// + /// See the API documentation for more details + /// + /// Required: Username + /// Required: The type of package + [ManualRoute("GET", "/users/{username}/packages")] + public Task> GetAllForUser(string username, PackageType packageType) + { + Ensure.ArgumentNotNullOrEmptyString(username, nameof(username)); + Ensure.ArgumentNotNull(packageType, nameof(packageType)); + + return GetAllForUser(username, packageType, ApiOptions.None); + } + + /// + /// Lists packages owned by the authenticated user within the user's namespace + /// + /// + /// See the API documentation for more details + /// + /// Required: Username + /// Required: The type of package + /// Options for changing the API response + [ManualRoute("GET", "/users/{username}/packages")] + public Task> GetAllForUser(string username, PackageType packageType, ApiOptions options) + { + Ensure.ArgumentNotNull(packageType, nameof(packageType)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return GetAllForUser(username, packageType, null, options); + } + + /// + /// Lists packages owned by the authenticated user within the user's namespace + /// + /// + /// See the API documentation for more details + /// + /// Required: Username + /// Required: The type of package + /// Optional: The visibility of the package + [ManualRoute("GET", "/users/{username}/packages")] + public Task> GetAllForUser(string username, PackageType packageType, PackageVisibility? packageVisibility) + { + Ensure.ArgumentNotNullOrEmptyString(username, nameof(username)); + Ensure.ArgumentNotNull(packageType, nameof(packageType)); + + return GetAllForUser(username, packageType, packageVisibility, ApiOptions.None); + } + /// /// Lists packages owned by the authenticated user within the user's namespace /// @@ -183,15 +346,18 @@ public Task RestoreForActiveUser(PackageType packageType, string packageName) /// Required: Username /// Required: The type of package /// Optional: The visibility of the package + /// Options for changing the API response [ManualRoute("GET", "/users/{username}/packages")] - public Task> GetAllForUser(string username, PackageType packageType, PackageVisibility? packageVisibility = null) + public Task> GetAllForUser(string username, PackageType packageType, PackageVisibility? packageVisibility, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(username, nameof(username)); + Ensure.ArgumentNotNull(packageType, nameof(packageType)); + Ensure.ArgumentNotNull(options, nameof(options)); var route = ApiUrls.PackagesUser(username); var parameters = ParameterBuilder.AddParameter("package_type", packageType).AddOptionalParameter("visibility", packageVisibility); - return ApiConnection.GetAll(route, parameters); + return ApiConnection.GetAll(route, parameters, options); } ///