From dba2f81d95f2be5298089f14d2caab6b4b667b65 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Thu, 13 Sep 2018 10:14:20 -0400 Subject: [PATCH 1/5] RepsoitoryController Update now formats job names better --- .../Controllers/RepositoryController.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Tgstation.Server.Host/Controllers/RepositoryController.cs b/src/Tgstation.Server.Host/Controllers/RepositoryController.cs index a5e749c6d4..92bff1cf9b 100644 --- a/src/Tgstation.Server.Host/Controllers/RepositoryController.cs +++ b/src/Tgstation.Server.Host/Controllers/RepositoryController.cs @@ -381,9 +381,29 @@ 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"); + var job = new Models.Job { - Description = "Apply repository changes", + Description = description ?? "Apply repository changes", StartedBy = AuthenticationContext.User, Instance = Instance, CancelRightsType = RightsType.Repository, From 89e3141689bc663bb8562f77fbd2f2c39073a679 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Thu, 13 Sep 2018 10:14:50 -0400 Subject: [PATCH 2/5] RepositoryController Update now returns OK without ActiveJob field if no git changes to make --- .../Controllers/RepositoryController.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Tgstation.Server.Host/Controllers/RepositoryController.cs b/src/Tgstation.Server.Host/Controllers/RepositoryController.cs index 92bff1cf9b..3cc31661ca 100644 --- a/src/Tgstation.Server.Host/Controllers/RepositoryController.cs +++ b/src/Tgstation.Server.Host/Controllers/RepositoryController.cs @@ -401,9 +401,13 @@ namespace Tgstation.Server.Host.Controllers 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 = description ?? "Apply repository changes", + Description = description, StartedBy = AuthenticationContext.User, Instance = Instance, CancelRightsType = RightsType.Repository, From e5d14aaef008649fd210f07a501c86e4e7e9d32e Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Thu, 13 Sep 2018 10:16:14 -0400 Subject: [PATCH 3/5] Update repository POST API docs --- docs/API.dox | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/API.dox b/docs/API.dox index 49c19ce3ee..759c73ff56 100644 --- a/docs/API.dox +++ b/docs/API.dox @@ -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 From de495b1417ad332f7728587c0105d3001aefb554 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Thu, 13 Sep 2018 10:31:52 -0400 Subject: [PATCH 4/5] Adds warnings when the repository takes it's HEAD as an OriginCommitSha --- src/Tgstation.Server.Host/Components/Instance.cs | 1 + .../Components/Repository/Repository.cs | 7 ++++++- .../Controllers/DreamMakerController.cs | 2 ++ .../Controllers/RepositoryController.cs | 11 ++++++++--- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Tgstation.Server.Host/Components/Instance.cs b/src/Tgstation.Server.Host/Components/Instance.cs index 080c469aab..21e7edc06d 100644 --- a/src/Tgstation.Server.Host/Components/Instance.cs +++ b/src/Tgstation.Server.Host/Components/Instance.cs @@ -186,6 +186,7 @@ namespace Tgstation.Server.Host.Components Id = metadata.Id } }; + logger.LogWarning(Repository.Repository.OriginTrackingErrorTemplate, currentSha); db.Instances.Attach(revInfo.Instance); } diff --git a/src/Tgstation.Server.Host/Components/Repository/Repository.cs b/src/Tgstation.Server.Host/Components/Repository/Repository.cs index 1b704da4f5..c29384b083 100644 --- a/src/Tgstation.Server.Host/Components/Repository/Repository.cs +++ b/src/Tgstation.Server.Host/Components/Repository/Repository.cs @@ -18,13 +18,18 @@ namespace Tgstation.Server.Host.Components.Repository /// public const string GitHubUrl = "://github.com/"; - const string UnknownReference = ""; + /// + /// Template error message for when tracking of the most recent origin commit fails + /// + 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."; /// /// The branch name used for publishing testmerge commits /// public const string RemoteTemporaryBranchName = "___TGSTempBranch"; + const string UnknownReference = ""; + /// public bool IsGitHubRepository { get; } diff --git a/src/Tgstation.Server.Host/Controllers/DreamMakerController.cs b/src/Tgstation.Server.Host/Controllers/DreamMakerController.cs index 9341fd8dd3..d2cb696917 100644 --- a/src/Tgstation.Server.Host/Controllers/DreamMakerController.cs +++ b/src/Tgstation.Server.Host/Controllers/DreamMakerController.cs @@ -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); } diff --git a/src/Tgstation.Server.Host/Controllers/RepositoryController.cs b/src/Tgstation.Server.Host/Controllers/RepositoryController.cs index 3cc31661ca..fc916acae6 100644 --- a/src/Tgstation.Server.Host/Controllers/RepositoryController.cs +++ b/src/Tgstation.Server.Host/Controllers/RepositoryController.cs @@ -67,7 +67,7 @@ namespace Tgstation.Server.Host.Controllers generalConfiguration = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions)); } - static async Task LoadRevisionInformation(Components.Repository.IRepository repository, IDatabaseContext databaseContext, Models.Instance instance, string lastOriginCommitSha, Action revInfoSink, CancellationToken cancellationToken) + async Task LoadRevisionInformation(Components.Repository.IRepository repository, IDatabaseContext databaseContext, Models.Instance instance, string lastOriginCommitSha, Action 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 PopulateApi(Repository model, Components.Repository.IRepository repository, IDatabaseContext databaseContext, Models.Instance instance, CancellationToken cancellationToken) + async Task PopulateApi(Repository model, Components.Repository.IRepository repository, IDatabaseContext databaseContext, Models.Instance instance, CancellationToken cancellationToken) { if (repository.IsGitHubRepository) { From e4245866e8307ce94e9d846674612fe93ad1b73e Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Thu, 13 Sep 2018 10:33:47 -0400 Subject: [PATCH 5/5] Do not update OriginCommitSha on an "Up To Date" merge Fixes #627 --- src/Tgstation.Server.Host/Components/Repository/IRepository.cs | 2 +- src/Tgstation.Server.Host/Components/Repository/Repository.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Tgstation.Server.Host/Components/Repository/IRepository.cs b/src/Tgstation.Server.Host/Components/Repository/IRepository.cs index 48f6ff2d06..244ef15f91 100644 --- a/src/Tgstation.Server.Host/Components/Repository/IRepository.cs +++ b/src/Tgstation.Server.Host/Components/Repository/IRepository.cs @@ -105,7 +105,7 @@ namespace Tgstation.Server.Host.Components.Repository /// The name of the merge committer /// The e-mail of the merge committer /// The for the operation - /// A resulting in a representing the merge result that is after a fast forward or up to date, on a merge, on a conflict + /// A resulting in a representing the merge result that is after a fast forward, on a merge or up to date, on a conflict Task MergeOrigin(string committerName, string committerEmail, CancellationToken cancellationToken); /// diff --git a/src/Tgstation.Server.Host/Components/Repository/Repository.cs b/src/Tgstation.Server.Host/Components/Repository/Repository.cs index c29384b083..e8f54cc2a2 100644 --- a/src/Tgstation.Server.Host/Components/Repository/Repository.cs +++ b/src/Tgstation.Server.Host/Components/Repository/Repository.cs @@ -371,7 +371,7 @@ namespace Tgstation.Server.Host.Components.Repository return null; } - return result.Status != MergeStatus.NonFastForward; + return result.Status == MergeStatus.FastForward; } ///