Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add license to repository search #2258

Merged
merged 2 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Octokit.Tests/Models/SearchRepositoryRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,13 @@ public void LanguageUsesParameterTranslation()
var result = request.MergedQualifiers();
Assert.Contains(result, x => string.Equals(x, "language:\"cpp\""));
}

[Fact]
public void LicenseUsesParameterTranslation()
{
var request = new SearchRepositoriesRequest() { License = RepoSearchLicense.Apache_2_0 };
var result = request.MergedQualifiers();
Assert.Contains(result, x => string.Equals(x, "license:apache-2.0"));
}
}
}
105 changes: 104 additions & 1 deletion Octokit/Models/Request/SearchRepositoriesRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ public IEnumerable<InQualifier> In
/// </summary>
public DateRange Updated { get; set; }

/// <summary>
/// Filters repositories based on license
/// https://help.github.com/articles/searching-repositories#search-by-license
/// </summary>
public RepoSearchLicense? License { get; set; }

/// <summary>
/// Filters whether archived repositories should be included (true) or not (false).
/// </summary>
Expand Down Expand Up @@ -171,6 +177,11 @@ public override IReadOnlyList<string> MergedQualifiers()
parameters.Add(string.Format(CultureInfo.InvariantCulture, "archived:{0}", Archived.ToString().ToLower()));
}

if (License != null)
{
parameters.Add(string.Format(CultureInfo.InvariantCulture, "license:{0}", License.ToParameter()));
}

return parameters;
}

Expand Down Expand Up @@ -501,7 +512,7 @@ public override string ToString()
}

/// <summary>
/// lanuages that can be searched on in github
/// Languages that can be searched on in GitHub
/// https://help.github.com/articles/searching-repositories#languages
/// </summary>
public enum Language
Expand Down Expand Up @@ -863,6 +874,98 @@ public enum Language
#pragma warning restore 1591
}

/// <summary>
/// Licenses than can be searched on GitHub
/// https://help.github.com/articles/searching-repositories#search-by-license
/// </summary>
public enum RepoSearchLicense
{
[Parameter(Value = "afl-3.0")]
AcademicFree_3_0,
[Parameter(Value = "apache-2.0")]
Apache_2_0,
[Parameter(Value = "artistic-2.0")]
Artistic_2_0,
[Parameter(Value = "bsl-1.0")]
BoostSoftware_1_0,
[Parameter(Value = "0bsd")]
BSD0Clause,
[Parameter(Value = "bsd-2-clause")]
BSD2Clause,
[Parameter(Value = "bsd-3-clause")]
BSD3Clause,
[Parameter(Value = "bsd-3-clause-clear")]
BSD3ClauseClear,
[Parameter(Value = "bsd-4-clause")]
BSD4Clause,
[Parameter(Value = "cc")]
CreativeCommons,
[Parameter(Value = "cc0-1.0")]
CreativeCommonsZero_1_0,
[Parameter(Value = "cc-by-4.0")]
CreativeCommonsAtrribution_4_0,
[Parameter(Value = "cc-by-sa-4.0")]
CreativeCommonsAttributionShareAlike_4_0,
[Parameter(Value = "cecill-2.1")]
CeCILL_2_1,
[Parameter(Value = "wtfpl")]
DoWhatTheFYouWant,
[Parameter(Value = "ecl-2.0")]
EducationalCommunity_2_0,
[Parameter(Value = "epl-1.0")]
EclipsePublic_1_0,
[Parameter(Value = "epl-2.0")]
EclipsePublic_2_0,
[Parameter(Value = "eupl-1.1")]
EuropeanUnionPublic_1_1,
[Parameter(Value = "eupl-1.2")]
EuropeanUnionPublic_1_2,
[Parameter(Value = "agpl-3.0")]
GNUAfferoGeneralPublic_3_0,
[Parameter(Value = "gpl")]
GNUGeneralPublic,
[Parameter(Value = "gpl-2.0")]
GNUGeneralPublic_2_0,
[Parameter(Value = "gpl-3.0")]
GNUGeneralPublic_3_0,
[Parameter(Value = "lgpl")]
GNULesserGeneralPublic,
[Parameter(Value = "lgpl-2.1")]
GNULesserGeneralPublic_2_1,
[Parameter(Value = "lgpl-3.0")]
GNULesserGeneralPublic_3_0,
[Parameter(Value = "isc")]
ISC,
[Parameter(Value = "lppl-1.3c")]
LatexProjectPublic,
[Parameter(Value = "ms-pl")]
MicrosoftPublic,
[Parameter(Value = "ms-rl")]
MicrosoftReciprocal,
[Parameter(Value = "mit")]
MIT,
[Parameter(Value = "mpl-2.0")]
MozillaPublic_2_0,
[Parameter(Value = "odbl-1.0")]
ODCOpenDatabase,
[Parameter(Value = "osl-3.0")]
OpenSoftware_3_0,
[Parameter(Value = "postgresql")]
PostgreseSQL,
[Parameter(Value = "ofl-1.1")]
SILOpenFont,
[Parameter(Value = "upl-1.0")]
UniversalPermissive,
[Parameter(Value = "ncsa")]
NSCAOpenSource,
[Parameter(Value = "unlicense")]
TheUnlicense,
[Parameter(Value = "vim")]
Vim,
[Parameter(Value = "zlib")]
ZLib
}

/// <summary>
/// sorting repositories by any of below
/// https://help.github.com/articles/searching-repositories#sorting
Expand Down