Merge pull request #1050 from tgstation/1044-RecusiveClone

Add support for disabling submodule cloning
This commit is contained in:
Jordan Brown
2020-06-13 22:22:39 -04:00
committed by GitHub
6 changed files with 43 additions and 7 deletions
@@ -11,14 +11,14 @@ namespace Tgstation.Server.Api.Models.Internal
/// The revision sha
/// </summary>
[Required]
[StringLength(40)]
[StringLength(Limits.MaximumCommitShaLength)]
public string? CommitSha { get; set; }
/// <summary>
/// The sha of the most recent remote commit
/// </summary>
[Required]
[StringLength(40)]
[StringLength(Limits.MaximumCommitShaLength)]
public string? OriginCommitSha { get; set; }
}
}
@@ -14,5 +14,10 @@
/// Length limit for <see cref="Internal.ChatBot.Name"/>s.
/// </summary>
public const int MaximumIndexableStringLength = 100;
/// <summary>
/// Length limit for git commit SHAs.
/// </summary>
public const int MaximumCommitShaLength = 40;
}
}
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Tgstation.Server.Api.Models
{
@@ -12,9 +13,15 @@ namespace Tgstation.Server.Api.Models
/// </summary>
public string? Origin { get; set; }
/// <summary>
/// If submodules should be recursively cloned.
/// </summary>
public bool? RecurseSubmodules { get; set; }
/// <summary>
/// The commit HEAD should point to. Not populated in responses, use <see cref="RevisionInformation"/> instead for retrieval
/// </summary>
[StringLength(Limits.MaximumCommitShaLength)]
public string? CheckoutSha { get; set; }
/// <summary>
@@ -45,6 +52,7 @@ namespace Tgstation.Server.Api.Models
/// <summary>
/// The branch or tag HEAD points to
/// </summary>
[StringLength(Limits.MaximumStringLength)]
public string? Reference { get; set; }
/// <summary>
@@ -15,7 +15,7 @@ namespace Tgstation.Server.Host.Components.Repository
bool InUse { get; }
/// <summary>
/// If a <see cref="CloneRepository(Uri, string, string, string, Action{int}, CancellationToken)"/> operation is in progress
/// If a <see cref="CloneRepository(Uri, string, string, string, Action{int}, bool, CancellationToken)"/> operation is in progress.
/// </summary>
bool CloneInProgress { get; }
@@ -34,9 +34,17 @@ namespace Tgstation.Server.Host.Components.Repository
/// <param name="username">The username to clone from <paramref name="url"/></param>
/// <param name="password">The password to clone from <paramref name="url"/></param>
/// <param name="progressReporter">A function to report 0-100 progress of the clone</param>
/// <param name="recurseSubmodules">If submodules should be recusively cloned and initialized.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>The newly cloned <see cref="IRepository"/>, <see langword="null"/> if one already exists</returns>
Task<IRepository> CloneRepository(Uri url, string initialBranch, string username, string password, Action<int> progressReporter, CancellationToken cancellationToken);
Task<IRepository> CloneRepository(
Uri url,
string initialBranch,
string username,
string password,
Action<int> progressReporter,
bool recurseSubmodules,
CancellationToken cancellationToken);
/// <summary>
/// Delete the current repository
@@ -89,7 +89,14 @@ namespace Tgstation.Server.Host.Components.Repository
}
/// <inheritdoc />
public async Task<IRepository> CloneRepository(Uri url, string initialBranch, string username, string password, Action<int> progressReporter, CancellationToken cancellationToken)
public async Task<IRepository> CloneRepository(
Uri url,
string initialBranch,
string username,
string password,
Action<int> progressReporter,
bool recurseSubmodules,
CancellationToken cancellationToken)
{
if (url == null)
throw new ArgumentNullException(nameof(url));
@@ -122,7 +129,7 @@ namespace Tgstation.Server.Host.Components.Repository
progressReporter((int)percentage);
return !cancellationToken.IsCancellationRequested;
},
RecurseSubmodules = true,
RecurseSubmodules = recurseSubmodules,
OnUpdateTips = (a, b, c) => !cancellationToken.IsCancellationRequested,
RepositoryOperationStarting = (a) => !cancellationToken.IsCancellationRequested,
BranchName = initialBranch,
@@ -204,7 +204,15 @@ namespace Tgstation.Server.Host.Controllers
var api = currentModel.ToApi();
await jobManager.RegisterOperation(job, async (paramJob, databaseContextFactory, progressReporter, ct) =>
{
using var repos = await repoManager.CloneRepository(new Uri(origin), cloneBranch, currentModel.AccessUser, currentModel.AccessToken, progressReporter, ct).ConfigureAwait(false);
using var repos = await repoManager.CloneRepository(
new Uri(origin),
cloneBranch,
currentModel.AccessUser,
currentModel.AccessToken,
progressReporter,
model.RecurseSubmodules ?? true,
ct)
.ConfigureAwait(false);
if (repos == null)
throw new JobException(ErrorCode.RepoExists);
var instance = new Models.Instance