Merge pull request #630 from tgstation/627-FixRepoInsanity

Fixes mistracking of most recent origin commit sha
This commit is contained in:
Jordan Brown
2018-09-13 11:04:32 -04:00
committed by GitHub
6 changed files with 45 additions and 8 deletions
+1 -1
View File
@@ -287,7 +287,7 @@ Modifications to the repository are done with the following request:
I POST "/Repository" => @ref Tgstation.Server.Api.Models.Repository => @ref Tgstation.Server.Api.Models.Repository
Each update creates a job specified in the @ref Tgstation.Server.Api.Models.Repository.ActiveJob field jobs will be queued in succession. See below for post examples.
Each update that requires git changes creates a job specified in the @ref Tgstation.Server.Api.Models.Repository.ActiveJob field jobs will be queued in succession. See below for POST examples.
@subsubsection api_repopost Repository Commands for Git Aliases
@@ -186,6 +186,7 @@ namespace Tgstation.Server.Host.Components
Id = metadata.Id
}
};
logger.LogWarning(Repository.Repository.OriginTrackingErrorTemplate, currentSha);
db.Instances.Attach(revInfo.Instance);
}
@@ -105,7 +105,7 @@ 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 a <see cref="Nullable{T}"/> <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>
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="Nullable{T}"/> <see cref="bool"/> representing the merge result that is <see langword="true"/> after a fast forward, <see langword="false"/> on a merge or up to date, <see langword="null"/> on a conflict</returns>
Task<bool?> MergeOrigin(string committerName, string committerEmail, CancellationToken cancellationToken);
/// <summary>
@@ -18,13 +18,18 @@ namespace Tgstation.Server.Host.Components.Repository
/// </summary>
public const string GitHubUrl = "://github.com/";
const string UnknownReference = "<UNKNOWN>";
/// <summary>
/// Template error message for when tracking of the most recent origin commit fails
/// </summary>
public const string OriginTrackingErrorTemplate = "Unable to determine most recent origin commit of {0}. Marking it as an origin commit. This may result in invalid git metadata until the next hard reset to an origin reference.";
/// <summary>
/// The branch name used for publishing testmerge commits
/// </summary>
public const string RemoteTemporaryBranchName = "___TGSTempBranch";
const string UnknownReference = "<UNKNOWN>";
/// <inheritdoc />
public bool IsGitHubRepository { get; }
@@ -366,7 +371,7 @@ namespace Tgstation.Server.Host.Components.Repository
return null;
}
return result.Status != MergeStatus.NonFastForward;
return result.Status == MergeStatus.FastForward;
}
/// <inheritdoc />
@@ -10,6 +10,7 @@ using System.Threading.Tasks;
using Tgstation.Server.Api;
using Tgstation.Server.Api.Rights;
using Tgstation.Server.Host.Components;
using Tgstation.Server.Host.Components.Repository;
using Tgstation.Server.Host.Core;
using Tgstation.Server.Host.Models;
using Tgstation.Server.Host.Security;
@@ -179,6 +180,7 @@ namespace Tgstation.Server.Host.Controllers
Id = Instance.Id
}
};
Logger.LogWarning(Repository.OriginTrackingErrorTemplate, repoSha);
databaseContext.Instances.Attach(revInfo.Instance);
}
@@ -67,7 +67,7 @@ namespace Tgstation.Server.Host.Controllers
generalConfiguration = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
}
static async Task<bool> LoadRevisionInformation(Components.Repository.IRepository repository, IDatabaseContext databaseContext, Models.Instance instance, string lastOriginCommitSha, Action<Models.RevisionInformation> revInfoSink, CancellationToken cancellationToken)
async Task<bool> LoadRevisionInformation(Components.Repository.IRepository repository, IDatabaseContext databaseContext, Models.Instance instance, string lastOriginCommitSha, Action<Models.RevisionInformation> revInfoSink, CancellationToken cancellationToken)
{
var repoSha = repository.Head;
@@ -96,12 +96,17 @@ namespace Tgstation.Server.Host.Controllers
lock (databaseContext) //cleaner this way
databaseContext.RevisionInformations.Add(revisionInfo);
}
revisionInfo.OriginCommitSha = revisionInfo.OriginCommitSha ?? lastOriginCommitSha ?? repository.Head;
revisionInfo.OriginCommitSha = revisionInfo.OriginCommitSha ?? lastOriginCommitSha;
if (revisionInfo.OriginCommitSha == null)
{
revisionInfo.OriginCommitSha = repoSha;
Logger.LogWarning(Components.Repository.Repository.OriginTrackingErrorTemplate, repoSha);
}
revInfoSink?.Invoke(revisionInfo);
return needsDbUpdate;
}
static async Task<bool> PopulateApi(Repository model, Components.Repository.IRepository repository, IDatabaseContext databaseContext, Models.Instance instance, CancellationToken cancellationToken)
async Task<bool> PopulateApi(Repository model, Components.Repository.IRepository repository, IDatabaseContext databaseContext, Models.Instance instance, CancellationToken cancellationToken)
{
if (repository.IsGitHubRepository)
{
@@ -381,9 +386,33 @@ namespace Tgstation.Server.Host.Controllers
//this is just db stuf so stow it away
await DatabaseContext.Save(cancellationToken).ConfigureAwait(false);
//format the job description
string description = null;
if (model.UpdateFromOrigin == true)
if (model.Reference != null)
description = String.Format(CultureInfo.InvariantCulture, "Fetch and hard reset repsitory to origin/{0}", model.Reference);
else if (model.CheckoutSha != null)
description = String.Format(CultureInfo.InvariantCulture, "Fetch and checkout {0} in repository", model.CheckoutSha);
else
description = "Pull current repository reference";
else if (model.Reference != null || model.CheckoutSha != null)
description = String.Format(CultureInfo.InvariantCulture, "Checkout repository {0} {1}", model.Reference != null ? "reference" : "SHA", model.Reference ?? model.CheckoutSha);
if (newTestMerges)
description = String.Format(CultureInfo.InvariantCulture, "{0}est merge pull request(s) {1}{2}",
description != null ? String.Format(CultureInfo.InvariantCulture, "{0} and t", description) : "T",
String.Join(", ", model.NewTestMerges.Select(x =>
String.Format(CultureInfo.InvariantCulture, "#{0}{1}", x.Number,
x.PullRequestRevision != null ? String.Format(CultureInfo.InvariantCulture, " {0}", x.PullRequestRevision.Substring(0, 7)) : String.Empty))),
description != null ? String.Empty : " in repository");
if (description == null)
//no git changes
return Json(api);
var job = new Models.Job
{
Description = "Apply repository changes",
Description = description,
StartedBy = AuthenticationContext.User,
Instance = Instance,
CancelRightsType = RightsType.Repository,