Skip to content

Commit

Permalink
Fix Runners active state in Mocks (#712)
Browse files Browse the repository at this point in the history
* Fix Runners active state in Mocks

* Fixes
  • Loading branch information
Toa741 authored Jul 4, 2024
1 parent 08b5ac8 commit c09c6da
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
6 changes: 2 additions & 4 deletions NGitLab.Mock/Clients/RunnerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public Models.Runner Update(int runnerId, RunnerUpdate runnerUpdate)
var runner = this[runnerId] ?? throw new GitLabNotFoundException();
var runnerOnServer = GetServerRunner(runnerId);

runnerOnServer.Active = runnerUpdate.Active ?? runnerOnServer.Active;
runnerOnServer.Active = runnerUpdate.IsActive() ?? runnerOnServer.IsActive();
runnerOnServer.Paused = runnerUpdate.Paused ?? runnerOnServer.Paused;
runnerOnServer.TagList = runnerUpdate.TagList ?? runnerOnServer.TagList;
runnerOnServer.Description = !string.IsNullOrEmpty(runnerUpdate.Description) ? runnerUpdate.Description : runnerOnServer.Description;
Expand Down Expand Up @@ -217,9 +217,7 @@ public Models.Runner Register(RunnerRegister request)
var project = Server.AllProjects.SingleOrDefault(p => string.Equals(p.RunnersToken, request.Token, StringComparison.Ordinal));
if (project != null)
{
#pragma warning disable CS0618 // Type or member is obsolete
var runner = project.AddRunner(null, request.Description, request.Active ?? false, request.Locked ?? true, false, request.RunUntagged ?? false);
#pragma warning restore CS0618 // Type or member is obsolete
var runner = project.AddRunner(null, request.Description, request.IsActive() ?? true, request.Locked ?? true, false, request.RunUntagged ?? false);
return runner.ToClientRunner(Context.User);
}

Expand Down
27 changes: 27 additions & 0 deletions NGitLab.Mock/RunnersExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using NGitLab.Models;

namespace NGitLab.Mock;

internal static class RunnersExtensions
{
public static bool? IsActive(this RunnerRegister runner)
{
#pragma warning disable CS0618 // Type or member is obsolete
return runner.Active ?? !runner.Paused;
#pragma warning restore CS0618 // Type or member is obsolete
}

public static bool? IsActive(this RunnerUpdate runner)
{
#pragma warning disable CS0618 // Type or member is obsolete
return runner.Active ?? !runner.Paused;
#pragma warning restore CS0618 // Type or member is obsolete
}

public static bool IsActive(this Runner runner)
{
#pragma warning disable CS0618 // Type or member is obsolete
return runner.Active || !runner.Paused;
#pragma warning restore CS0618 // Type or member is obsolete
}
}

0 comments on commit c09c6da

Please sign in to comment.