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

First pass #898

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -1304,9 +1304,14 @@ Octopus.Client.Editors.Async
Octopus.Client.Model.RunbookResource Instance { get; }
Task<RunbookProcessEditor> RunbookProcess { get; }
Task<RunbookEditor> CreateOrModify(Octopus.Client.Model.ProjectResource, String, String)
Task<RunbookEditor> CreateOrModify(Octopus.Client.Model.ProjectResource, String, String, CancellationToken)
Task<RunbookEditor> CreateOrModifyInGit(Octopus.Client.Model.ProjectResource, String, String, String, String, String, CancellationToken)
Octopus.Client.Editors.Async.RunbookEditor Customize(Action<RunbookResource>)
Task<RunbookEditor> Load(String)
Task<RunbookEditor> Load(String, CancellationToken)
Task<RunbookEditor> LoadInGit(String, Octopus.Client.Model.ProjectResource, String, CancellationToken)
Task<RunbookEditor> Save()
Task<RunbookEditor> SaveInGit(String, String, CancellationToken)
}
class RunbookProcessEditor
Octopus.Client.Editors.Async.IResourceEditor<RunbookProcessResource, RunbookProcessEditor>
Expand All @@ -1319,8 +1324,12 @@ Octopus.Client.Editors.Async
Octopus.Client.Editors.Async.RunbookProcessEditor Customize(Action<RunbookProcessResource>)
Octopus.Client.Model.DeploymentStepResource FindStep(String)
Task<RunbookProcessEditor> Load(String)
Task<RunbookProcessEditor> Load(String, CancellationToken)
Task<RunbookProcessEditor> LoadInGit(Octopus.Client.Model.ProjectResource, String, String, CancellationToken)
Octopus.Client.Editors.Async.RunbookProcessEditor RemoveStep(String)
Task<RunbookProcessEditor> Save()
Task<RunbookProcessEditor> Save(CancellationToken)
Task<RunbookProcessEditor> SaveInGit(String, String, CancellationToken)
}
class SshKeyPairAccountEditor
Octopus.Client.Editors.Async.IResourceEditor<SshKeyPairAccountResource, SshKeyPairAccountEditor>
Expand Down Expand Up @@ -4050,6 +4059,29 @@ Octopus.Client.Model
.ctor()
String ChangeDescription { get; set; }
}
class ModifyRunbookCommand
Octopus.Client.Extensibility.IResource
Octopus.Client.Model.IAuditedResource
Octopus.Client.Extensibility.INamedResource
Octopus.Client.Extensibility.IHaveSpaceResource
Octopus.Client.Model.IHaveSlugResource
Octopus.Client.Model.ICommitCommand
Octopus.Client.Model.RunbookResource
{
.ctor()
String ChangeDescription { get; set; }
}
class ModifyRunbookProcessCommand
Octopus.Client.Extensibility.IResource
Octopus.Client.Model.IAuditedResource
Octopus.Client.Model.IProcessResource
Octopus.Client.Extensibility.IHaveSpaceResource
Octopus.Client.Model.ICommitCommand
Octopus.Client.Model.RunbookProcessResource
{
.ctor()
String ChangeDescription { get; set; }
}
MultipleAccountType
{
None = 0
Expand Down Expand Up @@ -9193,7 +9225,9 @@ Octopus.Client.Repositories.Async
Octopus.Client.Repositories.Async.IGet<RunbookProcessResource>
Octopus.Client.Repositories.Async.IModify<RunbookProcessResource>
{
Task<RunbookProcessResource> GetInGit(Octopus.Client.Model.ProjectResource, String, String, CancellationToken)
Task<RunbookSnapshotTemplateResource> GetTemplate(Octopus.Client.Model.RunbookProcessResource)
Task<RunbookProcessResource> ModifyInGit(String, String, Octopus.Client.Model.RunbookProcessResource, CancellationToken)
}
interface IRunbookRepository
Octopus.Client.Repositories.Async.IFindByName<RunbookResource>
Expand All @@ -9203,11 +9237,15 @@ Octopus.Client.Repositories.Async
Octopus.Client.Repositories.Async.IModify<RunbookResource>
Octopus.Client.Repositories.Async.IDelete<RunbookResource>
{
Task<RunbookResource> CreateInGit(Octopus.Client.Model.RunbookResource, String, String, CancellationToken)
Task<RunbookEditor> CreateOrModify(Octopus.Client.Model.ProjectResource, String, String)
Task<RunbookEditor> CreateOrModifyInGit(Octopus.Client.Model.ProjectResource, String, String, String, String, String, CancellationToken)
Task<RunbookResource> FindByName(Octopus.Client.Model.ProjectResource, String)
Task<RunbookResource> GetInGit(String, Octopus.Client.Model.ProjectResource, String, CancellationToken)
Task<RunbookRunPreviewResource> GetPreview(Octopus.Client.Model.DeploymentPromotionTarget)
Task<RunbookRunTemplateResource> GetRunbookRunTemplate(Octopus.Client.Model.RunbookResource)
Task<RunbookSnapshotTemplateResource> GetRunbookSnapshotTemplate(Octopus.Client.Model.RunbookResource)
Task<RunbookResource> ModifyInGit(Octopus.Client.Model.RunbookResource, String, String, CancellationToken)
Task<RunbookRunResource> Run(Octopus.Client.Model.RunbookResource, Octopus.Client.Model.RunbookRunResource)
Task<RunbookRunResource[]> Run(Octopus.Client.Model.RunbookResource, Octopus.Client.Model.RunbookRunParameters)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1305,9 +1305,14 @@ Octopus.Client.Editors.Async
Octopus.Client.Model.RunbookResource Instance { get; }
Task<RunbookProcessEditor> RunbookProcess { get; }
Task<RunbookEditor> CreateOrModify(Octopus.Client.Model.ProjectResource, String, String)
Task<RunbookEditor> CreateOrModify(Octopus.Client.Model.ProjectResource, String, String, CancellationToken)
Task<RunbookEditor> CreateOrModifyInGit(Octopus.Client.Model.ProjectResource, String, String, String, String, String, CancellationToken)
Octopus.Client.Editors.Async.RunbookEditor Customize(Action<RunbookResource>)
Task<RunbookEditor> Load(String)
Task<RunbookEditor> Load(String, CancellationToken)
Task<RunbookEditor> LoadInGit(String, Octopus.Client.Model.ProjectResource, String, CancellationToken)
Task<RunbookEditor> Save()
Task<RunbookEditor> SaveInGit(String, String, CancellationToken)
}
class RunbookProcessEditor
Octopus.Client.Editors.Async.IResourceEditor<RunbookProcessResource, RunbookProcessEditor>
Expand All @@ -1320,8 +1325,12 @@ Octopus.Client.Editors.Async
Octopus.Client.Editors.Async.RunbookProcessEditor Customize(Action<RunbookProcessResource>)
Octopus.Client.Model.DeploymentStepResource FindStep(String)
Task<RunbookProcessEditor> Load(String)
Task<RunbookProcessEditor> Load(String, CancellationToken)
Task<RunbookProcessEditor> LoadInGit(Octopus.Client.Model.ProjectResource, String, String, CancellationToken)
Octopus.Client.Editors.Async.RunbookProcessEditor RemoveStep(String)
Task<RunbookProcessEditor> Save()
Task<RunbookProcessEditor> Save(CancellationToken)
Task<RunbookProcessEditor> SaveInGit(String, String, CancellationToken)
}
class SshKeyPairAccountEditor
Octopus.Client.Editors.Async.IResourceEditor<SshKeyPairAccountResource, SshKeyPairAccountEditor>
Expand Down Expand Up @@ -4067,6 +4076,29 @@ Octopus.Client.Model
.ctor()
String ChangeDescription { get; set; }
}
class ModifyRunbookCommand
Octopus.Client.Extensibility.IResource
Octopus.Client.Model.IAuditedResource
Octopus.Client.Extensibility.INamedResource
Octopus.Client.Extensibility.IHaveSpaceResource
Octopus.Client.Model.IHaveSlugResource
Octopus.Client.Model.ICommitCommand
Octopus.Client.Model.RunbookResource
{
.ctor()
String ChangeDescription { get; set; }
}
class ModifyRunbookProcessCommand
Octopus.Client.Extensibility.IResource
Octopus.Client.Model.IAuditedResource
Octopus.Client.Model.IProcessResource
Octopus.Client.Extensibility.IHaveSpaceResource
Octopus.Client.Model.ICommitCommand
Octopus.Client.Model.RunbookProcessResource
{
.ctor()
String ChangeDescription { get; set; }
}
MultipleAccountType
{
None = 0
Expand Down Expand Up @@ -9218,7 +9250,9 @@ Octopus.Client.Repositories.Async
Octopus.Client.Repositories.Async.IGet<RunbookProcessResource>
Octopus.Client.Repositories.Async.IModify<RunbookProcessResource>
{
Task<RunbookProcessResource> GetInGit(Octopus.Client.Model.ProjectResource, String, String, CancellationToken)
Task<RunbookSnapshotTemplateResource> GetTemplate(Octopus.Client.Model.RunbookProcessResource)
Task<RunbookProcessResource> ModifyInGit(String, String, Octopus.Client.Model.RunbookProcessResource, CancellationToken)
}
interface IRunbookRepository
Octopus.Client.Repositories.Async.IFindByName<RunbookResource>
Expand All @@ -9228,11 +9262,15 @@ Octopus.Client.Repositories.Async
Octopus.Client.Repositories.Async.IModify<RunbookResource>
Octopus.Client.Repositories.Async.IDelete<RunbookResource>
{
Task<RunbookResource> CreateInGit(Octopus.Client.Model.RunbookResource, String, String, CancellationToken)
Task<RunbookEditor> CreateOrModify(Octopus.Client.Model.ProjectResource, String, String)
Task<RunbookEditor> CreateOrModifyInGit(Octopus.Client.Model.ProjectResource, String, String, String, String, String, CancellationToken)
Task<RunbookResource> FindByName(Octopus.Client.Model.ProjectResource, String)
Task<RunbookResource> GetInGit(String, Octopus.Client.Model.ProjectResource, String, CancellationToken)
Task<RunbookRunPreviewResource> GetPreview(Octopus.Client.Model.DeploymentPromotionTarget)
Task<RunbookRunTemplateResource> GetRunbookRunTemplate(Octopus.Client.Model.RunbookResource)
Task<RunbookSnapshotTemplateResource> GetRunbookSnapshotTemplate(Octopus.Client.Model.RunbookResource)
Task<RunbookResource> ModifyInGit(Octopus.Client.Model.RunbookResource, String, String, CancellationToken)
Task<RunbookRunResource> Run(Octopus.Client.Model.RunbookResource, Octopus.Client.Model.RunbookRunResource)
Task<RunbookRunResource[]> Run(Octopus.Client.Model.RunbookResource, Octopus.Client.Model.RunbookRunParameters)
}
Expand Down
66 changes: 61 additions & 5 deletions source/Octopus.Server.Client/Editors/Async/RunbookEditor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Octopus.Client.Model;
using Octopus.Client.Repositories.Async;
Expand All @@ -21,33 +22,74 @@ public RunbookEditor(IRunbookRepository repository,

public Task<RunbookProcessEditor> RunbookProcess => runbookProcess.Value;


public async Task<RunbookEditor> CreateOrModify(ProjectResource project, string name, string description)
=> await CreateOrModify(project, name, description, CancellationToken.None).ConfigureAwait(false);

public async Task<RunbookEditor> CreateOrModify(ProjectResource project, string name, string description, CancellationToken cancellationToken)
{
var existing = await repository.FindByName(project, name).ConfigureAwait(false);

if (existing == null)
{
Instance = await repository.Create(new RunbookResource
{
ProjectId = project.Id,
Name = name,
Description = description
}).ConfigureAwait(false);
}, cancellationToken).ConfigureAwait(false);
}
else
{
existing.Name = name;
existing.Description = description;

Instance = await repository.Modify(existing).ConfigureAwait(false);
Instance = await repository.Modify(existing, cancellationToken).ConfigureAwait(false);
}

return this;
}

