Skip to content

Commit

Permalink
Work on ssh support for repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangiebel committed Sep 13, 2023
1 parent 71c0d22 commit e2e6369
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
26 changes: 20 additions & 6 deletions SS14.MapServer/Configuration/GitConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/// <summary>
/// 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.
Expand All @@ -24,13 +24,13 @@ public sealed class GitConfiguration
{
"Resources/Maps/*.yml"
};

/// <summary>
/// Glob patterns for excluding specific map files
/// </summary>
public List<string> MapFileExcludePatterns { get; set; } = new();


/// <summary>
/// Prevent updating maps when there where any c# files changed.
/// </summary>
Expand All @@ -48,9 +48,23 @@ public sealed class GitConfiguration
{
"**/*.cs"
};

/// <summary>
/// Setting this to true enables listening to the PullRequest event for putting the rendered map as a comment into the PR
/// </summary>
public bool RunOnPullRequests { get; set; } = true;
}

/// <summary>
/// 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
/// </summary>
public GitIdentity Identity { get; set; } = new GitIdentity("ss14.mapserver", "git@mapserver.localhost");

/// <summary>
/// The ssh command used by git if set. Used for providing an ssh key to use.
/// <example>"ssh -i [path to ssh key]"</example>
/// </summary>
public string? SshCommand { get; set; }

public record GitIdentity(string Name, string Email);
}
18 changes: 13 additions & 5 deletions SS14.MapServer/Services/GitService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");
}

Expand All @@ -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<string> { "fetch -fu origin", gitRef }).Wait();
Expand Down

0 comments on commit e2e6369

Please sign in to comment.