Skip to content
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 23 commits into from
Feb 11, 2014
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c8d99c3
Implemented DeploymentsClient and unit tests
Jan 10, 2014
3c5e39c
Implemented DeploymentStatusesClient and unit tests
Jan 10, 2014
2692de6
Initial simple integration tests for DeploymentsClient
Jan 10, 2014
6d4d8a4
Initial integration tests for DeploymentStatusClient
Jan 10, 2014
41704d7
Added documentation comments to...
Jan 11, 2014
c89f8aa
Changing DateTime to DateTimeOffset...
Jan 11, 2014
c7b681f
Renamed GitDeployment to Deployment
Jan 11, 2014
4e2d7d1
Added second integration test for DeploymentStatuses..
Jan 11, 2014
2c3743f
ApiUrls documentation comments
Jan 12, 2014
83fec9a
Added documentation comment remarks with links...
Jan 12, 2014
86d7229
Added deserialization unit test for Deployment
Jan 12, 2014
1db77c6
Implemented deserialization unit test for...
Jan 12, 2014
b147a70
Merge branch 'master' into deployments_client
Jan 20, 2014
89a8776
Merge remote-tracking branch 'upstream/master' into deployments_client
Jan 21, 2014
a220069
Implemented ObservableDeploymentsClient and...
Jan 21, 2014
c5d12dc
Implemented ObservableDeploymentStatusClient and...
Jan 21, 2014
4029fdc
Formatting
Jan 21, 2014
ed462e7
Merge branch 'master' into deployments_client
Feb 2, 2014
2e92630
Fixing argument tests for ObservableDeployments...
Feb 3, 2014
f0f6a96
Merge branch 'master' into deployments_client
Feb 9, 2014
ddbfc0a
Fixing unit tests for DeploymentsClient,
Feb 9, 2014
a9b9358
Merge branch 'master' of https://github.com/octokit/octokit.net into …
Feb 11, 2014
106e21b
Fixing whitespace
Feb 11, 2014
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
36 changes: 36 additions & 0 deletions Octokit.Reactive/Clients/IObservableDeploymentStatusClient.cs
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);
}
}
32 changes: 32 additions & 0 deletions Octokit.Reactive/Clients/IObservableDeploymentsClient.cs
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 Octokit.Reactive/Clients/ObservableDeploymentStatusClient.cs
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();
}
}
}
55 changes: 55 additions & 0 deletions Octokit.Reactive/Clients/ObservableDeploymentsClient.cs
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");
Copy link
Contributor

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. 😄

Copy link
Author

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.

}

/// <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();
}
}
}
4 changes: 4 additions & 0 deletions Octokit.Reactive/Octokit.Reactive-Mono.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@
<Compile Include="Clients\ObservableGistsClient.cs" />
<Compile Include="Clients\IObservableSearchClient.cs" />
<Compile Include="Clients\ObservableSearchClient.cs" />
<Compile Include="Clients\ObservableDeploymentsClient.cs" />
<Compile Include="Clients\IObservableDeploymentsClient.cs" />
<Compile Include="Clients\IObservableDeploymentStatusClient.cs" />
<Compile Include="Clients\ObservableDeploymentStatusClient.cs" />
<Compile Include="Clients\IObservableWatchedClient.cs" />
<Compile Include="Clients\ObservableWatchedClient.cs" />
<Compile Include="Clients\IObservableFollowersClient.cs" />
Expand Down
4 changes: 4 additions & 0 deletions Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@
<Compile Include="Clients\ObservableGistsClient.cs" />
<Compile Include="Clients\IObservableSearchClient.cs" />
<Compile Include="Clients\ObservableSearchClient.cs" />
<Compile Include="Clients\ObservableDeploymentsClient.cs" />
<Compile Include="Clients\IObservableDeploymentsClient.cs" />
<Compile Include="Clients\IObservableDeploymentStatusClient.cs" />
<Compile Include="Clients\ObservableDeploymentStatusClient.cs" />
<Compile Include="Clients\IObservableWatchedClient.cs" />
<Compile Include="Clients\ObservableWatchedClient.cs" />
<Compile Include="Clients\IObservableFollowersClient.cs" />
Expand Down
4 changes: 4 additions & 0 deletions Octokit.Reactive/Octokit.Reactive-Monotouch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@
<Compile Include="Clients\ObservableGistsClient.cs" />
<Compile Include="Clients\IObservableSearchClient.cs" />
<Compile Include="Clients\ObservableSearchClient.cs" />
<Compile Include="Clients\ObservableDeploymentsClient.cs" />
<Compile Include="Clients\IObservableDeploymentsClient.cs" />
<Compile Include="Clients\IObservableDeploymentStatusClient.cs" />
<Compile Include="Clients\ObservableDeploymentStatusClient.cs" />
<Compile Include="Clients\IObservableWatchedClient.cs" />
<Compile Include="Clients\ObservableWatchedClient.cs" />
<Compile Include="Clients\IObservableFollowersClient.cs" />
Expand Down
4 changes: 4 additions & 0 deletions Octokit.Reactive/Octokit.Reactive.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
<Compile Include="..\SolutionInfo.cs">
<Link>Properties\SolutionInfo.cs</Link>
</Compile>
<Compile Include="Clients\IObservableDeploymentsClient.cs" />
<Compile Include="Clients\IObservableDeploymentStatusClient.cs" />
<Compile Include="Clients\ObservableDeploymentsClient.cs" />
<Compile Include="Clients\ObservableDeploymentStatusClient.cs" />
<Compile Include="Clients\IObservableWatchedClient.cs" />
<Compile Include="Clients\IObservableFollowersClient.cs" />
<Compile Include="Clients\ObservableSearchClient.cs" />
Expand Down
88 changes: 88 additions & 0 deletions Octokit.Tests.Integration/Clients/DeploymentStatusClientTests.cs
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);
}
}

Loading