diff --git a/Octokit.Tests/Clients/RepositoriesClientTests.cs b/Octokit.Tests/Clients/RepositoriesClientTests.cs index 37a1da54..87379473 100644 --- a/Octokit.Tests/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoriesClientTests.cs @@ -162,5 +162,32 @@ namespace Octokit.Tests.Clients await AssertEx.Throws(async () => await repositoriesClient.GetReleases("owner", null)); } } + + public class TheCreateReleaseMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var client = Substitute.For>(); + var repositoriesClient = new RepositoriesClient(client); + var data = new ReleaseUpdate("fake-tag"); + + repositoriesClient.CreateRelease("fake", "repo", data); + + client.Received().Create(Arg.Is(u => u.ToString() == "/repos/fake/repo/releases"), data); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var repositoriesClient = new RepositoriesClient(Substitute.For>()); + var data = new ReleaseUpdate("fake-tag"); + + Assert.Throws(() => new ReleaseUpdate(null)); + await AssertEx.Throws(async () => await repositoriesClient.CreateRelease(null, "name", data)); + await AssertEx.Throws(async () => await repositoriesClient.CreateRelease("owner", null, data)); + await AssertEx.Throws(async () => await repositoriesClient.CreateRelease("owner", "name", null)); + } + } } } diff --git a/Octokit/Clients/RepositoriesClient.cs b/Octokit/Clients/RepositoriesClient.cs index d3d3f768..a8353832 100644 --- a/Octokit/Clients/RepositoriesClient.cs +++ b/Octokit/Clients/RepositoriesClient.cs @@ -62,5 +62,16 @@ namespace Octokit.Clients var endpoint = "/repos/{0}/{1}/releases".FormatUri(owner, name); return await Client.GetAll(endpoint); } + + + public async Task 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(endpoint, data); + } } } diff --git a/Octokit/GitHubModels.cs b/Octokit/GitHubModels.cs index 4ac44070..29645349 100644 --- a/Octokit/GitHubModels.cs +++ b/Octokit/GitHubModels.cs @@ -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; } diff --git a/Octokit/Http/ApiConnection.cs b/Octokit/Http/ApiConnection.cs index 637cc894..ff1f22dc 100644 --- a/Octokit/Http/ApiConnection.cs +++ b/Octokit/Http/ApiConnection.cs @@ -71,6 +71,16 @@ namespace Octokit.Http return response.BodyAsObject; } + public async Task Create(Uri endpoint, object data) + { + Ensure.ArgumentNotNull(endpoint, "endpoint"); + Ensure.ArgumentNotNull(data, "data"); + + var response = await Connection.PostAsync(endpoint, data); + + return response.BodyAsObject; + } + public async Task Update(Uri endpoint, object data) { Ensure.ArgumentNotNull(endpoint, "endpoint"); diff --git a/Octokit/Http/IApiConnection.cs b/Octokit/Http/IApiConnection.cs index ad3decb4..b4389ac9 100644 --- a/Octokit/Http/IApiConnection.cs +++ b/Octokit/Http/IApiConnection.cs @@ -19,6 +19,7 @@ namespace Octokit.Http Task> GetAll(Uri endpoint, IDictionary parameters); Task> GetAll(Uri endpoint, IDictionary parameters); Task Create(Uri endpoint, object data); + Task Create(Uri endpoint, object data); Task Update(Uri endpoint, object data); Task Delete(Uri endpoint); } diff --git a/Octokit/IRepositoriesClient.cs b/Octokit/IRepositoriesClient.cs index efa70a67..fd26ae56 100644 --- a/Octokit/IRepositoriesClient.cs +++ b/Octokit/IRepositoriesClient.cs @@ -61,8 +61,17 @@ namespace Octokit /// Retrieves every for the specified repository. /// /// The owner of the repository. - /// The name of the reposiitory + /// The name of the repository. /// A of . Task> GetReleases(string owner, string name); + + /// + /// Create a for the specified repository. + /// + /// The owner of the repository. + /// The name of the repository. + /// The data for the release. + /// A new . + Task CreateRelease(string owner, string name, ReleaseUpdate data); } }