public async Task<RunbookEditor> CreateOrModifyInGit(ProjectResource project, string slug, string name, string description, string gitRef, string commitMessage, CancellationToken cancellationToken)
{
var existing = await repository.GetInGit(slug, project, gitRef, cancellationToken).ConfigureAwait(false);

if (existing == null)
{
Instance = await repository.CreateInGit(new RunbookResource
{
Slug = slug,
ProjectId = project.Id,
Name = name,
Description = description
},
gitRef,
commitMessage,
cancellationToken).ConfigureAwait(false);
}
else
{
existing.Name = name;
existing.Description = description;

Instance = await repository.ModifyInGit(existing, gitRef, commitMessage, cancellationToken).ConfigureAwait(false);
}

return this;
}

public async Task<RunbookEditor> Load(string id)
=> await Load(id, CancellationToken.None).ConfigureAwait(false);

public async Task<RunbookEditor> Load(string id, CancellationToken cancellationToken)
{
Instance = await repository.Get(id).ConfigureAwait(false);
Instance = await repository.Get(id, cancellationToken).ConfigureAwait(false);
return this;
}

public async Task<RunbookEditor> LoadInGit(string id, ProjectResource project, string gitRef, CancellationToken cancellationToken)
{
Instance = await repository.GetInGit(id, project, gitRef, cancellationToken).ConfigureAwait(false);
return this;
}

