Skip to content

Commit

Permalink
feat: Implement dependency review and dependency submission APIs (#2932)
Browse files Browse the repository at this point in the history
Implement dependency review and dependency submission

Co-authored-by: André Pereira <[email protected]>
  • Loading branch information
awedist and André Pereira authored Jun 14, 2024
1 parent 6c43183 commit 7d54cb0
Show file tree
Hide file tree
Showing 39 changed files with 1,949 additions and 8 deletions.
22 changes: 22 additions & 0 deletions Octokit.Reactive/Clients/IObservableDependencyGraphClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's Dependency Graph API.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/dependency-graph">Git Dependency Graph API documentation</a> for more information.
/// </remarks>
public interface IObservableDependencyGraphClient
{
/// <summary>
/// Client for getting a dependency comparison between two commits.
/// </summary>
IObservableDependencyReviewClient DependencyReview { get; }

/// <summary>
/// Client for submitting dependency snapshots.
/// </summary>
IObservableDependencySubmissionClient DependencySubmission { get; }
}
}

39 changes: 39 additions & 0 deletions Octokit.Reactive/Clients/IObservableDependencyReviewClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

using System;

namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's Dependency Review API.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/dependency-graph/dependency-review">Git Dependency Review API documentation</a> for more information.
/// </remarks>
public interface IObservableDependencyReviewClient
{
/// <summary>
/// Gets all <see cref="DependencyDiff"/>s for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/dependency-graph/dependency-review">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="base">The base revision</param>
/// <param name="head">The head revision</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
IObservable<DependencyDiff> GetAll(string owner, string name, string @base, string head);

/// <summary>
/// Gets all <see cref="DependencyDiff"/>s for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/dependency-graph/dependency-review">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="base">The base revision</param>
/// <param name="head">The head revision</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
IObservable<DependencyDiff> GetAll(long repositoryId, string @base, string head);
}
}
39 changes: 39 additions & 0 deletions Octokit.Reactive/Clients/IObservableDependencySubmissionClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;

namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's Dependency Submission API.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/dependency-graph/dependency-submission">Dependency Submission API documentation</a> for more details.
/// </remarks>
public interface IObservableDependencySubmissionClient
{
/// <summary>
/// Creates a new dependency snapshot.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/dependency-graph/dependency-submission">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="snapshot">The dependency snapshot to create</param>
/// <exception cref="ApiException">Thrown when a general API error occurs</exception>
/// <returns>A <see cref="DependencySnapshotSubmission"/> instance for the created snapshot</returns>
IObservable<DependencySnapshotSubmission> Create(string owner, string name, NewDependencySnapshot snapshot);

/// <summary>
/// Creates a new dependency snapshot.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/dependency-graph/dependency-submission">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="snapshot">The dependency snapshot to create</param>
/// <exception cref="ApiException">Thrown when a general API error occurs</exception>
/// <returns>A <see cref="DependencySnapshotSubmission"/> instance for the created snapshot</returns>
IObservable<DependencySnapshotSubmission> Create(long repositoryId, NewDependencySnapshot snapshot);
}
}

29 changes: 29 additions & 0 deletions Octokit.Reactive/Clients/ObservableDependencyGraphClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's Dependency Graph API.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/dependency-graph">Git Dependency Graph API documentation</a> for more information.
/// </remarks>
public class ObservableDependencyGraphClient : IObservableDependencyGraphClient
{
public ObservableDependencyGraphClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, nameof(client));

//DependencyReview = new ObservableDependencyReviewClient(client);
DependencySubmission = new ObservableDependencySubmissionClient(client);
}

/// <summary>
/// Client for getting a dependency comparison between two commits.
/// </summary>
public IObservableDependencyReviewClient DependencyReview { get; private set; }

/// <summary>
/// Client for submitting dependency snapshots.
/// </summary>
public IObservableDependencySubmissionClient DependencySubmission { get; private set; }
}
}
63 changes: 63 additions & 0 deletions Octokit.Reactive/Clients/ObservableDependencyReviewClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;

namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's Dependency Review API.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/dependency-graph/dependency-review">Git Dependency Review API documentation</a> for more information.
/// </remarks>
public class ObservableDependencyReviewClient : IObservableDependencyReviewClient
{
readonly IDependencyReviewClient _client;

public ObservableDependencyReviewClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, nameof(client));

_client = client.DependencyGraph.DependencyReview;
}

/// <summary>
/// Gets all <see cref="DependencyDiff"/>s for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/dependency-graph/dependency-review">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="base">The base revision</param>
/// <param name="head">The head revision</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<DependencyDiff> GetAll(string owner, string name, string @base, string head)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(@base, nameof(@base));
Ensure.ArgumentNotNullOrEmptyString(head, nameof(head));

return _client.GetAll(owner, name, @base, head).ToObservable().SelectMany(x => x);
}

