Skip to content

Commit

Permalink
Implement GetLicenseContents() method for getting repository's licens…
Browse files Browse the repository at this point in the history
…e info
  • Loading branch information
jozefizso committed Nov 14, 2017
1 parent b6e80e8 commit 16f6eec
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Octokit.Reactive/Clients/IObservableRepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,27 @@ public interface IObservableRepositoriesClient
/// <returns>All of the repositories tags.</returns>
IObservable<RepositoryTag> GetAllTags(long repositoryId, ApiOptions options);

/// <summary>
/// Get the contents of a repository's license
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/licenses/#get-the-contents-of-a-repositorys-license">API documentation</a> for more details
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns>Returns the contents of the repository's license file, if one is detected.</returns>
IObservable<RepositoryLicense> GetLicenseContents(string owner, string name);

/// <summary>
/// Get the contents of a repository's license
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/licenses/#get-the-contents-of-a-repositorys-license">API documentation</a> for more details
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <returns>Returns the contents of the repository's license file, if one is detected.</returns>
IObservable<RepositoryLicense> GetLicenseContents(long repositoryId);

/// <summary>
/// Updates the specified repository with the values given in <paramref name="update"/>
/// </summary>
Expand Down
30 changes: 30 additions & 0 deletions Octokit.Reactive/Clients/ObservableRepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,36 @@ public IObservable<Repository> Edit(string owner, string name, RepositoryUpdate
return _client.Edit(owner, name, update).ToObservable();
}

/// <summary>
/// Get the contents of a repository's license
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/licenses/#get-the-contents-of-a-repositorys-license">API documentation</a> for more details
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns>Returns the contents of the repository's license file, if one is detected.</returns>
public IObservable<RepositoryLicense> GetLicenseContents(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");

return _client.GetLicenseContents(owner, name).ToObservable();
}

/// <summary>
/// Get the contents of a repository's license
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/licenses/#get-the-contents-of-a-repositorys-license">API documentation</a> for more details
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <returns>Returns the contents of the repository's license file, if one is detected.</returns>
public IObservable<RepositoryLicense> GetLicenseContents(long repositoryId)
{
return _client.GetLicenseContents(repositoryId).ToObservable();
}

/// <summary>
/// Updates the specified repository with the values given in <paramref name="update"/>
/// </summary>
Expand Down
21 changes: 21 additions & 0 deletions Octokit/Clients/IRepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,27 @@ public interface IRepositoriesClient
/// <returns>All of the repositories tags.</returns>
Task<IReadOnlyList<RepositoryTag>> GetAllTags(long repositoryId, ApiOptions options);

/// <summary>
/// Get the contents of a repository's license
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/licenses/#get-the-contents-of-a-repositorys-license">API documentation</a> for more details
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns>Returns the contents of the repository's license file, if one is detected.</returns>
Task<RepositoryLicense> GetLicenseContents(string owner, string name);

/// <summary>
/// Get the contents of a repository's license
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/licenses/#get-the-contents-of-a-repositorys-license">API documentation</a> for more details
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <returns>Returns the contents of the repository's license file, if one is detected.</returns>
Task<RepositoryLicense> GetLicenseContents(long repositoryId);

/// <summary>
/// Updates the specified repository with the values given in <paramref name="update"/>
/// </summary>
Expand Down
31 changes: 31 additions & 0 deletions Octokit/Clients/RepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,37 @@ public Task<IReadOnlyList<RepositoryTag>> GetAllTags(long repositoryId, ApiOptio
return ApiConnection.GetAll<RepositoryTag>(ApiUrls.RepositoryTags(repositoryId), options);
}

/// <summary>
/// Get the contents of a repository's license
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/licenses/#get-the-contents-of-a-repositorys-license">API documentation</a> for more details
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns>Returns the contents of the repository's license file, if one is detected.</returns>
public Task<RepositoryLicense> GetLicenseContents(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");

return ApiConnection.Get<RepositoryLicense>(ApiUrls.RepositoryLicense(owner, name), null, AcceptHeaders.LicensesApiPreview);

}

/// <summary>
/// Get the contents of a repository's license
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/licenses/#get-the-contents-of-a-repositorys-license">API documentation</a> for more details
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <returns>Returns the contents of the repository's license file, if one is detected.</returns>
public Task<RepositoryLicense> GetLicenseContents(long repositoryId)
{
return ApiConnection.Get<RepositoryLicense>(ApiUrls.RepositoryLicense(repositoryId), null, AcceptHeaders.LicensesApiPreview);
}

/// <summary>
/// A client for GitHub's Repository Pages API.
/// </summary>
Expand Down
21 changes: 21 additions & 0 deletions Octokit/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3699,5 +3699,26 @@ public static Uri ProjectCardMove(int id)
{
return "projects/columns/cards/{0}/moves".FormatUri(id);
}

/// <summary>
/// Returns the <see cref="Uri"/> for repository's license requests.
/// </summary>
/// <param name="owner">The owner of repo</param>
/// <param name="repo">The name of repo</param>
/// <returns>The <see cref="Uri"/> for repository's license requests.</returns>
public static Uri RepositoryLicense(string owner, string repo)
{
return "repos/{0}/{1}/license".FormatUri(owner, repo);
}

/// <summary>
/// Returns the <see cref="Uri"/> for repository's license requests.
/// </summary>
/// <param name="repositoryId">The id of the repository</param>
/// <returns>The <see cref="Uri"/> for repository's license requests.</returns>
public static Uri RepositoryLicense(long repositoryId)
{
return "repositories/{0}/license".FormatUri(repositoryId);
}
}
}
44 changes: 44 additions & 0 deletions Octokit/Models/Response/RepositoryLicense.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Diagnostics;
using System.Globalization;

namespace Octokit
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class RepositoryLicense : LicenseMetadata
{
public RepositoryLicense(
string key,
string name,
string spdxId,
string url,
bool featured) : base(key, name, url)
{
Ensure.ArgumentNotNull(spdxId, "spdxId");

SpdxId = spdxId;
Featured = featured;
}

public RepositoryLicense()
{
}

/// <summary>
/// SPDX license identifier.
/// </summary>
public string SpdxId { get; protected set; }

/// <summary>
/// Whether the license is one of the licenses featured on https://choosealicense.com
/// </summary>
public bool Featured { get; protected set; }

internal override string DebuggerDisplay
{
get
{
return string.Format(CultureInfo.InvariantCulture, "{0} Featured: {1}", base.DebuggerDisplay, Featured);
}
}
}
}

0 comments on commit 16f6eec

Please sign in to comment.