-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementing Deployments client #298
Merged
Merged
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
c8d99c3
Implemented DeploymentsClient and unit tests
3c5e39c
Implemented DeploymentStatusesClient and unit tests
2692de6
Initial simple integration tests for DeploymentsClient
6d4d8a4
Initial integration tests for DeploymentStatusClient
41704d7
Added documentation comments to...
c89f8aa
Changing DateTime to DateTimeOffset...
c7b681f
Renamed GitDeployment to Deployment
4e2d7d1
Added second integration test for DeploymentStatuses..
2c3743f
ApiUrls documentation comments
83fec9a
Added documentation comment remarks with links...
86d7229
Added deserialization unit test for Deployment
1db77c6
Implemented deserialization unit test for...
b147a70
Merge branch 'master' into deployments_client
89a8776
Merge remote-tracking branch 'upstream/master' into deployments_client
a220069
Implemented ObservableDeploymentsClient and...
c5d12dc
Implemented ObservableDeploymentStatusClient and...
4029fdc
Formatting
ed462e7
Merge branch 'master' into deployments_client
2e92630
Fixing argument tests for ObservableDeployments...
f0f6a96
Merge branch 'master' into deployments_client
ddbfc0a
Fixing unit tests for DeploymentsClient,
a9b9358
Merge branch 'master' of https://github.com/octokit/octokit.net into …
106e21b
Fixing whitespace
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
Octokit.Reactive/Clients/IObservableDeploymentStatusClient.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,36 @@ | ||
using System; | ||
using System.Reactive.Threading.Tasks; | ||
using Octokit.Reactive.Internal; | ||
|
||
namespace Octokit.Reactive.Clients | ||
{ | ||
public interface IObservableDeploymentStatusClient | ||
{ | ||
/// <summary> | ||
/// Gets all the statuses for the given deployment. Any user with pull access to a repository can | ||
/// view deployments. | ||
/// </summary> | ||
/// <remarks> | ||
/// http://developer.github.com/v3/repos/deployments/#list-deployment-statuses | ||
/// </remarks> | ||
/// <param name="owner">The owner of the repository.</param> | ||
/// <param name="name">The name of the repository.</param> | ||
/// <param name="deploymentId">The id of the deployment.</param> | ||
/// <returns>All deployment statuses for the given deployment.</returns> | ||
IObservable<DeploymentStatus> GetAll(string owner, string name, int deploymentId); | ||
|
||
/// <summary> | ||
/// Creates a new status for the given deployment. Users with push access can create deployment | ||
/// statuses for a given deployment. | ||
/// </summary> | ||
/// <remarks> | ||
/// http://developer.github.com/v3/repos/deployments/#create-a-deployment-status | ||
/// </remarks> | ||
/// <param name="owner">The owner of the repository.</param> | ||
/// <param name="name">The name of the repository.</param> | ||
/// <param name="deploymentId">The id of the deployment.</param> | ||
/// <param name="newDeploymentStatus">The new deployment status to create.</param> | ||
/// <returns></returns> | ||
IObservable<DeploymentStatus> Create(string owner, string name, int deploymentId, NewDeploymentStatus newDeploymentStatus); | ||
} | ||
} |
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,32 @@ | ||
using System; | ||
|
||
namespace Octokit.Reactive.Clients | ||
{ | ||
public interface IObservableDeploymentsClient | ||
{ | ||
/// <summary> | ||
/// Gets all the deployments for the specified repository. Any user with pull access | ||
/// to a repository can view deployments. | ||
/// </summary> | ||
/// <remarks> | ||
/// http://developer.github.com/v3/repos/deployments/#list-deployments | ||
/// </remarks> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="name">The name of the repository</param> | ||
/// <returns>All the <see cref="Deployment"/>s for the specified repository.</returns> | ||
IObservable<Deployment> GetAll(string owner, string name); | ||
|
||
/// <summary> | ||
/// Creates a new deployment for the specified repository. | ||
/// Users with push access can create a deployment for a given ref. | ||
/// </summary> | ||
/// <remarks> | ||
/// http://developer.github.com/v3/repos/deployments/#create-a-deployment | ||
/// </remarks> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="name">The name of the repository</param> | ||
/// <param name="newDeployment">A <see cref="NewDeployment"/> instance describing the new deployment to create</param> | ||
/// <returns>The created <see cref="Deployment"></returns> | ||
IObservable<Deployment> Create(string owner, string name, NewDeployment newDeployment); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
Octokit.Reactive/Clients/ObservableDeploymentStatusClient.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,59 @@ | ||
using Octokit.Reactive.Internal; | ||
using System; | ||
using System.Reactive.Threading.Tasks; | ||
|
||
namespace Octokit.Reactive.Clients | ||
{ | ||
public class ObservableDeploymentStatusClient : IObservableDeploymentStatusClient | ||
{ | ||
const string acceptsHeader = "application/vnd.github.cannonball-preview+json"; | ||
private IDeploymentStatusClient _client; | ||
private IConnection _connection; | ||
|
||
public ObservableDeploymentStatusClient(IGitHubClient client) | ||
{ | ||
Ensure.ArgumentNotNull(client, "client"); | ||
|
||
_client = client.Deployment.Status; | ||
_connection = client.Connection; | ||
} | ||
|
||
/// <summary> | ||
/// Gets all the statuses for the given deployment. Any user with pull access to a repository can | ||
/// view deployments. | ||
/// </summary> | ||
/// <remarks> | ||
/// http://developer.github.com/v3/repos/deployments/#list-deployment-statuses | ||
/// </remarks> | ||
/// <param name="owner">The owner of the repository.</param> | ||
/// <param name="name">The name of the repository.</param> | ||
/// <param name="deploymentId">The id of the deployment.</param> | ||
/// <returns>All deployment statuses for the given deployment.</returns> | ||
public IObservable<DeploymentStatus> GetAll(string owner, string name, int deploymentId) | ||
{ | ||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); | ||
Ensure.ArgumentNotNullOrEmptyString(name, "name"); | ||
|
||
return _connection.GetAndFlattenAllPages<DeploymentStatus>( | ||
ApiUrls.DeploymentStatuses(owner, name, deploymentId), | ||
null, acceptsHeader); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new status for the given deployment. Users with push access can create deployment | ||
/// statuses for a given deployment. | ||
/// </summary> | ||
/// <remarks> | ||
/// http://developer.github.com/v3/repos/deployments/#create-a-deployment-status | ||
/// </remarks> | ||
/// <param name="owner">The owner of the repository.</param> | ||
/// <param name="name">The name of the repository.</param> | ||
/// <param name="deploymentId">The id of the deployment.</param> | ||
/// <param name="newDeploymentStatus">The new deployment status to create.</param> | ||
/// <returns></returns> | ||
public IObservable<DeploymentStatus> Create(string owner, string name, int deploymentId, NewDeploymentStatus newDeploymentStatus) | ||
{ | ||
return _client.Create(owner, name, deploymentId, newDeploymentStatus).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using Octokit.Reactive.Internal; | ||
using System; | ||
using System.Reactive.Threading.Tasks; | ||
|
||
namespace Octokit.Reactive.Clients | ||
{ | ||
public class ObservableDeploymentsClient : IObservableDeploymentsClient | ||
{ | ||
readonly IDeploymentsClient _client; | ||
readonly IConnection _connection; | ||
|
||
public ObservableDeploymentsClient(IGitHubClient client) | ||
{ | ||
Ensure.ArgumentNotNull(client, "client"); | ||
|
||
_client = client.Deployment; | ||
_connection = client.Connection; | ||
} | ||
|
||
/// <summary> | ||
/// Gets all the deployments for the specified repository. Any user with pull access | ||
/// to a repository can view deployments. | ||
/// </summary> | ||
/// <remarks> | ||
/// http://developer.github.com/v3/repos/deployments/#list-deployments | ||
/// </remarks> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="name">The name of the repository</param> | ||
/// <returns>All the <see cref="Deployment"/>s for the specified repository.</returns> | ||
public IObservable<Deployment> GetAll(string owner, string name) | ||
{ | ||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); | ||
Ensure.ArgumentNotNullOrEmptyString(name, "name"); | ||
|
||
return _connection.GetAndFlattenAllPages<Deployment>(ApiUrls.Deployments(owner, name), null, | ||
"application/vnd.github.cannonball-preview+json"); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new deployment for the specified repository. | ||
/// Users with push access can create a deployment for a given ref. | ||
/// </summary> | ||
/// <remarks> | ||
/// http://developer.github.com/v3/repos/deployments/#create-a-deployment | ||
/// </remarks> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="name">The name of the repository</param> | ||
/// <param name="newDeployment">A <see cref="NewDeployment"/> instance describing the new deployment to create</param> | ||
/// <returns>The created <see cref="Deployment"></returns> | ||
public IObservable<Deployment> Create(string owner, string name, NewDeployment newDeployment) | ||
{ | ||
return _client.Create(owner, name, newDeployment).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
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
88 changes: 88 additions & 0 deletions
88
Octokit.Tests.Integration/Clients/DeploymentStatusClientTests.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,88 @@ | ||
using Octokit; | ||
using Octokit.Tests.Integration; | ||
using System; | ||
using System.Net.Http.Headers; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
public class DeploymentStatusClientTests : IDisposable | ||
{ | ||
IGitHubClient _gitHubClient; | ||
IDeploymentsClient _deploymentsClient; | ||
Repository _repository; | ||
Commit _commit; | ||
Deployment _deployment; | ||
string _repositoryOwner; | ||
|
||
public DeploymentStatusClientTests() | ||
{ | ||
_gitHubClient = new GitHubClient(new ProductHeaderValue("OctokitTests")) | ||
{ | ||
Credentials = Helper.Credentials | ||
}; | ||
|
||
_deploymentsClient = _gitHubClient.Deployment; | ||
|
||
var newRepository = new NewRepository | ||
{ | ||
Name = Helper.MakeNameWithTimestamp("public-repo"), | ||
AutoInit = true | ||
}; | ||
|
||
_repository = _gitHubClient.Repository.Create(newRepository).Result; | ||
_repositoryOwner = _repository.Owner.Login; | ||
|
||
var blob = new NewBlob | ||
{ | ||
Content = "Hello World!", | ||
Encoding = EncodingType.Utf8 | ||
}; | ||
|
||
var blobResult = _gitHubClient.GitDatabase.Blob.Create(_repositoryOwner, _repository.Name, blob).Result; | ||
|
||
var newTree = new NewTree(); | ||
newTree.Tree.Add(new NewTreeItem | ||
{ | ||
Type = TreeType.Blob, | ||
Mode = FileMode.File, | ||
Path = "README.md", | ||
Sha = blobResult.Sha | ||
}); | ||
|
||
var treeResult = _gitHubClient.GitDatabase.Tree.Create(_repositoryOwner, _repository.Name, newTree).Result; | ||
var newCommit = new NewCommit("test-commit", treeResult.Sha); | ||
_commit = _gitHubClient.GitDatabase.Commit.Create(_repositoryOwner, _repository.Name, newCommit).Result; | ||
|
||
var newDeployment = new NewDeployment { Ref = _commit.Sha }; | ||
_deployment = _deploymentsClient.Create(_repositoryOwner, _repository.Name, newDeployment).Result; | ||
} | ||
|
||
[IntegrationTest] | ||
public async Task CanCreateDeploymentStatus() | ||
{ | ||
var newStatus = new NewDeploymentStatus { State = DeploymentState.Success }; | ||
|
||
var status = await _deploymentsClient.Status.Create(_repositoryOwner, _repository.Name, _deployment.Id, newStatus); | ||
|
||
Assert.NotNull(status); | ||
Assert.Equal(DeploymentState.Success, status.State); | ||
} | ||
|
||
[IntegrationTest] | ||
public async Task CanReadDeploymentStatuses() | ||
{ | ||
var newStatus = new NewDeploymentStatus { State = DeploymentState.Success }; | ||
await _deploymentsClient.Status.Create(_repositoryOwner, _repository.Name, _deployment.Id, newStatus); | ||
|
||
var statuses = await _deploymentsClient.Status.GetAll(_repositoryOwner, _repository.Name, _deployment.Id); | ||
|
||
Assert.NotEmpty(statuses); | ||
Assert.Equal(DeploymentState.Success, statuses[0].State); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Helper.DeleteRepo(_repository); | ||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey buddy. What are you doing way over there on the right. Come over here. It's ok, we won't bite. Perhaps one tab in like you do elsewhere. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My own conventions sneaking in there. I generally line up arguments either all on new lines or lined up with the first argument. Dot-notation indentation is a whole other story.