/// <summary>
/// Gets all <see cref="DependencyDiff"/>s for the specified repository.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/dependency-graph/dependency-review">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="base">The base revision</param>
/// <param name="head">The head revision</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<DependencyDiff> GetAll(long repositoryId, string @base, string head)
{
Ensure.ArgumentNotNullOrEmptyString(@base, nameof(@base));
Ensure.ArgumentNotNullOrEmptyString(head, nameof(head));

return _client.GetAll(repositoryId, @base, head).ToObservable().SelectMany(x => x);
}
}
}
60 changes: 60 additions & 0 deletions Octokit.Reactive/Clients/ObservableDependencySubmissionClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.Reactive.Threading.Tasks;

namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's Dependency Submission API.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/dependency-graph/dependency-submission">Dependency Submission API documentation</a> for more details.
/// </remarks>
public class ObservableDependencySubmissionClient : IObservableDependencySubmissionClient
{
readonly IDependencySubmissionClient _client;

public ObservableDependencySubmissionClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, nameof(client));

_client = client.DependencyGraph.DependencySubmission;
}

/// <summary>
/// Creates a new dependency snapshot.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/dependency-graph/dependency-submission">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The repository's owner</param>
/// <param name="name">The repository's name</param>
/// <param name="snapshot">The dependency snapshot to create</param>
/// <exception cref="ApiException">Thrown when a general API error occurs</exception>
/// <returns>A <see cref="DependencySnapshotSubmission"/> instance for the created snapshot</returns>
public IObservable<DependencySnapshotSubmission> Create(string owner, string name, NewDependencySnapshot snapshot)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(snapshot, nameof(snapshot));

return _client.Create(owner, name, snapshot).ToObservable();
}

/// <summary>
/// Creates a new dependency snapshot.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/rest/dependency-graph/dependency-submission">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="snapshot">The dependency snapshot to create</param>
/// <exception cref="ApiException">Thrown when a general API error occurs</exception>
/// <returns>A <see cref="DependencySnapshotSubmission"/> instance for the created snapshot</returns>
public IObservable<DependencySnapshotSubmission> Create(long repositoryId, NewDependencySnapshot snapshot)
{
Ensure.ArgumentNotNull(snapshot, nameof(snapshot));

return _client.Create(repositoryId, snapshot).ToObservable();
}
}
}
1 change: 1 addition & 0 deletions Octokit.Reactive/IObservableGitHubClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ public interface IObservableGitHubClient : IApiInfoProvider
IObservableActionsClient Actions { get; }
IObservableCodespacesClient Codespaces { get; }
IObservableCopilotClient Copilot { get; }
IObservableDependencyGraphClient DependencyGraph { get; }
}
}
4 changes: 3 additions & 1 deletion Octokit.Reactive/ObservableGitHubClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public ObservableGitHubClient(IGitHubClient gitHubClient)
Actions = new ObservableActionsClient(gitHubClient);
Codespaces = new ObservableCodespacesClient(gitHubClient);
Copilot = new ObservableCopilotClient(gitHubClient);
DependencyGraph = new ObservableDependencyGraphClient(gitHubClient);
}

public IConnection Connection
Expand Down Expand Up @@ -108,7 +109,8 @@ public void SetRequestTimeout(TimeSpan timeout)
public IObservableActionsClient Actions { get; private set; }
public IObservableCodespacesClient Codespaces { get; private set; }
public IObservableCopilotClient Copilot { get; set; }

public IObservableDependencyGraphClient DependencyGraph { get; }

/// <summary>
/// Gets the latest API Info - this will be null if no API calls have been made
/// </summary>
Expand Down
55 changes: 55 additions & 0 deletions Octokit.Tests.Integration/Clients/DependencyReviewClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Octokit;
using Octokit.Tests.Integration;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

/// <summary>
/// Base and head must have different dependencies
/// </summary>
public class DependencyReviewClientTests
{

public class TheGetAllMethod
{
readonly IDependencyReviewClient _fixture;
readonly IGitHubClient _github;
readonly string _owner;
readonly string _repo;
readonly string _base;
readonly string _head;
readonly long _repoId;

public TheGetAllMethod()
{
_github = Helper.GetAuthenticatedClient();
_fixture = _github.DependencyGraph.DependencyReview;

_owner = "octokit";
_repo = "octokit.net";
_base = "main";
_head = "brave-new-codegen-world";
_repoId = _github.Repository.Get(_owner, _repo).Result.Id;
}

[IntegrationTest]
public async Task GetDependencyDiffs()
{
var diffs = await _fixture.GetAll(_owner, _repo, _base, _head);

Assert.NotEmpty(diffs);
Assert.NotNull(diffs);
Assert.IsType<DependencyDiff>(diffs.First());
}

[IntegrationTest]
public async Task GetDependencyDiffsWithRepositoryId()
{
var diffs = await _fixture.GetAll(_repoId, _base, _head);

Assert.NotEmpty(diffs);
Assert.NotNull(diffs);
Assert.IsType<DependencyDiff>(diffs.First());
}
}
}
Loading

0 comments on commit 7d54cb0

Please sign in to comment.