From e2e63696932352f7b31149da178f7e04d9775b96 Mon Sep 17 00:00:00 2001 From: juliangiebel Date: Wed, 13 Sep 2023 11:32:02 +0200 Subject: [PATCH] Work on ssh support for repositories --- .../Configuration/GitConfiguration.cs | 26 ++++++++++++++----- SS14.MapServer/Services/GitService.cs | 18 +++++++++---- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/SS14.MapServer/Configuration/GitConfiguration.cs b/SS14.MapServer/Configuration/GitConfiguration.cs index 68664fe..2a08cd5 100644 --- a/SS14.MapServer/Configuration/GitConfiguration.cs +++ b/SS14.MapServer/Configuration/GitConfiguration.cs @@ -5,9 +5,9 @@ public sealed class GitConfiguration public const string Name = "Git"; public string RepositoryUrl { get; set; } = string.Empty; - + public string Branch { get; set; } = "master"; - + /// /// If true the map server will retrieve the list of changed maps from the github diff api. /// If this is false all maps will get updated on every push. @@ -24,13 +24,13 @@ public sealed class GitConfiguration { "Resources/Maps/*.yml" }; - + /// /// Glob patterns for excluding specific map files /// public List MapFileExcludePatterns { get; set; } = new(); - + /// /// Prevent updating maps when there where any c# files changed. /// @@ -48,9 +48,23 @@ public sealed class GitConfiguration { "**/*.cs" }; - + /// /// Setting this to true enables listening to the PullRequest event for putting the rendered map as a comment into the PR /// public bool RunOnPullRequests { get; set; } = true; -} \ No newline at end of file + + /// + /// The identity git will use to pull changes with. This doesn't have an effect on anything but is required + /// for pulling changes in some situations + /// + public GitIdentity Identity { get; set; } = new GitIdentity("ss14.mapserver", "git@mapserver.localhost"); + + /// + /// The ssh command used by git if set. Used for providing an ssh key to use. + /// "ssh -i [path to ssh key]" + /// + public string? SshCommand { get; set; } + + public record GitIdentity(string Name, string Email); +} diff --git a/SS14.MapServer/Services/GitService.cs b/SS14.MapServer/Services/GitService.cs index 55cb7fa..127d9cd 100644 --- a/SS14.MapServer/Services/GitService.cs +++ b/SS14.MapServer/Services/GitService.cs @@ -67,7 +67,9 @@ public static string StripRef(string gitRef) private void Clone(string repoUrl, string directory, string gitRef) { _log.Information("Cloning branch/commit {Ref}...", gitRef); - var repoDirectory = Repository.Clone(repoUrl, directory, new CloneOptions + + + /*var repoDirectory = Repository.Clone(repoUrl, directory, new CloneOptions { RecurseSubmodules = true, OnProgress = LogProgress @@ -85,7 +87,7 @@ private void Clone(string repoUrl, string directory, string gitRef) }, null); - Commands.Checkout(repository, StripRef(gitRef)); + Commands.Checkout(repository, StripRef(gitRef));*/ _log.Information("Done cloning"); } @@ -95,10 +97,16 @@ private void Pull(string repoDirectory, string gitRef) _log.Debug("Opening repository in: {RepositoryPath}", repoDirectory); using var repository = new Repository(repoDirectory); - //Set a dummy identity + //Set an identity _log.Debug("Setting identity"); - repository.Config.Set("user.name", "ss14.mapserver"); - repository.Config.Set("user.email", "git@mapserver.localhost"); + repository.Config.Set("user.name", _configuration.Identity.Name); + repository.Config.Set("user.email", _configuration.Identity.Email); + + if (_configuration.SshCommand != null) + { + _log.Debug("Setting ssh command"); + repository.Config.Set("core.sshcommand", _configuration.SshCommand); + } _log.Debug("Fetching ref"); _buildService.Run(repoDirectory, "git", new List { "fetch -fu origin", gitRef }).Wait();