Merge branch 'master' into BetterFileCopy

This commit is contained in:
Jordan Brown
2021-02-02 11:47:53 -05:00
5 changed files with 51 additions and 10 deletions
@@ -32,6 +32,7 @@ namespace Tgstation.Server.Host.Components.Events
/// <summary>
/// Parameters: Absolute path to repository root
/// </summary>
/// <remarks>Changes made to the repository during this event will be pushed to the tracked branch if no test merges are present.</remarks>
[EventScript("PreSynchronize")]
RepoPreSynchronize,
@@ -152,6 +152,16 @@ namespace Tgstation.Server.Host.Components
}
}
/// <summary>
/// The <see cref="JobEntrypoint"/> for updating the repository.
/// </summary>
/// <param name="core">The <see cref="IInstanceCore"/> for the <paramref name="job"/>.</param>
/// <param name="databaseContextFactory">The <see cref="IDatabaseContextFactory"/> for the <paramref name="job"/>.</param>
/// <param name="job">The <see cref="Job"/> being run.</param>
/// <param name="progressReporter">The progress reporter action for the <paramref name="job"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
#pragma warning disable CA1502 // Cyclomatic complexity
Task RepositoryAutoUpdateJob(
IInstanceCore core,
IDatabaseContextFactory databaseContextFactory,
@@ -321,7 +331,7 @@ namespace Tgstation.Server.Host.Components
}
// synch if necessary
if (repositorySettings.AutoUpdatesSynchronize.Value && startSha != repo.Head)
if (repositorySettings.AutoUpdatesSynchronize.Value && startSha != repo.Head && (shouldSyncTracked || repositorySettings.PushTestMergeCommits.Value))
{
var pushedOrigin = await repo.Sychronize(
repositorySettings.AccessUser,
@@ -350,6 +360,7 @@ namespace Tgstation.Server.Host.Components
progressReporter(5 * ProgressStep);
});
#pragma warning restore CA1502 // Cyclomatic complexity
/// <summary>
/// Pull the repository and compile for every set of given <paramref name="minutes"/>
@@ -610,7 +610,14 @@ namespace Tgstation.Server.Host.Components.Repository
}
/// <inheritdoc />
public async Task<bool> Sychronize(string username, string password, string committerName, string committerEmail, Action<int> progressReporter, bool synchronizeTrackedBranch, CancellationToken cancellationToken)
public async Task<bool> Sychronize(
string username,
string password,
string committerName,
string committerEmail,
Action<int> progressReporter,
bool synchronizeTrackedBranch,
CancellationToken cancellationToken)
{
if (committerName == null)
throw new ArgumentNullException(nameof(committerName));
@@ -659,12 +666,12 @@ namespace Tgstation.Server.Host.Components.Repository
logger.LogTrace("Resetting and cleaning untracked files...");
await Task.Factory.StartNew(() =>
{
libGitRepo.RemoveUntrackedFiles();
cancellationToken.ThrowIfCancellationRequested();
libGitRepo.Reset(ResetMode.Hard, libGitRepo.Head.Tip, new CheckoutOptions
{
OnCheckoutProgress = CheckoutProgressHandler(progress => progressReporter(progress / 10))
});
cancellationToken.ThrowIfCancellationRequested();
libGitRepo.RemoveUntrackedFiles();
}, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current).ConfigureAwait(false);
}
@@ -586,7 +586,15 @@ namespace Tgstation.Server.Host.Controllers
await UpdateRevInfo().ConfigureAwait(false);
if (fastForward.Value)
{
await repo.Sychronize(currentModel.AccessUser, currentModel.AccessToken, currentModel.CommitterName, currentModel.CommitterEmail, NextProgressReporter(), true, ct).ConfigureAwait(false);
await repo.Sychronize(
currentModel.AccessUser,
currentModel.AccessToken,
currentModel.CommitterName,
currentModel.CommitterEmail,
NextProgressReporter(),
true,
ct)
.ConfigureAwait(false);
postUpdateSha = repo.Head;
}
else
@@ -622,7 +630,15 @@ namespace Tgstation.Server.Host.Controllers
if (!repo.Tracking)
throw new JobException(ErrorCode.RepoReferenceNotTracking);
await repo.ResetToOrigin(NextProgressReporter(), ct).ConfigureAwait(false);
await repo.Sychronize(currentModel.AccessUser, currentModel.AccessToken, currentModel.CommitterName, currentModel.CommitterEmail, NextProgressReporter(), true, ct).ConfigureAwait(false);
await repo.Sychronize(
currentModel.AccessUser,
currentModel.AccessToken,
currentModel.CommitterName,
currentModel.CommitterEmail,
NextProgressReporter(),
true,
ct)
.ConfigureAwait(false);
await CallLoadRevInfo().ConfigureAwait(false);
// repo head is on origin so force this
@@ -836,9 +852,17 @@ namespace Tgstation.Server.Host.Controllers
}
var currentHead = repo.Head;
if (startSha != currentHead || (postUpdateSha != null && postUpdateSha != currentHead))
if (currentModel.PushTestMergeCommits.Value && (startSha != currentHead || (postUpdateSha != null && postUpdateSha != currentHead)))
{
await repo.Sychronize(currentModel.AccessUser, currentModel.AccessToken, currentModel.CommitterName, currentModel.CommitterEmail, NextProgressReporter(), false, ct).ConfigureAwait(false);
await repo.Sychronize(
currentModel.AccessUser,
currentModel.AccessToken,
currentModel.CommitterName,
currentModel.CommitterEmail,
NextProgressReporter(),
false,
ct)
.ConfigureAwait(false);
await UpdateRevInfo().ConfigureAwait(false);
}
@@ -34,9 +34,7 @@ namespace Tgstation.Server.Host.Jobs
/// <param name="jobCancellationToken">A <see cref="CancellationToken"/> that will cancel the <paramref name="job"/></param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task"/> representing the <see cref="Job"/></returns>
#pragma warning disable CA1068 // CancellationToken parameters must come last https://github.com/dotnet/roslyn-analyzers/issues/1816
Task WaitForJobCompletion(Job job, User canceller, CancellationToken jobCancellationToken, CancellationToken cancellationToken);
#pragma warning restore CA1068 // CancellationToken parameters must come last
/// <summary>
/// Cancels a give <paramref name="job"/>