Implement missing functions in Repo Releases API

This commit is contained in:
Henrik Andersson
2014-01-27 22:23:51 +10:00
parent 690dc540ab
commit 77f70f75bb
9 changed files with 271 additions and 1 deletions
+73
View File
@@ -2,6 +2,7 @@
using System.Collections.Generic;
#endif
using System.Threading.Tasks;
using System.Diagnostics.CodeAnalysis;
namespace Octokit
{
@@ -25,6 +26,17 @@ namespace Octokit
/// <returns>The list of <see cref="Release"/>s for the specified repository.</returns>
Task<IReadOnlyList<Release>> GetAll(string owner, string name);
/// <summary>
/// Gets a single <see cref="Release"/> for the specified repository.
/// </summary>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="number">The id of the release</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>The <see cref="Release"/> specified by the id</returns>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
Task<Release> Get(string owner, string name, int number);
/// <summary>
/// Creates a new <see cref="Release"/> for the specified repository.
/// </summary>
@@ -38,6 +50,36 @@ namespace Octokit
/// <returns>The created <see cref="Release"/>.</returns>
Task<Release> CreateRelease(string owner, string name, ReleaseUpdate data);
/// <summary>
/// Edits an existing <see cref="Release"/> for the specified repository.
/// </summary>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="data">A description of the release to edit</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>The updated <see cref="Release"/>.</returns>
Task<Release> EditRelease(string owner, string name, ReleaseUpdate data);
/// <summary>
/// Deletes an existing <see cref="Release"/> for the specified repository.
/// </summary>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="number">The id of the release to delete</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns></returns>
Task DeleteRelease(string owner, string name, int number);
/// <summary>
/// Gets all <see cref="ReleaseAsset"/> for the specified release of the specified repository.
/// </summary>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="number">The id of the <see cref="Release"/>.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>The list of <see cref="ReleaseAsset"/> for the specified release of the specified repository.</returns>
Task<IReadOnlyList<ReleaseAsset>> GetAssets(string owner, string name, int number);
/// <summary>
/// Uploads a <see cref="ReleaseAsset"/> for the specified release.
/// </summary>
@@ -49,5 +91,36 @@ namespace Octokit
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>The created <see cref="ReleaseAsset"/>.</returns>
Task<ReleaseAsset> UploadAsset(Release release, ReleaseAssetUpload data);
/// <summary>
/// Gets the specified <see cref="ReleaseAsset"/> for the specified release of the specified repository.
/// </summary>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="releaseId">The id of the <see cref="Release"/></param>
/// <param name="assetId">The id of the <see cref="ReleaseAsset"/></param>
/// <returns>The <see cref="ReleaseAsset"/> specified by the asset id.</returns>
Task<ReleaseAsset> GetAsset(string owner, string name, int releaseId, int assetId);
/// <summary>
/// Edits the <see cref="ReleaseAsset"/> for the specified release of the specified repository.
/// </summary>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="releaseId">The id of the <see cref="Release"/></param>
/// <param name="assetId">The id of the <see cref="ReleaseAsset"/></param>
/// <param name="data">Description of the asset with its amended data</param>
/// <returns>The edited <see cref="ReleaseAsset"/>.</returns>
Task<ReleaseAsset> EditAsset(string owner, string name, int releaseId, int assetId, ReleaseAssetUpdate data);
/// <summary>
/// Deletes the specified <see cref="ReleaseAsset"/> from the specified repository
/// </summary>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="number">The id of the <see cref="ReleaseAsset"/>.</param>
/// <returns></returns>
Task DeleteAsset(string owner, string name, int number);
}
}
+131 -1
View File
@@ -40,6 +40,24 @@ namespace Octokit
return ApiConnection.GetAll<Release>(endpoint, null, "application/vnd.github.v3");
}
/// <summary>
/// Gets a single <see cref="Release"/> for the specified repository.
/// </summary>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="number">The id of the release</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>The <see cref="Release"/> specified by the id</returns>
public Task<Release> Get(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(number, "number");
var endpoint = ApiUrls.Releases(owner, name, number);
return ApiConnection.Get<Release>(endpoint);
}
/// <summary>
/// Creates a new <see cref="Release"/> for the specified repository.
/// </summary>
@@ -61,6 +79,60 @@ namespace Octokit
return ApiConnection.Post<Release>(endpoint, data, "application/vnd.github.v3");
}
/// <summary>
/// Edits an existing <see cref="Release"/> for the specified repository.
/// </summary>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="data">A description of the release to edit</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>The updated <see cref="Release"/>.</returns>
public Task<Release> EditRelease(string owner, string name, ReleaseUpdate data)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(data, "data");
var endpoint = ApiUrls.Releases(owner, name);
return ApiConnection.Patch<Release>(endpoint, data);
}
/// <summary>
/// Deletes an existing <see cref="Release"/> for the specified repository.
/// </summary>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="number">The id of the release to delete</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns></returns>
public Task DeleteRelease(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(number, "number");
var endpoint = ApiUrls.Releases(owner, name, number);
return ApiConnection.Delete(endpoint);
}
/// <summary>
/// Gets all <see cref="ReleaseAsset"/> for the specified release of the specified repository.
/// </summary>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="number">The id of the <see cref="Release"/>.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>The list of <see cref="ReleaseAsset"/> for the specified release of the specified repository.</returns>
public Task<IReadOnlyList<ReleaseAsset>> GetAssets(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(number, "number");
var endpoint = ApiUrls.ReleaseAssets(owner, name, number);
return ApiConnection.GetAll<ReleaseAsset>(endpoint, null, "application/vnd.github.v3");
}
/// <summary>
/// Uploads a <see cref="ReleaseAsset"/> for the specified release.
/// </summary>
@@ -76,12 +148,70 @@ namespace Octokit
Ensure.ArgumentNotNull(release, "release");
Ensure.ArgumentNotNull(data, "data");
var endpoint = release.UploadUrl.ExpandUriTemplate(new {name = data.FileName});
var endpoint = release.UploadUrl.ExpandUriTemplate(new { name = data.FileName });
return ApiConnection.Post<ReleaseAsset>(
endpoint,
data.RawData,
"application/vnd.github.v3",
data.ContentType);
}
/// <summary>
/// Gets the specified <see cref="ReleaseAsset"/> for the specified release of the specified repository.
/// </summary>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="releaseId">The id of the <see cref="Release"/></param>
/// <param name="assetId">The id of the <see cref="ReleaseAsset"/></param>
/// <returns>The <see cref="ReleaseAsset"/> specified by the asset id.</returns>
public Task<ReleaseAsset> GetAsset(string owner, string name, int releaseId, int assetId)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(releaseId, "releaseId");
Ensure.ArgumentNotNull(assetId, "assetId");
var endpoint = ApiUrls.ReleaseAssets(owner, name, releaseId, assetId);
return ApiConnection.Get<ReleaseAsset>(endpoint);
}
/// <summary>
/// Edits the <see cref="ReleaseAsset"/> for the specified release of the specified repository.
/// </summary>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="releaseId">The id of the <see cref="Release"/></param>
/// <param name="assetId">The id of the <see cref="ReleaseAsset"/></param>
/// <param name="data">Description of the asset with its amended data</param>
/// <returns>The edited <see cref="ReleaseAsset"/>.</returns>
public Task<ReleaseAsset> EditAsset(string owner, string name, int releaseId, int assetId, ReleaseAssetUpdate data)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(releaseId, "releaseId");
Ensure.ArgumentNotNull(assetId, "assetId");
Ensure.ArgumentNotNull(data, "data");
Ensure.ArgumentNotNullOrEmptyString(data.Name, "data.Name");
var endpoint = ApiUrls.ReleaseAssets(owner, name, releaseId, assetId);
return ApiConnection.Patch<ReleaseAsset>(endpoint, data);
}
/// <summary>
/// Deletes the specified <see cref="ReleaseAsset"/> from the specified repository
/// </summary>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="number">The id of the <see cref="ReleaseAsset"/>.</param>
/// <returns></returns>
public Task DeleteAsset(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(number, "number");
var endpoint = ApiUrls.Assets(owner, name, number);
return ApiConnection.Delete(endpoint);
}
}
}
+49
View File
@@ -107,6 +107,55 @@ namespace Octokit
return "repos/{0}/{1}/releases".FormatUri(owner, name);
}
/// <summary>
/// Returns the <see cref="Uri"/> that returns a single release for the specified repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The id of the release</param>
/// <returns></returns>
public static Uri Releases(string owner, string name, int number)
{
return "repos/{0}/{1}/releases/{2}".FormatUri(owner, name, number);
}
/// <summary>
/// Returns the <see cref="Uri"/> that returns all the assets for the specified release for the specified repository.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The id of the release</param>
/// <returns></returns>
public static Uri ReleaseAssets(string owner, string name, int number)
{
return "repos/{0}/{1}/releases/{2}/assets".FormatUri(owner, name, number);
}
/// <summary>
/// Returns the <see cref="Uri"/> that returns a single asset for the specified release for the specified repository.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="releaseId">The id of the release</param>
/// <param name="assetId">The id of the release asset</param>
/// <returns></returns>
public static Uri ReleaseAssets(string owner, string name, int releaseId, int assetId)
{
return "repos/{0}/{1}/releases/{2}/assets/{3}".FormatUri(owner, name, releaseId, assetId);
}
/// <summary>
/// Returns the <see cref="Uri"/> that returns all the assets for the specified repository.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The id of the release asset</param>
/// <returns></returns>
public static Uri Assets(string owner, string name, int number)
{
return "repos/{0}/{1}/releases/assets/{2}".FormatUri(owner, name, number);
}
/// <summary>
/// Returns the <see cref="Uri"/> that returns all of the authorizations for the currently logged in user.
/// </summary>
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Octokit
{
public class ReleaseAssetUpdate
{
public string Name { get; set; }
public string Label { get; set; }
}
}
+1
View File
@@ -255,6 +255,7 @@
<Compile Include="Models\Response\Emoji.cs" />
<Compile Include="Clients\FollowersClient.cs" />
<Compile Include="Clients\IFollowersClient.cs" />
<Compile Include="Models\Request\ReleaseAssetUpdate.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
+1
View File
@@ -265,6 +265,7 @@
<Compile Include="Models\Response\Emoji.cs" />
<Compile Include="Clients\FollowersClient.cs" />
<Compile Include="Clients\IFollowersClient.cs" />
<Compile Include="Models\Request\ReleaseAssetUpdate.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
</Project>
+1
View File
@@ -260,6 +260,7 @@
<Compile Include="Models\Response\Emoji.cs" />
<Compile Include="Clients\FollowersClient.cs" />
<Compile Include="Clients\IFollowersClient.cs" />
<Compile Include="Models\Request\ReleaseAssetUpdate.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
+1
View File
@@ -181,6 +181,7 @@
<Compile Include="Models\Request\NewTeam.cs" />
<Compile Include="Models\Request\Permission.cs" />
<Compile Include="Models\Request\ReferenceUpdate.cs" />
<Compile Include="Models\Request\ReleaseAssetUpdate.cs" />
<Compile Include="Models\Request\ReleaseUpdate.cs" />
<Compile Include="Models\Request\RepositoryIssueRequest.cs" />
<Compile Include="Models\Request\RequestParameters.cs" />
+1
View File
@@ -55,6 +55,7 @@
</Compile>
<Compile Include="Clients\ActivitiesClient.cs" />
<Compile Include="Clients\IWatchedClient.cs" />
<Compile Include="Models\Request\ReleaseAssetUpdate.cs" />
<Compile Include="Clients\SearchClient.cs" />
<Compile Include="Clients\ISearchClient.cs" />
<Compile Include="Clients\WatchedClient.cs" />