Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Octokit.Reactive/Clients/IObservableRepositoryCommitsClients.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ public interface IObservableRepositoryCommitsClient
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "base")]
IObservable<CompareResult> Compare(long repositoryId, string @base, string head);

/// <summary>
/// Compare two references in a repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="base">The reference to use as the base commit</param>
/// <param name="head">The reference to use as the head commit</param>
/// <param name="options">Options for changing the API response</param>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "base")]
IObservable<CompareResult> Compare(string owner, string name, string @base, string head, ApiOptions options);

/// <summary>
/// Compare two references in a repository
/// </summary>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="base">The reference to use as the base commit</param>
/// <param name="head">The reference to use as the head commit</param>
/// <param name="options">Options for changing the API response</param>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "base")]
IObservable<CompareResult> Compare(long repositoryId, string @base, string head, ApiOptions options);

/// <summary>
/// Gets all commits for a given repository
/// </summary>
Expand Down
35 changes: 35 additions & 0 deletions Octokit.Reactive/Clients/ObservableRepositoryCommitsClients.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,41 @@ public IObservable<CompareResult> Compare(long repositoryId, string @base, strin
return _commit.Compare(repositoryId, @base, head).ToObservable();
}

/// <summary>
/// Compare two references in a repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="base">The reference to use as the base commit</param>
/// <param name="head">The reference to use as the head commit</param>
/// <param name="options">Options for changing the API response</param>
public IObservable<CompareResult> Compare(string owner, string name, string @base, string head, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(@base, "base");
Ensure.ArgumentNotNullOrEmptyString(head, nameof(head));
Ensure.ArgumentNotNull(options, nameof(options));

return _commit.Compare(owner, name, @base, head, options).ToObservable();
}

/// <summary>
/// Compare two references in a repository
/// </summary>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="base">The reference to use as the base commit</param>
/// <param name="head">The reference to use as the head commit</param>
/// <param name="options">Options for changing the API response</param>
public IObservable<CompareResult> Compare(long repositoryId, string @base, string head, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(@base, "base");
Ensure.ArgumentNotNullOrEmptyString(head, nameof(head));
Ensure.ArgumentNotNull(options, nameof(options));

return _commit.Compare(repositoryId, @base, head, options).ToObservable();
}

/// <summary>
/// Gets all commits for a given repository
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,28 @@ public async Task CanGetSha1WithRepositoryId()

Assert.NotNull(sha1);
}

[IntegrationTest]
public async Task CanFetchAllCommitsInComparision()
{
const string @base = "8dcb1db0da7c86596bf1d63631bd335363c64b8c";
const string head = "7349ecd6685c370ba84eb13f4c39f75f33";

var compareResultWithoutOptions = await _fixture.Compare(octokitNetRepositoryId, @base, head);
Assert.Equal(250, compareResultWithoutOptions.Commits.Count);

var compareResult = await _fixture.Compare(octokitNetRepositoryId, @base, head, new ApiOptions { PageSize = 100 });
Assert.Equal(534, compareResult.Commits.Count);
}

[IntegrationTest]
public async Task CanCompareTheSameCommitWithApiOptions()
{
const string head = "7349ecd6685c370ba84eb13f4c39f75f33";

var compareResult = await _fixture.Compare(octokitNetRepositoryId, head, head, new ApiOptions { PageSize = 100 });
Assert.Equal(0, compareResult.Commits.Count);
}
}

public class TestsWithNewRepository : IDisposable
Expand Down Expand Up @@ -503,4 +525,4 @@ public void Dispose()
_context.Dispose();
}
}
}
}
17 changes: 17 additions & 0 deletions Octokit.Tests/Clients/RepositoriesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,23 @@ public async Task EnsureNonNullArguments()

await Assert.ThrowsAsync<ArgumentNullException>(() => client.Compare("owner", "repo", "base", null));
await Assert.ThrowsAsync<ArgumentException>(() => client.Compare("owner", "repo", "base", ""));


var options = new ApiOptions();
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Compare(null, "repo", "base", "head", options));
await Assert.ThrowsAsync<ArgumentException>(() => client.Compare("", "repo", "base", "head", options));

await Assert.ThrowsAsync<ArgumentNullException>(() => client.Compare("owner", null, "base", "head", options));
await Assert.ThrowsAsync<ArgumentException>(() => client.Compare("owner", "", "base", "head", options));

