mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-03 11:05:56 +00:00
Create a new release.
This commit is contained in:
@@ -162,5 +162,32 @@ namespace Octokit.Tests.Clients
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await repositoriesClient.GetReleases("owner", null));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateReleaseMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var client = Substitute.For<IApiConnection<Repository>>();
|
||||
var repositoriesClient = new RepositoriesClient(client);
|
||||
var data = new ReleaseUpdate("fake-tag");
|
||||
|
||||
repositoriesClient.CreateRelease("fake", "repo", data);
|
||||
|
||||
client.Received().Create<Release>(Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/releases"), data);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresArgumentsNotNull()
|
||||
{
|
||||
var repositoriesClient = new RepositoriesClient(Substitute.For<IApiConnection<Repository>>());
|
||||
var data = new ReleaseUpdate("fake-tag");
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => new ReleaseUpdate(null));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await repositoriesClient.CreateRelease(null, "name", data));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await repositoriesClient.CreateRelease("owner", null, data));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await repositoriesClient.CreateRelease("owner", "name", null));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,5 +62,16 @@ namespace Octokit.Clients
|
||||
var endpoint = "/repos/{0}/{1}/releases".FormatUri(owner, name);
|
||||
return await Client.GetAll<Release, Repository>(endpoint);
|
||||
}
|
||||
|
||||
|
||||
public async Task<Release> CreateRelease(string owner, string name, ReleaseUpdate data)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "repository");
|
||||
Ensure.ArgumentNotNull(data, "data");
|
||||
|
||||
var endpoint = "/repos/{0}/{1}/releases".FormatUri(owner, name);
|
||||
return await Client.Create<Release>(endpoint, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+18
-1
@@ -462,7 +462,7 @@ namespace Octokit
|
||||
public string UploadUrl { get; set; }
|
||||
public int Id { get; set; }
|
||||
public string TagName { get; set; }
|
||||
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Commitish", Justification = "Spelling is correct")]
|
||||
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Commitish")]
|
||||
public string TargetCommitish { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Body { get; set; }
|
||||
@@ -472,6 +472,23 @@ namespace Octokit
|
||||
public DateTimeOffset PublishedAt { get; set; }
|
||||
}
|
||||
|
||||
public class ReleaseUpdate
|
||||
{
|
||||
public ReleaseUpdate(string tagName)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(tagName, "tagName");
|
||||
TagName = tagName;
|
||||
}
|
||||
|
||||
public string TagName { get; private set; }
|
||||
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Commitish")]
|
||||
public string TargetCommitish { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public bool Draft { get; set; }
|
||||
public bool Prerelease { get; set; }
|
||||
}
|
||||
|
||||
public class ApiError
|
||||
{
|
||||
public string Message { get; set; }
|
||||
|
||||
@@ -71,6 +71,16 @@ namespace Octokit.Http
|
||||
return response.BodyAsObject;
|
||||
}
|
||||
|
||||
public async Task<TOther> Create<TOther>(Uri endpoint, object data)
|
||||
{
|
||||
Ensure.ArgumentNotNull(endpoint, "endpoint");
|
||||
Ensure.ArgumentNotNull(data, "data");
|
||||
|
||||
var response = await Connection.PostAsync<TOther>(endpoint, data);
|
||||
|
||||
return response.BodyAsObject;
|
||||
}
|
||||
|
||||
public async Task<T> Update(Uri endpoint, object data)
|
||||
{
|
||||
Ensure.ArgumentNotNull(endpoint, "endpoint");
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace Octokit.Http
|
||||
Task<IReadOnlyCollection<T>> GetAll(Uri endpoint, IDictionary<string, string> parameters);
|
||||
Task<IReadOnlyCollection<TOther>> GetAll<TOther>(Uri endpoint, IDictionary<string, string> parameters);
|
||||
Task<T> Create(Uri endpoint, object data);
|
||||
Task<TOther> Create<TOther>(Uri endpoint, object data);
|
||||
Task<T> Update(Uri endpoint, object data);
|
||||
Task Delete(Uri endpoint);
|
||||
}
|
||||
|
||||
@@ -61,8 +61,17 @@ namespace Octokit
|
||||
/// Retrieves every <see cref="Release"/> for the specified repository.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository.</param>
|
||||
/// <param name="name">The name of the reposiitory</param>
|
||||
/// <param name="name">The name of the repository.</param>
|
||||
/// <returns>A <see cref="IReadonlyPagedCollection{Release}"/> of <see cref="Release"/>.</returns>
|
||||
Task<IReadOnlyCollection<Release>> GetReleases(string owner, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Create a <see cref="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="data">The data for the release.</param>
|
||||
/// <returns>A new <see cref="Release"/>.</returns>
|
||||
Task<Release> CreateRelease(string owner, string name, ReleaseUpdate data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user