Permalink
Browse files

Add REST API to deploy the latest bits on the selected branch

  • Loading branch information...
1 parent 4a1cc9a commit dad7327cb7d2abaa729fb307f14071222c2e39bd @davidebbo davidebbo committed Jan 18, 2013
@@ -157,6 +157,16 @@ public void Deploy(IRepository repository, ChangeSet changeSet, string deployer,
ITracer tracer = _traceFactory.GetTracer();
IDisposable deployStep = null;
var deploymentRepository = new DeploymentRepository(repository);
+
+ // If we don't get a changeset, find out what branch we should be deploying and update the repo to it
+ if (changeSet == null)
+ {
+ string targetBranch = _settings.GetValue(SettingsKeys.Branch);
+ deploymentRepository.Update(targetBranch);
+
+ changeSet = deploymentRepository.GetChangeSet(repository.CurrentId);
+ }
+
string id = changeSet.Id;
try
{
@@ -6,7 +6,12 @@ public static class DeploymentManagerExtensions
{
public static void Deploy(this IDeploymentManager deploymentManager, IRepository repository, string id, string deployer, bool clean)
{
- ChangeSet changeSet = repository.GetChangeSet(id);
+ ChangeSet changeSet = null;
+ if (id != null)
+ {
+ changeSet = repository.GetChangeSet(id);
+ }
+
deploymentManager.Deploy(repository, changeSet, deployer, clean);
}
}
@@ -514,14 +514,31 @@ public void PushingConfiguredBranch()
Git.CheckOut(repo.PhysicalPath, "test");
ApplicationManager.Run(appName, appManager =>
{
- // Act
+ // Set the branch to test and push to that branch
appManager.SettingsManager.SetValue("branch", "test").Wait();
appManager.GitDeploy(repo.PhysicalPath, "test", "test");
var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
// Assert
Assert.Equal(1, results.Count);
KuduAssert.VerifyUrl(appManager.SiteUrl, "Test branch");
+
+ // Now push master, but without changing the deploy branch
+ appManager.GitDeploy(repo.PhysicalPath, "master", "master");
+ results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
+
+ // Here, no new deployment should have happened
+ Assert.Equal(1, results.Count);
+ KuduAssert.VerifyUrl(appManager.SiteUrl, "Test branch");
+
+ // Now change deploy branch to master and do a 'Deploy Latest' (i.e. no id)
+ appManager.SettingsManager.SetValue("branch", "master").Wait();
+ appManager.DeploymentManager.DeployAsync(id: null).Wait();
+ results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
+
+ // Now, we should have a second deployment with master bit
+ Assert.Equal(2, results.Count);
+ KuduAssert.VerifyUrl(appManager.SiteUrl, "Master branch");
});
}
}
@@ -229,9 +229,9 @@ public static void RegisterRoutes(IKernel kernel, RouteCollection routes)
routes.MapHttpRoute("execute-command", "command", new { controller = "Command", action = "ExecuteCommand" }, new { verb = new HttpMethodConstraint("POST") });
// Deployments
- routes.MapHttpRoute("all-deployments", "deployments", new { controller = "Deployment", action = "GetDeployResults" });
+ routes.MapHttpRoute("all-deployments", "deployments", new { controller = "Deployment", action = "GetDeployResults" }, new { verb = new HttpMethodConstraint("GET") });
routes.MapHttpRoute("one-deployment-get", "deployments/{id}", new { controller = "Deployment", action = "GetResult" }, new { verb = new HttpMethodConstraint("GET") });
- routes.MapHttpRoute("one-deployment-put", "deployments/{id}", new { controller = "Deployment", action = "Deploy" }, new { verb = new HttpMethodConstraint("PUT") });
+ routes.MapHttpRoute("one-deployment-put", "deployments/{id}", new { controller = "Deployment", action = "Deploy", id = RouteParameter.Optional }, new { verb = new HttpMethodConstraint("PUT") });
routes.MapHttpRoute("one-deployment-delete", "deployments/{id}", new { controller = "Deployment", action = "Delete" }, new { verb = new HttpMethodConstraint("DELETE") });
routes.MapHttpRoute("one-deployment-log", "deployments/{id}/log", new { controller = "Deployment", action = "GetLogEntry" });
routes.MapHttpRoute("one-deployment-log-details", "deployments/{id}/log/{logId}", new { controller = "Deployment", action = "GetLogEntryDetails" });
@@ -65,7 +65,7 @@ public void Delete(string id)
/// </summary>
/// <param name="id">id of the deployment to redeploy</param>
[HttpPut]
- public void Deploy(string id)
+ public void Deploy(string id = null)
{
JObject result = GetJsonContent();

0 comments on commit dad7327

Please sign in to comment.