|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +using System; |
| 5 | +using Microsoft.DotNet.DarcLib; |
| 6 | +using Microsoft.DotNet.DarcLib.Helpers; |
| 7 | +using Microsoft.DotNet.DarcLib.VirtualMonoRepo; |
| 8 | +using Microsoft.Extensions.Logging; |
| 9 | + |
| 10 | +namespace Microsoft.DotNet.VirtualMonoRepo.Tasks; |
| 11 | + |
| 12 | +public class GitFileManagerFactory : IGitFileManagerFactory |
| 13 | +{ |
| 14 | + private readonly IVmrInfo _vmrInfo; |
| 15 | + private readonly VmrRemoteConfiguration _remoteConfiguration; |
| 16 | + private readonly IProcessManager _processManager; |
| 17 | + private readonly IVersionDetailsParser _versionDetailsParser; |
| 18 | + private readonly ILoggerFactory _loggerFactory; |
| 19 | + |
| 20 | + public GitFileManagerFactory( |
| 21 | + IVmrInfo vmrInfo, |
| 22 | + VmrRemoteConfiguration remoteConfiguration, |
| 23 | + IProcessManager processManager, |
| 24 | + IVersionDetailsParser versionDetailsParser, |
| 25 | + ILoggerFactory loggerFactory) |
| 26 | + { |
| 27 | + _vmrInfo = vmrInfo; |
| 28 | + _remoteConfiguration = remoteConfiguration; |
| 29 | + _processManager = processManager; |
| 30 | + _versionDetailsParser = versionDetailsParser; |
| 31 | + _loggerFactory = loggerFactory; |
| 32 | + } |
| 33 | + |
| 34 | + public IGitFileManager Create(string repoUri) |
| 35 | + => new GitFileManager(CreateGitRepo(repoUri), _versionDetailsParser, _loggerFactory.CreateLogger<GitFileManager>()); |
| 36 | + |
| 37 | + private IGitRepo CreateGitRepo(string repoUri) => GitRepoTypeParser.ParseFromUri(repoUri) switch |
| 38 | + { |
| 39 | + GitRepoType.AzureDevOps => throw new Exception("VMR initialization should not require Azure DevOps repositories"), |
| 40 | + |
| 41 | + GitRepoType.GitHub => new GitHubClient( |
| 42 | + _processManager.GitExecutable, |
| 43 | + _remoteConfiguration.GitHubToken, |
| 44 | + _loggerFactory.CreateLogger<GitHubClient>(), |
| 45 | + _vmrInfo.TmpPath, |
| 46 | + // Caching not in use for Darc local client. |
| 47 | + null), |
| 48 | + |
| 49 | + GitRepoType.Local => new LocalGitClient(_processManager.GitExecutable, _loggerFactory.CreateLogger<LocalGitClient>()), |
| 50 | + _ => throw new ArgumentException("Unknown git repository type", nameof(repoUri)), |
| 51 | + }; |
| 52 | +} |
0 commit comments