mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-05-31 02:05:39 +00:00
Add TagsClient create method
This commit is contained in:
@@ -18,7 +18,7 @@ public class TagsClientTests
|
||||
|
||||
client.Get("owner", "repo", "reference");
|
||||
|
||||
connection.Received().Get<Tag>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/tags/reference"), null);
|
||||
connection.Received().Get<Tag>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/git/tags/reference"), null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -26,12 +26,39 @@ public class TagsClientTests
|
||||
{
|
||||
var client = new TagsClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get(null, "name", "sha"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get("owner", null, "sha"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get(null, "name", "reference"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get("owner", null, "reference"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get("owner", "name", null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Get(null, "", null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Get("", null, null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Get(null, null, ""));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Get("", "name", "reference"));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Get("owner", "", "reference"));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Get("owner", "name", ""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateMethod
|
||||
{
|
||||
[Fact]
|
||||
public void PostsToTheCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new TagsClient(connection);
|
||||
|
||||
client.Create("owner", "repo", new NewTag{Type = NewTagType.Tree});
|
||||
|
||||
connection.Received().Post<Tag>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/git/tags"),
|
||||
Arg.Is<NewTag>(nt => nt.Type == NewTagType.Tree));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new TagsClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Create(null, "name", new NewTag()));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Create("owner", null, new NewTag()));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Create("owner", "name", null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Create("", "name", new NewTag()));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Create("owner", "", new NewTag()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Octokit
|
||||
public interface ITagsClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a tag for a given repository by sha
|
||||
/// Gets a tag for a given repository by sha reference
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/git/tags/#get-a-tag
|
||||
@@ -18,5 +18,17 @@ namespace Octokit
|
||||
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get",
|
||||
Justification = "Method makes a network request")]
|
||||
Task<Tag> Get(string owner, string name, string reference);
|
||||
|
||||
/// <summary>
|
||||
/// Create a tag for a given repository
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/git/tags/#create-a-tag-object
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="tag">The tag to create</param>
|
||||
/// <returns></returns>
|
||||
Task<Tag> Create(string owner, string name, NewTag tag);
|
||||
}
|
||||
}
|
||||
@@ -13,9 +13,18 @@ namespace Octokit
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(reference, "sha");
|
||||
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
|
||||
|
||||
return ApiConnection.Get<Tag>(ApiUrls.Tag(owner, name, reference));
|
||||
}
|
||||
|
||||
public Task<Tag> Create(string owner, string name, NewTag tag)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNull(tag, "tag");
|
||||
|
||||
return ApiConnection.Post<Tag>(ApiUrls.CreateTag(owner, name), tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -256,7 +256,18 @@ namespace Octokit
|
||||
/// <returns></returns>
|
||||
public static Uri Tag(string owner, string name, string reference)
|
||||
{
|
||||
return "repos/{0}/{1}/tags/{2}".FormatUri(owner, name, reference);
|
||||
return "repos/{0}/{1}/git/tags/{2}".FormatUri(owner, name, reference);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> for creating a tag object.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <returns></returns>
|
||||
public static Uri CreateTag(string owner, string name)
|
||||
{
|
||||
return "repos/{0}/{1}/git/tags".FormatUri(owner, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,4 +12,24 @@ namespace Octokit
|
||||
public Tagger Tagger { get; set; }
|
||||
public TagObject Object { get; set; }
|
||||
}
|
||||
|
||||
public class NewTag
|
||||
{
|
||||
[DataMember(Name = "tag")]
|
||||
public string Name { get; set; }
|
||||
public string Message { get; set; }
|
||||
public string Object { get; set; }
|
||||
public NewTagType Type { get; set; }
|
||||
public Tagger Tagger { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents the type of object being tagged
|
||||
/// </summary>
|
||||
public enum NewTagType
|
||||
{
|
||||
Commit,
|
||||
Blob,
|
||||
Tree
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user