From 0e34a666267ce80ec3465c6f68699c2008e85549 Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Wed, 20 Dec 2023 14:50:04 -0500 Subject: [PATCH] Nullify `RepositoryController` --- .../Controllers/RepositoryController.cs | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/Tgstation.Server.Host/Controllers/RepositoryController.cs b/src/Tgstation.Server.Host/Controllers/RepositoryController.cs index dbf80a4171..dcff26b25e 100644 --- a/src/Tgstation.Server.Host/Controllers/RepositoryController.cs +++ b/src/Tgstation.Server.Host/Controllers/RepositoryController.cs @@ -24,8 +24,6 @@ using Tgstation.Server.Host.Models; using Tgstation.Server.Host.Security; using Tgstation.Server.Host.Utils; -#nullable disable - namespace Tgstation.Server.Host.Controllers { /// @@ -213,7 +211,7 @@ namespace Tgstation.Server.Host.Controllers await DatabaseContext.Save(cancellationToken); - Logger.LogInformation("Instance {instanceId} repository delete initiated by user {userId}", Instance.Id, AuthenticationContext.User.Id.Value); + Logger.LogInformation("Instance {instanceId} repository delete initiated by user {userId}", Instance.Id, AuthenticationContext.User.Require(x => x.Id)); var job = Job.Create(JobCode.RepositoryDelete, AuthenticationContext.User, Instance); var api = currentModel.ToApi(); @@ -378,23 +376,23 @@ namespace Tgstation.Server.Host.Controllers var api = canRead ? currentModel.ToApi() : new RepositoryResponse(); if (canRead) { - var earlyOut = await WithComponentInstance( - async instance => - { - var repoManager = instance.RepositoryManager; - if (repoManager.CloneInProgress) - return Conflict(new ErrorMessageResponse(ErrorCode.RepoCloning)); + var earlyOut = await WithComponentInstanceNullable( + async instance => + { + var repoManager = instance.RepositoryManager; + if (repoManager.CloneInProgress) + return Conflict(new ErrorMessageResponse(ErrorCode.RepoCloning)); - if (repoManager.InUse) - return Conflict(new ErrorMessageResponse(ErrorCode.RepoBusy)); + if (repoManager.InUse) + return Conflict(new ErrorMessageResponse(ErrorCode.RepoBusy)); - using var repo = await repoManager.LoadRepository(cancellationToken); - if (repo == null) - return Conflict(new ErrorMessageResponse(ErrorCode.RepoMissing)); - await PopulateApi(api, repo, DatabaseContext, Instance, cancellationToken); + using var repo = await repoManager.LoadRepository(cancellationToken); + if (repo == null) + return Conflict(new ErrorMessageResponse(ErrorCode.RepoMissing)); + await PopulateApi(api, repo, DatabaseContext, Instance, cancellationToken); - return null; - }); + return null; + }); if (earlyOut != null) return earlyOut; @@ -404,7 +402,7 @@ namespace Tgstation.Server.Host.Controllers await DatabaseContext.Save(cancellationToken); // format the job description - string description = null; + string? description = null; if (model.UpdateFromOrigin == true) if (model.Reference != null) description = String.Format(CultureInfo.InvariantCulture, "Fetch and hard reset repository to origin/{0}", model.Reference); @@ -424,7 +422,7 @@ namespace Tgstation.Server.Host.Controllers : "T", String.Join( ", ", - model.NewTestMerges.Select( + model.NewTestMerges!.Select( x => String.Format( CultureInfo.InvariantCulture, "#{0}{1}", @@ -450,7 +448,7 @@ namespace Tgstation.Server.Host.Controllers currentModel, AuthenticationContext.User, loggerFactory.CreateLogger(), - Instance.Id.Value); + Instance.Require(x => x.Id)); // Time to access git, do it in a job await jobManager.RegisterOperation( @@ -486,16 +484,14 @@ namespace Tgstation.Server.Host.Controllers apiResponse.Reference = repository.Reference; // rev info stuff - Models.RevisionInformation revisionInfo = null; var needsDbUpdate = await RepositoryUpdateService.LoadRevisionInformation( repository, databaseContext, Logger, instance, null, - newRevInfo => revisionInfo = newRevInfo, + newRevInfo => apiResponse.RevisionInformation = newRevInfo.ToApi(), cancellationToken); - apiResponse.RevisionInformation = revisionInfo.ToApi(); return needsDbUpdate; } }