await Assert.ThrowsAsync<ArgumentNullException>(() => client.Compare("owner", "repo", null, "head", options));
await Assert.ThrowsAsync<ArgumentException>(() => client.Compare("owner", "repo", "", "head", options));

await Assert.ThrowsAsync<ArgumentNullException>(() => client.Compare("owner", "repo", "base", null, options));
await Assert.ThrowsAsync<ArgumentException>(() => client.Compare("owner", "repo", "base", "", options));

await Assert.ThrowsAsync<ArgumentNullException>(() => client.Compare("owner", "repo", "base", "head", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Compare("owner", "repo", "base", "head", null));
}

[Fact]
Expand Down
21 changes: 21 additions & 0 deletions Octokit/Clients/IRepositoryCommitsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ public interface IRepositoryCommitsClient
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "base")]
Task<CompareResult> Compare(long repositoryId, string @base, string head);

/// <summary>
/// Compare two references in a repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="base">The reference to use as the base commit</param>
/// <param name="head">The reference to use as the head commit</param>
/// <param name="options">Options for changing the API response</param>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "base")]
Task<CompareResult> Compare(string owner, string name, string @base, string head, ApiOptions options);

/// <summary>
/// Compare two references in a repository
/// </summary>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="base">The reference to use as the base commit</param>
/// <param name="head">The reference to use as the head commit</param>
/// <param name="options">Options for changing the API response</param>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "base")]
Task<CompareResult> Compare(long repositoryId, string @base, string head, ApiOptions options);

/// <summary>
/// Gets a single commit for a given repository
/// </summary>
Expand Down
72 changes: 71 additions & 1 deletion Octokit/Clients/RepositoryCommitsClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Octokit
Expand Down Expand Up @@ -105,6 +107,74 @@ public Task<CompareResult> Compare(long repositoryId, string @base, string head)
return ApiConnection.Get<CompareResult>(ApiUrls.RepoCompare(repositoryId, @base, head));
}

/// <summary>
/// Compare two references in a repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="base">The reference to use as the base commit</param>
/// <param name="head">The reference to use as the head commit</param>
/// <param name="options">Options for changing the API response</param>
[ManualRoute("GET", "/repos/{owner}/{repo}/compare/{base}...{head}")]
public Task<CompareResult> Compare(string owner, string name, string @base, string head, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(@base, nameof(@base));
Ensure.ArgumentNotNullOrEmptyString(head, nameof(head));
Ensure.ArgumentNotNull(options, nameof(options));

return Compare(ApiUrls.RepoCompare(owner, name, @base, head), options);
}

/// <summary>
/// Compare two references in a repository
/// </summary>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="base">The reference to use as the base commit</param>
/// <param name="head">The reference to use as the head commit</param>
/// <param name="options">Options for changing the API response</param>
[ManualRoute("GET", "/repositories/{id}/compare/{base}...{head}")]
public Task<CompareResult> Compare(long repositoryId, string @base, string head, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(@base, nameof(@base));
Ensure.ArgumentNotNullOrEmptyString(head, nameof(head));
Ensure.ArgumentNotNull(options, nameof(options));

return Compare(ApiUrls.RepoCompare(repositoryId, @base, head), options);
}

private async Task<CompareResult> Compare(Uri uri, ApiOptions options)
{
var results = await ApiConnection.GetAll<CompareResult>(uri, options);
if (results.Count == 1) return results[0];

var firstCompareResult = results[0];
var commits = firstCompareResult.Commits.ToList();
var files = firstCompareResult.Files.ToList();

foreach (var compareResult in results.Skip(1))
{
commits.AddRange(compareResult.Commits ?? Array.Empty<GitHubCommit>());
files.AddRange(compareResult.Files ?? Array.Empty<GitHubCommitFile>());
}

return new CompareResult(
firstCompareResult.Url,
firstCompareResult.HtmlUrl,
firstCompareResult.PermalinkUrl,
firstCompareResult.DiffUrl,
firstCompareResult.PatchUrl,
firstCompareResult.BaseCommit,
firstCompareResult.MergeBaseCommit,
firstCompareResult.Status,
firstCompareResult.AheadBy,
firstCompareResult.BehindBy,
firstCompareResult.TotalCommits,
commits,
files);
}

/// <summary>
/// Gets a single commit for a given repository
/// </summary>
Expand Down