Fix a ton of Repository linter errors

This commit is contained in:
Dominion
2023-04-23 02:40:26 -04:00
parent d771da71b9
commit 06043de502
2 changed files with 25 additions and 30 deletions
@@ -65,7 +65,7 @@ namespace Tgstation.Server.Host.Components.Repository
public string Reference => libGitRepo.Head.FriendlyName;
/// <inheritdoc />
public Uri Origin => new Uri(libGitRepo.Network.Remotes.First().Url);
public Uri Origin => new (libGitRepo.Network.Remotes.First().Url);
/// <summary>
/// The <see cref="LibGit2Sharp.IRepository"/> for the <see cref="Repository"/>.
@@ -201,9 +201,9 @@ namespace Tgstation.Server.Host.Components.Repository
throw new ArgumentNullException(nameof(progressReporter));
logger.LogDebug(
"Begin AddTestMerge: #{0} at {1} ({2}) by <{3} ({4})>",
"Begin AddTestMerge: #{prNumber} at {targetSha} ({comment}) by <{committerName} ({committerEmail})>",
testMergeParameters.Number,
testMergeParameters.TargetCommitSha?.Substring(0, 7),
testMergeParameters.TargetCommitSha?[..7],
testMergeParameters.Comment,
committerName,
committerEmail);
@@ -242,7 +242,7 @@ namespace Tgstation.Server.Host.Components.Repository
{
try
{
logger.LogTrace("Fetching refspec {0}...", refSpec);
logger.LogTrace("Fetching refspec {refSpec}...", refSpec);
var remote = libGitRepo.Network.Remotes.First();
commands.Fetch(
@@ -276,15 +276,13 @@ namespace Tgstation.Server.Host.Components.Repository
cancellationToken.ThrowIfCancellationRequested();
var objectName = testMergeParameters.TargetCommitSha ?? localBranchName;
var gitObject = libGitRepo.Lookup(objectName);
if (gitObject == null)
throw new JobException($"Could not find object to merge: {objectName}");
var gitObject = libGitRepo.Lookup(objectName) ?? throw new JobException($"Could not find object to merge: {objectName}");
testMergeParameters.TargetCommitSha = gitObject.Sha;
cancellationToken.ThrowIfCancellationRequested();
logger.LogTrace("Merging {0} into {1}...", testMergeParameters.TargetCommitSha[..7], Reference);
logger.LogTrace("Merging {targetCommitSha} into {currentReference}...", testMergeParameters.TargetCommitSha[..7], Reference);
result = libGitRepo.Merge(testMergeParameters.TargetCommitSha, sig, new MergeOptions
{
@@ -312,7 +310,7 @@ namespace Tgstation.Server.Host.Components.Repository
conflictedPaths.Add(file.FilePath);
var revertTo = originalCommit.CanonicalName ?? originalCommit.Tip.Sha;
logger.LogDebug("Merge conflict, aborting and reverting to {0}", revertTo);
logger.LogDebug("Merge conflict, aborting and reverting to {revertTarget}", revertTo);
progressReporter.ReportProgress(0);
RawCheckout(revertTo, progressReporter.CreateSection("Hard Reset to {revertTo}", 1.0), cancellationToken);
cancellationToken.ThrowIfCancellationRequested();
@@ -349,7 +347,7 @@ namespace Tgstation.Server.Host.Components.Repository
if (result.Status != MergeStatus.UpToDate)
{
logger.LogTrace("Committing merge: \"{0}\"...", commitMessage);
logger.LogTrace("Committing merge: \"{commitMessage}\"...", commitMessage);
await Task.Factory.StartNew(
() => libGitRepo.Commit(commitMessage, sig, sig, new CommitOptions
{
@@ -400,7 +398,7 @@ namespace Tgstation.Server.Host.Components.Repository
throw new ArgumentNullException(nameof(committish));
if (progressReporter == null)
throw new ArgumentNullException(nameof(progressReporter));
logger.LogDebug("Checkout object: {0}...", committish);
logger.LogDebug("Checkout object: {committish}...", committish);
await eventConsumer.HandleEvent(EventType.RepoCheckout, new List<string> { committish }, cancellationToken);
await Task.Factory.StartNew(
() =>
@@ -506,7 +504,7 @@ namespace Tgstation.Server.Host.Components.Repository
if (progressReporter == null)
throw new ArgumentNullException(nameof(progressReporter));
logger.LogDebug("Reset to sha: {0}", sha.Substring(0, 7));
logger.LogDebug("Reset to sha: {sha}", sha[..7]);
libGitRepo.RemoveUntrackedFiles();
cancellationToken.ThrowIfCancellationRequested();
@@ -531,7 +529,7 @@ namespace Tgstation.Server.Host.Components.Repository
{
if (path == null)
throw new ArgumentNullException(nameof(path));
logger.LogTrace("Copying to {0}...", path);
logger.LogTrace("Copying to {path}...", path);
await ioMananger.CopyDirectory(
new List<string> { ".git" },
(src, dest) =>
@@ -590,7 +588,7 @@ namespace Tgstation.Server.Host.Components.Repository
trackedBranch = libGitRepo.Head.TrackedBranch;
logger.LogDebug(
"Merge origin/{0}: <{1} ({2})>",
"Merge origin/{trackedBranch}: <{committerName} ({committerEmail})>",
trackedBranch.FriendlyName,
committerName,
committerEmail);
@@ -607,7 +605,7 @@ namespace Tgstation.Server.Host.Components.Repository
if (result.Status == MergeStatus.Conflicts)
{
logger.LogDebug("Merge conflict, aborting and reverting to {0}", oldHead.FriendlyName);
logger.LogDebug("Merge conflict, aborting and reverting to {oldHeadFriendlyName}", oldHead.FriendlyName);
progressReporter.ReportProgress(0);
libGitRepo.Reset(ResetMode.Hard, oldTip, new CheckoutOptions
{
@@ -664,7 +662,7 @@ namespace Tgstation.Server.Host.Components.Repository
var startHead = Head;
logger.LogTrace("Configuring <{0} ({1})> as author/committer", committerName, committerEmail);
logger.LogTrace("Configuring <{committerName} ({committerEmail})> as author/committer", committerName, committerEmail);
await Task.Factory.StartNew(
() =>
{
@@ -721,7 +719,7 @@ namespace Tgstation.Server.Host.Components.Repository
var sameHead = Head == startHead;
if (sameHead || !Tracking)
{
logger.LogTrace("Aborted synchronize due to {0}!", sameHead ? "lack of changes" : "not being on tracked reference");
logger.LogTrace("Aborted synchronize due to {abortReason}!", sameHead ? "lack of changes" : "not being on tracked reference");
return false;
}
@@ -795,7 +793,7 @@ namespace Tgstation.Server.Host.Components.Repository
var targetCommit = libGitRepo.Lookup<Commit>(sha);
if (targetCommit == null)
{
logger.LogTrace("Commit {0} not found in repository", sha);
logger.LogTrace("Commit {sha} not found in repository", sha);
return false;
}
@@ -846,10 +844,7 @@ namespace Tgstation.Server.Host.Components.Repository
if (sha == null)
throw new ArgumentNullException(nameof(sha));
var commit = libGitRepo.Lookup<Commit>(sha);
if (commit == null)
throw new JobException($"Commit {sha} does not exist in the repository!");
var commit = libGitRepo.Lookup<Commit>(sha) ?? throw new JobException($"Commit {sha} does not exist in the repository!");
return commit.Committer.When;
},
cancellationToken,
@@ -864,7 +859,7 @@ namespace Tgstation.Server.Host.Components.Repository
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
void RawCheckout(string committish, JobProgressReporter progressReporter, CancellationToken cancellationToken)
{
logger.LogTrace("Checkout: {0}", committish);
logger.LogTrace("Checkout: {committish}", committish);
var stage = $"Checkout {committish}";
progressReporter = progressReporter.CreateSection(stage, 1.0);
@@ -897,7 +892,7 @@ namespace Tgstation.Server.Host.Components.Repository
if (remoteBranch == default)
throw;
logger.LogDebug("Creating local branch for {0}...", remoteBranch.FriendlyName);
logger.LogDebug("Creating local branch for {remoteBranchFriendlyName}...", remoteBranch.FriendlyName);
var branch = libGitRepo.CreateBranch(committish, remoteBranch.Tip);
libGitRepo.Branches.Update(branch, branchUpdate => branchUpdate.TrackedBranch = remoteBranch.CanonicalName);
@@ -1005,7 +1000,7 @@ namespace Tgstation.Server.Host.Components.Repository
return;
}
logger.LogTrace("Updating submodules with{0} credentials...", username == null ? "out" : String.Empty);
logger.LogTrace("Updating submodules with{orWithout} credentials...", username == null ? "out" : String.Empty);
var factor = 1.0 / submoduleCount / 2;
foreach (var submodule in libGitRepo.Submodules)
@@ -1023,7 +1018,7 @@ namespace Tgstation.Server.Host.Components.Repository
progressReporter.CreateSection($"Checkout submodule {submodule.Name}", factor)),
};
logger.LogDebug("Updating submodule {0}...", submodule.Name);
logger.LogDebug("Updating submodule {submoduleName}...", submodule.Name);
Task RawSubModuleUpdate() => Task.Factory.StartNew(
() => libGitRepo.Submodules.Update(submodule.Name, submoduleUpdateOptions),
cancellationToken,
@@ -1039,14 +1034,14 @@ namespace Tgstation.Server.Host.Components.Repository
// kill off the modules/ folder in .git and try again
progressReporter.ReportProgress(null);
credentialsProvider.CheckBadCredentialsException(ex);
logger.LogWarning(ex, "Initial update of submodule {0} failed. Deleting submodule directories and re-attempting...", submodule.Name);
logger.LogWarning(ex, "Initial update of submodule {submoduleName} failed. Deleting submodule directories and re-attempting...", submodule.Name);
await Task.WhenAll(
ioMananger.DeleteDirectory($".git/modules/{submodule.Path}", cancellationToken),
ioMananger.DeleteDirectory(submodule.Path, cancellationToken))
;
logger.LogTrace("Second update attempt for submodule {0}...", submodule.Name);
logger.LogTrace("Second update attempt for submodule {submoduleName}...", submodule.Name);
try
{
await RawSubModuleUpdate();
@@ -1058,7 +1053,7 @@ namespace Tgstation.Server.Host.Components.Repository
catch (LibGit2SharpException ex2)
{
credentialsProvider.CheckBadCredentialsException(ex2);
logger.LogTrace(ex2, "Retried update of submodule {0} failed!", submodule.Name);
logger.LogTrace(ex2, "Retried update of submodule {submoduleName} failed!", submodule.Name);
throw new AggregateException(ex, ex2);
}
}
@@ -130,7 +130,7 @@ namespace Tgstation.Server.Host.Components.Repository
if (progressReporter == null)
throw new ArgumentNullException(nameof(progressReporter));
logger.LogInformation("Begin clone {0} (Branch: {1})", url, initialBranch);
logger.LogInformation("Begin clone {url} (Branch: {initialBranch})", url, initialBranch);
lock (semaphore)
{
if (CloneInProgress)