Expand All @@ -58,14 +100,28 @@ public RunbookEditor Customize(Action<RunbookResource> customize)
}

public async Task<RunbookEditor> Save()
{
{
Instance = await repository.Modify(Instance).ConfigureAwait(false);

if (runbookProcess.IsValueCreated)
{
var steps = await runbookProcess.Value.ConfigureAwait(false);
await steps.Save().ConfigureAwait(false);
}
return this;
}

public async Task<RunbookEditor> SaveInGit(string gitRef, string commitMessage, CancellationToken cancellationToken)
{
Instance = await repository.ModifyInGit(Instance, gitRef, commitMessage, cancellationToken).ConfigureAwait(false);

if (runbookProcess.IsValueCreated)
{
var steps = await runbookProcess.Value.ConfigureAwait(false);
await steps.SaveInGit(gitRef, commitMessage, cancellationToken).ConfigureAwait(false);
}

return this;
}
}
}
23 changes: 21 additions & 2 deletions source/Octopus.Server.Client/Editors/Async/RunbookProcessEditor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Octopus.Client.Model;
using Octopus.Client.Repositories.Async;
Expand All @@ -17,8 +18,17 @@ public RunbookProcessEditor(IRunbookProcessRepository repository)
public RunbookProcessResource Instance { get; private set; }

