Other fixups

This commit is contained in:
Jordan Brown
2018-07-31 11:07:21 -04:00
parent 456aa0b849
commit 5aba26e0dc
4 changed files with 23 additions and 16 deletions
@@ -51,7 +51,7 @@ namespace Tgstation.Server.Api.Models
public string Reference { get; set; }
/// <summary>
/// <see cref="TestMergeParameters"/> for new <see cref="TestMerge"/>s
/// <see cref="TestMergeParameters"/> for new <see cref="TestMerge"/>s. Note that merges that conflict will not be performed
/// </summary>
[Permissions(WriteRight = RepositoryRights.MergePullRequest)]
public List<TestMergeParameters> NewTestMerges { get; set; }
@@ -62,8 +62,8 @@ namespace Tgstation.Server.Host.Components.Repository
/// <param name="accessString">The access string to fetch from the origin repository</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <param name="progressReporter">Optional function to report 0-100 progress of the clone</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the SHA of the new HEAD on success, <see langword="null"/> on merge conflict</returns>
Task<string> AddTestMerge(int pullRequestNumber, string targetCommit, string committerName, string committerEmail, string accessString, Action<int> progressReporter, CancellationToken cancellationToken);
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="bool?"/> representing the merge result that is <see langword="true"/> after a fast forward or up to date, <see langword="false"/> on a merge, <see langword="null"/> on a conflict</returns>
Task<bool?> AddTestMerge(int pullRequestNumber, string targetCommit, string committerName, string committerEmail, string accessString, Action<int> progressReporter, CancellationToken cancellationToken);
/// <summary>
/// Fetch commits from the origin repository
@@ -79,7 +79,7 @@ namespace Tgstation.Server.Host.Components.Repository
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the SHA of the new HEAD</returns>
Task<string> ResetToOrigin(CancellationToken cancellationToken);
Task ResetToOrigin(CancellationToken cancellationToken);
/// <summary>
/// Requires the current HEAD to be a tracked reference. Merges the reference to what it tracks on the origin repository
@@ -87,8 +87,8 @@ namespace Tgstation.Server.Host.Components.Repository
/// <param name="committerName">The name of the merge committer</param>
/// <param name="committerEmail">The e-mail of the merge committer</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the SHA of the new HEAD. <see langword="null"/> if the merge resulted in conflict</returns>
Task<string> MergeOrigin(string committerName, string committerEmail, CancellationToken cancellationToken);
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="bool?"/> representing the merge result that is <see langword="true"/> after a fast forward or up to date, <see langword="false"/> on a merge, <see langword="null"/> on a conflict</returns>
Task<bool?> MergeOrigin(string committerName, string committerEmail, CancellationToken cancellationToken);
/// <summary>
/// Force push the current repository HEAD to <see cref="Repository.RemoteTemporaryBranchName"/>;
@@ -139,7 +139,7 @@ namespace Tgstation.Server.Host.Components.Repository
}
/// <inheritdoc />
public async Task<string> AddTestMerge(int pullRequestNumber, string targetCommit, string committerName, string committerEmail, string accessString, Action<int> progressReporter, CancellationToken cancellationToken)
public async Task<bool?> AddTestMerge(int pullRequestNumber, string targetCommit, string committerName, string committerEmail, string accessString, Action<int> progressReporter, CancellationToken cancellationToken)
{
if (!IsGitHubRepository)
@@ -206,10 +206,10 @@ namespace Tgstation.Server.Host.Components.Repository
if (result.Status == MergeStatus.Conflicts)
{
await eventConsumer.HandleEvent(EventType.RepoMergeConflict, new List<string> { originalCommit.Tip.Sha, targetCommit, originalCommit.FriendlyName ?? UnknownReference, prBranchName }, cancellationToken).ConfigureAwait(false);
return null;
return false;
}
return result.Commit.Sha;
return true;
}
/// <inheritdoc />
@@ -285,13 +285,13 @@ namespace Tgstation.Server.Host.Components.Repository
}, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current);
/// <inheritdoc />
public async Task<string> ResetToOrigin(CancellationToken cancellationToken)
public async Task ResetToOrigin(CancellationToken cancellationToken)
{
if (!repository.Head.IsTracking)
throw new InvalidOperationException("Cannot reset to origin while not on a tracked reference!");
var trackedBranch = repository.Head.TrackedBranch;
await eventConsumer.HandleEvent(EventType.RepoResetOrigin, new List<string> { trackedBranch.FriendlyName, trackedBranch.Tip.Sha }, cancellationToken).ConfigureAwait(false);
return await Task.Factory.StartNew(() =>
await Task.Factory.StartNew(() =>
{
Commands.Checkout((LibGit2Sharp.Repository)repository, repository.Head.TrackedBranch, new CheckoutOptions
{
@@ -299,7 +299,6 @@ namespace Tgstation.Server.Host.Components.Repository
});
cancellationToken.ThrowIfCancellationRequested();
repository.RemoveUntrackedFiles();
return trackedBranch.Tip.Sha;
}, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false);
}
@@ -312,7 +311,7 @@ namespace Tgstation.Server.Host.Components.Repository
}
/// <inheritdoc />
public async Task<string> MergeOrigin(string committerName, string committerEmail, CancellationToken cancellationToken)
public async Task<bool?> MergeOrigin(string committerName, string committerEmail, CancellationToken cancellationToken)
{
MergeResult result = null;
Branch trackedBranch = null;
@@ -350,7 +349,7 @@ namespace Tgstation.Server.Host.Components.Repository
return null;
}
return Head;
return result.Status != MergeStatus.NonFastForward;
}
/// <inheritdoc />
@@ -336,8 +336,12 @@ namespace Tgstation.Server.Host.Controllers
doneFetches = 1;
if (!modelHasShaOrReference)
{
await repo.MergeOrigin(committerName, currentModel.CommitterEmail, cancellationToken).ConfigureAwait(false);
var fastForward = await repo.MergeOrigin(committerName, currentModel.CommitterEmail, cancellationToken).ConfigureAwait(false);
if (!fastForward.HasValue)
throw new InvalidOperationException("Merge conflict occurred during origin update!");
await UpdateRevInfo().ConfigureAwait(false);
if (fastForward.Value)
lastRevisionInfo.OriginCommitSha = repo.Head;
}
}
@@ -372,7 +376,11 @@ namespace Tgstation.Server.Host.Controllers
{
var prTask = gitHubClient.PullRequest.Get(repoOwner, repoName, I.Number);
await repo.AddTestMerge(I.Number, I.PullRequestRevision, committerName, currentModel.CommitterEmail, accessString, x => progressReporter((x + 100 * doneFetches) / numFetches), cancellationToken).ConfigureAwait(false);
var mergeResult = await repo.AddTestMerge(I.Number, I.PullRequestRevision, committerName, currentModel.CommitterEmail, accessString, x => progressReporter((x + 100 * doneFetches) / numFetches), cancellationToken).ConfigureAwait(false);
if (!mergeResult.HasValue) //conflict, we don't care, dd already knows
continue;
++doneFetches;
var revInfoUpdateTask = UpdateRevInfo();