mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-01 10:25:36 +00:00
Get the SHA-1 of a commit reference
Updated RepositoryCommitsClients and unit/integration tests
This commit is contained in:
@@ -87,6 +87,14 @@ public class RepositoryCommitsClientTests
|
||||
.Where(file => file.Status == "renamed")
|
||||
.All(file => string.IsNullOrEmpty(file.PreviousFileName) == false));
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task CanGetSha1()
|
||||
{
|
||||
var sha1 = await _fixture.Sha1("octokit", "octokit.net", "master");
|
||||
|
||||
Assert.NotNull(sha1);
|
||||
}
|
||||
}
|
||||
|
||||
public class TestsWithNewRepository : IDisposable
|
||||
|
||||
@@ -790,5 +790,35 @@ namespace Octokit.Tests.Clients
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.EditBranch("owner", "repo", "", update));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheSha1Method
|
||||
{
|
||||
[Fact]
|
||||
public async Task EnsureNonNullArguments()
|
||||
{
|
||||
var client = new RepositoryCommitsClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Sha1(null, "name", "reference"));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Sha1("", "name", "reference"));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Sha1("owner", null, "reference"));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Sha1("owner", "", "reference"));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Sha1("owner", "name", null));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Sha1("owner", "name", ""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoryCommitsClient(connection);
|
||||
|
||||
client.Sha1("owner", "name", "reference");
|
||||
|
||||
connection.Received()
|
||||
.Get<string>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/commits/reference"), null, AcceptHeaders.CommitReferenceSha1Preview);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,5 +50,14 @@ namespace Octokit
|
||||
/// <param name="request">Used to filter list of commits returned</param>
|
||||
/// <returns></returns>
|
||||
Task<IReadOnlyList<GitHubCommit>> GetAll(string owner, string name, CommitRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// Get the SHA-1 of a commit reference
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="reference">The repository reference</param>
|
||||
/// <returns></returns>
|
||||
Task<string> Sha1(string owner, string name, string reference);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,5 +79,21 @@ namespace Octokit
|
||||
return _apiConnection.GetAll<GitHubCommit>(ApiUrls.RepositoryCommits(owner, name),
|
||||
request.ToParametersDictionary());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the SHA-1 of a commit reference
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="reference">The repository reference</param>
|
||||
/// <returns></returns>
|
||||
public Task<string> Sha1(string owner, string name, string reference)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
|
||||
|
||||
return _apiConnection.Get<string>(ApiUrls.RepositoryCommit(owner, name, reference), null, AcceptHeaders.CommitReferenceSha1Preview);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user