public async Task<RunbookProcessEditor> Load(string id)
=> await Load(id, CancellationToken.None);

public async Task<RunbookProcessEditor> Load(string id, CancellationToken cancellationToken)
{
Instance = await repository.Get(id).ConfigureAwait(false);
Instance = await repository.Get(id, cancellationToken).ConfigureAwait(false);
return this;
}

public async Task<RunbookProcessEditor> LoadInGit(ProjectResource project, string id, string gitRef, CancellationToken cancellationToken)
{
Instance = await repository.GetInGit(project, id, gitRef, cancellationToken).ConfigureAwait(false);
return this;
}

Expand Down Expand Up @@ -51,8 +61,17 @@ public RunbookProcessEditor Customize(Action<RunbookProcessResource> customize)
}

public async Task<RunbookProcessEditor> Save()
=> await Save(CancellationToken.None);

public async Task<RunbookProcessEditor> Save(CancellationToken cancellationToken)
{
Instance = await repository.Modify(Instance, cancellationToken).ConfigureAwait(false);
return this;
}

public async Task<RunbookProcessEditor> SaveInGit(string gitRef, string commitMessage, CancellationToken cancellationToken)
{
Instance = await repository.Modify(Instance).ConfigureAwait(false);
Instance = await repository.ModifyInGit(gitRef, commitMessage, Instance, cancellationToken).ConfigureAwait(false);
return this;
}
}
Expand Down
46 changes: 46 additions & 0 deletions source/Octopus.Server.Client/Editors/RunbookEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,44 @@ public RunbookEditor CreateOrModify(ProjectResource project, string name, string
return this;
}

public RunbookEditor CreateOrModifyInGit(ProjectResource project, string slug, string name, string description, string gitRef, string commitMessage)
{
var existing = repository.GetInGit(slug, project, gitRef);

if (existing == null)
{
Instance = repository.CreateInGit(new RunbookResource
{
Slug = slug,
ProjectId = project.Id,
Name = name,
Description = description
},
gitRef,
commitMessage);
}
else
{
existing.Name = name;
existing.Description = description;

Instance = repository.ModifyInGit(existing, gitRef, commitMessage);
}

return this;
}

public RunbookEditor Load(string id)
{
Instance = repository.Get(id);
return this;
}

public RunbookEditor LoadInGit(string id, ProjectResource project, string gitRef)
{
Instance = repository.GetInGit(id, project, gitRef);
return this;
}

public RunbookEditor Customize(Action<RunbookResource> customize)
{
Expand All @@ -68,5 +101,18 @@ public RunbookEditor Save()
}
return this;
}

public RunbookEditor SaveInGit(string gitRef, string commitMessage)
{
Instance = repository.ModifyInGit(Instance, gitRef, commitMessage);

if (runbookProcess.IsValueCreated)
{
var steps = runbookProcess.Value;
steps.SaveInGit(gitRef, commitMessage);
}

return this;
}
}
}
Loading
Loading