-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathICloner.cs
56 lines (50 loc) · 1.76 KB
/
ICloner.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Concurrent;
using System.IO;
using AutoCloner.VsOnline.Dto;
namespace AutoCloner.VsOnline
{
public interface ICloner
{
CloneResult CloneIfNotExists(string projectName, string baseDir, Repository repo, long? maxRepoSizeToClone);
}
public class GitCloner : ICloner
{
private readonly ILogger<GitCloner> logger;
private readonly IGitRunner gitRunner;
public GitCloner(ILogger<GitCloner> logger, IGitRunner gitRunner)
{
this.logger = logger;
this.gitRunner = gitRunner;
}
public CloneResult CloneIfNotExists(string projectName, string baseDir, Repository repo, long? maxRepoSizeToClone)
{
var result = new CloneResult(projectName) { Name = repo.Name, Status = CloneStatus.Exception };
if (maxRepoSizeToClone.HasValue && repo.Size > maxRepoSizeToClone.Value)
{
result.Status = CloneStatus.ExceededMaxRepositorySizeCheck;
return result;
}
try
{
result.ClonePath = Path.Combine(baseDir, repo.Name);
if (!Directory.Exists(result.ClonePath))
{
gitRunner.Clone(repo.RemoteUrl, baseDir);
result.Status = CloneStatus.Success;
}
else
{
result.Status = CloneStatus.FolderExists;
}
}
catch (Exception ex)
{
logger.LogError(ex, $"Failure while cloning {repo.Name} - {repo.RemoteUrl}");
result.Status = CloneStatus.Exception;
}
return result;
}
}
}