[FEAT]: Search based on repository custom property (#2936)

search based on repository custom property
This commit is contained in:
Colby Williams
2024-06-21 14:09:43 -05:00
committed by GitHub
parent 9a3177e385
commit 1053a2045d
3 changed files with 78 additions and 22 deletions

View File

@@ -738,6 +738,29 @@ namespace Octokit.Tests.Clients
Assert.Contains("topics:<=2", request.MergedQualifiers());
}
[Fact]
public void TestingTheCustomPropertiesQualifier()
{
var request = new SearchRepositoriesRequest("github");
request.CustomProperties = new Dictionary<string, string> { { "custom", "value" } };
Assert.Contains("props.custom:value", request.MergedQualifiers());
}
[Fact]
public void TestingMultipleCustomPropertiesQualifiers()
{
var request = new SearchRepositoriesRequest("github");
request.CustomProperties = new Dictionary<string, string> {
{ "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

View File

@@ -1,4 +1,4 @@
using System;
using System.Collections.Generic;
using Octokit;
using Octokit.Tests.Helpers;
using Xunit;
@@ -41,5 +41,13 @@ public class SearchRepositoryRequestTests
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<string, string> { { "name", "value" } } };
var result = request.MergedQualifiers();
Assert.Contains(result, x => string.Equals(x, "props.name:value"));
}
}
}

View File

@@ -10,7 +10,7 @@ namespace Octokit
{
/// <summary>
/// Searching Repositories
/// http://developer.github.com/v3/search/#search-repositories
/// https://docs.github.com/rest/search/search#search-repositories
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class SearchRepositoriesRequest : BaseSearchRequest
@@ -33,7 +33,7 @@ namespace Octokit
}
/// <summary>
/// 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.
/// </summary>
public RepoSearchSort? SortField { get; set; }
@@ -48,7 +48,7 @@ namespace Octokit
/// <summary>
/// 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
/// </summary>
public IEnumerable<InQualifier> In
{
@@ -65,74 +65,83 @@ namespace Octokit
/// <summary>
/// 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
/// </summary>
public Range Forks { get; set; }
/// <summary>
/// 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
/// </summary>
public ForkQualifier? Fork { get; set; }
/// <summary>
/// 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
/// </summary>
public Range Size { get; set; }
/// <summary>
/// Searches repositories based on the language theyre 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
/// </summary>
public Language? Language { get; set; }
/// <summary>
/// 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
/// </summary>
public Range Stars { get; set; }
/// <summary>
/// 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
/// </summary>
public string User { get; set; }
/// <summary>
/// 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
/// </summary>
public DateRange Created { get; set; }
/// <summary>
/// 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
/// </summary>
public DateRange Updated { get; set; }
/// <summary>
/// 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
/// </summary>
public RepoSearchLicense? License { get; set; }
/// <summary>
/// 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
/// </summary>
public bool? Archived { get; set; }
/// <summary>
/// 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
/// </summary>
public string Topic { get; set; }
/// <summary>
/// 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
/// </summary>
public Range Topics { get; set; }
/// <summary>
/// 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
/// </summary>
public IDictionary<string, string> CustomProperties { get; set; }
public override IReadOnlyList<string> MergedQualifiers()
{
var parameters = new List<string>();
@@ -200,6 +209,13 @@ namespace Octokit
{
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,7 +230,7 @@ namespace Octokit
}
/// <summary>
/// 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
/// 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.
/// </summary>
@@ -226,6 +242,9 @@ namespace Octokit
[Parameter(Value = "description")]
Description,
[Parameter(Value = "topics")]
Topics,
[Parameter(Value = "readme")]
Readme
}
@@ -323,7 +342,7 @@ namespace Octokit
/// <summary>
/// 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
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class DateRange
@@ -532,7 +551,7 @@ namespace Octokit
/// <summary>
/// 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
/// </summary>
public enum Language
{
@@ -897,7 +916,7 @@ namespace Octokit
/// <summary>
/// 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
/// </summary>
public enum RepoSearchLicense
{
@@ -989,7 +1008,8 @@ namespace Octokit
/// <summary>
/// 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
/// </summary>
public enum RepoSearchSort
{
@@ -1004,6 +1024,11 @@ namespace Octokit
[Parameter(Value = "forks")]
Forks,
/// <summary>
/// search by number of help-wanted-issues
/// </summary>
[Parameter(Value = "help-wanted-issues")]
HelpWantedIssues,
/// <summary>
/// search by last updated
/// </summary>
[Parameter(Value = "updated")]
@@ -1011,7 +1036,7 @@ namespace Octokit
}
/// <summary>
/// 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.
/// </summary>
public enum ForkQualifier