-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement dependency review and dependency submission APIs (#2932)
Implement dependency review and dependency submission Co-authored-by: André Pereira <[email protected]>
- Loading branch information
Showing
39 changed files
with
1,949 additions
and
8 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
Octokit.Reactive/Clients/IObservableDependencyGraphClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
39
Octokit.Reactive/Clients/IObservableDependencyReviewClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
39
Octokit.Reactive/Clients/IObservableDependencySubmissionClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
29
Octokit.Reactive/Clients/ObservableDependencyGraphClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
63
Octokit.Reactive/Clients/ObservableDependencyReviewClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
60
Octokit.Reactive/Clients/ObservableDependencySubmissionClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
Octokit.Tests.Integration/Clients/DependencyReviewClientTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
Oops, something went wrong.