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 5 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
36 changes: 36 additions & 0 deletions source/Notebooks/Notebooks.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Notebooks</AssemblyName>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<Authors>Octopus Deploy</Authors>
<Copyright>Octopus Deploy Pty Ltd</Copyright>
<Description>
Octopus Deploy is an automated release management tool for modern developers and DevOps teams.

This package contains the client library for the HTTP API in Octopus.
</Description>
<NuspecFile>Octopus.Client.nuspec</NuspecFile>
<!-- copy dependencies to the output folder (for netstandard) so we can ilmerge them together -->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<LangVersion>8</LangVersion>
<UserSecretsId>e33919d5-7abc-48db-bb00-0d49c717b69e</UserSecretsId>

</PropertyGroup>

<PropertyGroup Condition="!$([MSBuild]::IsOSUnixLike())">
<TargetFrameworks>net462;net48;netstandard2.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition="$([MSBuild]::IsOSUnixLike())">
<TargetFrameworks>netstandard2.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Octopus.Server.Client\Octopus.Server.Client.csproj" />
</ItemGroup>

</Project>
43 changes: 43 additions & 0 deletions source/Notebooks/Runbooks ASync.dib
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!meta

{"kernelInfo":{"defaultKernelName":"csharp","items":[{"aliases":[],"languageName":"csharp","name":"csharp"}]}}

#!csharp

#r "..\Octopus.Server.Client\bin\Debug\netstandard2.0\Octopus.Server.Client.dll"

using Octopus.Client.Repositories;
using System.Threading;

var apiKey = Environment.GetEnvironmentVariable("Server__ApiKey");

var endpoint = new Octopus.Client.OctopusServerEndpoint("http://localhost:8066", apiKey);
var client = await Octopus.Client.OctopusAsyncClient.Create(endpoint, new Octopus.Client.OctopusClientOptions());
var repository = new Octopus.Client.OctopusAsyncRepository(client);

var project = await repository.Projects.FindByName("Git Example", CancellationToken.None);

var runbook = await repository.Runbooks.GetInGit("mr-runbooks", project, "main", CancellationToken.None);
runbook.Name ="Aync New Test";

await repository.Runbooks.ModifyInGit(runbook, "main", "Test", CancellationToken.None);

#!csharp

#r "..\Octopus.Server.Client\bin\Debug\netstandard2.0\Octopus.Server.Client.dll"

using Octopus.Client.Repositories;
using System.Threading;

var apiKey = Environment.GetEnvironmentVariable("Server__ApiKey");

var endpoint = new Octopus.Client.OctopusServerEndpoint("http://localhost:8066", apiKey);
var client = await Octopus.Client.OctopusAsyncClient.Create(endpoint, new Octopus.Client.OctopusClientOptions());
var repository = new Octopus.Client.OctopusAsyncRepository(client);

var project = await repository.Projects.FindByName("Git Example", CancellationToken.None);

var runbook = await repository.Runbooks.CreateOrModifyInGit(project, "test-1", "Test One", "Allows testing", "main", "Test", CancellationToken.None);
runbook = await repository.Runbooks.CreateOrModifyInGit(project, "test-1", "Test One", "Allows more testing", "main", "Test 2", CancellationToken.None);

await repository.Runbooks.DeleteInGit(runbook, "main", "test delete", CancellationToken.None);
21 changes: 21 additions & 0 deletions source/Notebooks/Runbooks Sync.dib
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!meta

{"kernelInfo":{"defaultKernelName":"csharp","items":[{"aliases":[],"languageName":"csharp","name":"csharp"}]}}

#!csharp

#r "..\Octopus.Server.Client\bin\Debug\netstandard2.0\Octopus.Server.Client.dll"

using Octopus.Client.Repositories;

var apiKey = Environment.GetEnvironmentVariable("Server__ApiKey");

var endpoint = new Octopus.Client.OctopusServerEndpoint("http://localhost:8066", apiKey);

var repository = new Octopus.Client.OctopusRepository(endpoint);
var project = repository.Projects.FindByName("Git Example");

var runbook = repository.Runbooks.GetInGit("mr-runbooks", project, "main");
runbook.Name ="New Test";

repository.Runbooks.ModifyInGit(runbook, "main", "Test");
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;
}
}
}
Loading
Loading