diff --git a/src/Maestro/FeedCleanerService/Program.cs b/src/Maestro/FeedCleanerService/Program.cs index d54eea75dc..7a93562160 100644 --- a/src/Maestro/FeedCleanerService/Program.cs +++ b/src/Maestro/FeedCleanerService/Program.cs @@ -9,6 +9,7 @@ using Microsoft.DotNet.ServiceFabric.ServiceHost; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; namespace FeedCleanerService; @@ -52,6 +53,9 @@ public static void Configure(IServiceCollection services) services.AddAzureDevOpsTokenProvider(); services.Configure("AzureDevOps", (o, s) => s.Bind(o)); services.AddTransient(); - services.AddTransient(sp => ActivatorUtilities.CreateInstance(sp, "git")); + services.AddTransient(sp => + new ProcessManager( + sp.GetRequiredService>(), + "git")); } } diff --git a/src/Maestro/Maestro.Web/Startup.cs b/src/Maestro/Maestro.Web/Startup.cs index ea4e4fcf3d..b869b446d8 100644 --- a/src/Maestro/Maestro.Web/Startup.cs +++ b/src/Maestro/Maestro.Web/Startup.cs @@ -245,7 +245,10 @@ public override void ConfigureServices(IServiceCollection services) // in such a way that will work with sizing. services.AddSingleton(); - services.AddTransient(sp => ActivatorUtilities.CreateInstance(sp, "git")); + services.AddTransient(sp => + new ProcessManager( + sp.GetRequiredService>(), + "git")); services.AddTransient(); services.AddScoped(); services.AddTransient(); diff --git a/src/Maestro/SubscriptionActorService/DarcRemoteFactory.cs b/src/Maestro/SubscriptionActorService/DarcRemoteFactory.cs index aebea88b17..375273931c 100644 --- a/src/Maestro/SubscriptionActorService/DarcRemoteFactory.cs +++ b/src/Maestro/SubscriptionActorService/DarcRemoteFactory.cs @@ -94,8 +94,6 @@ private async Task GetRemoteGitClient(string repoUrl, ILogger lo throw new GithubApplicationInstallationException($"No installation is available for repository '{normalizedUrl}'"); } - var gitExe = _localGit.GetPathToLocalGit(); - return GitRepoUrlParser.ParseTypeFromUri(normalizedUrl) switch { GitRepoType.GitHub => installationId == default diff --git a/src/Maestro/SubscriptionActorService/Program.cs b/src/Maestro/SubscriptionActorService/Program.cs index e8bff9edfa..6b94205759 100644 --- a/src/Maestro/SubscriptionActorService/Program.cs +++ b/src/Maestro/SubscriptionActorService/Program.cs @@ -40,7 +40,8 @@ private static void Main() public static void Configure(IServiceCollection services) { services.TryAddTransient(sp => sp.GetRequiredService>()); - services.AddTransient(sp => ActivatorUtilities.CreateInstance(sp, "git")); + services.AddTransient(sp => + ActivatorUtilities.CreateInstance(sp, sp.GetRequiredService().GetPathToLocalGit())); services.AddSingleton(); services.AddSingleton(); services.AddTransient(); diff --git a/src/Microsoft.DotNet.Darc/DarcLib/GitHubClient.cs b/src/Microsoft.DotNet.Darc/DarcLib/GitHubClient.cs index 659c427702..36c3118e2f 100644 --- a/src/Microsoft.DotNet.Darc/DarcLib/GitHubClient.cs +++ b/src/Microsoft.DotNet.Darc/DarcLib/GitHubClient.cs @@ -115,6 +115,7 @@ private async Task GetFileContentsAsync(string owner, string repo, strin { using (HttpResponseMessage response = await ExecuteRemoteGitCommandAsync( HttpMethod.Get, + $"https://github.com/{owner}/{repo}", $"repos/{owner}/{repo}/contents/{filePath}?ref={branch}", _logger, logFailure: false)) @@ -160,6 +161,7 @@ public async Task CreateBranchAsync(string repoUri, string newBranch, string bas using (await ExecuteRemoteGitCommandAsync( HttpMethod.Get, + $"https://github.com/{owner}/{repo}", $"repos/{owner}/{repo}/branches/{newBranch}", _logger, retryCount: 0)) { } @@ -168,6 +170,7 @@ public async Task CreateBranchAsync(string repoUri, string newBranch, string bas body = JsonConvert.SerializeObject(githubRef, _serializerSettings); using (await ExecuteRemoteGitCommandAsync( new HttpMethod("PATCH"), + $"https://github.com/{owner}/{repo}", $"repos/{owner}/{repo}/git/{gitRef}", _logger, body)) { } @@ -181,6 +184,7 @@ public async Task CreateBranchAsync(string repoUri, string newBranch, string bas body = JsonConvert.SerializeObject(githubRef, _serializerSettings); using (await ExecuteRemoteGitCommandAsync( HttpMethod.Post, + $"https://github.com/{owner}/{repo}", $"repos/{owner}/{repo}/git/refs", _logger, body)) { } @@ -277,6 +281,7 @@ public async Task> SearchPullRequestsAsync( JObject responseContent; using (HttpResponseMessage response = await ExecuteRemoteGitCommandAsync( HttpMethod.Get, + $"https://github.com/{owner}/{repo}", $"search/issues?q={query}", _logger)) { @@ -300,8 +305,11 @@ public async Task GetPullRequestStatusAsync(string pullRequestUrl) (string owner, string repo, int id) = ParsePullRequestUri(pullRequestUrl); JObject responseContent; - using (HttpResponseMessage response = await ExecuteRemoteGitCommandAsync(HttpMethod.Get, - $"repos/{owner}/{repo}/pulls/{id}", _logger)) + using (HttpResponseMessage response = await ExecuteRemoteGitCommandAsync( + HttpMethod.Get, + $"https://github.com/{owner}/{repo}", + $"repos/{owner}/{repo}/pulls/{id}", + _logger)) { responseContent = JObject.Parse(await response.Content.ReadAsStringAsync()); } @@ -748,6 +756,7 @@ private async Task GetGitItemImpl(string path, TreeItem treeItem, strin /// private async Task ExecuteRemoteGitCommandAsync( HttpMethod method, + string repoUri, string requestUri, ILogger logger, string body = null, @@ -759,7 +768,7 @@ private async Task ExecuteRemoteGitCommandAsync( { retryCount = 0; } - using (HttpClient client = CreateHttpClient()) + using (HttpClient client = CreateHttpClient(repoUri)) { var requestManager = new HttpRequestManager(client, method, requestUri, logger, body, versionOverride, logFailure); try @@ -783,14 +792,14 @@ private async Task ExecuteRemoteGitCommandAsync( /// Create a new http client for talking to github. /// /// New http client CheckIfFileExistsAsync(string repoUri, string filePath JObject content; using (response = await ExecuteRemoteGitCommandAsync( HttpMethod.Get, + $"https://github.com/{owner}/{repo}", $"repos/{owner}/{repo}/contents/{filePath}?ref={branch}", _logger)) { @@ -891,6 +901,7 @@ private async Task GetLastCommitShaAsync(string owner, string repo, stri JObject content; using (HttpResponseMessage response = await ExecuteRemoteGitCommandAsync( HttpMethod.Get, + $"https://github.com/{owner}/{repo}", $"repos/{owner}/{repo}/commits/{branch}", _logger)) { @@ -1102,6 +1113,7 @@ private async Task GetCommitMapForPathAsync( using (HttpResponseMessage response = await ExecuteRemoteGitCommandAsync( HttpMethod.Get, + $"https://github.com/{owner}/{repo}", $"repos/{owner}/{repo}/contents/{path}?ref={assetsProducedInCommit}", _logger)) { @@ -1207,6 +1219,7 @@ public async Task GitDiffAsync(string repoUri, string baseVersion, stri JObject content; using (HttpResponseMessage response = await ExecuteRemoteGitCommandAsync( HttpMethod.Get, + $"https://github.com/{owner}/{repo}", $"repos/{owner}/{repo}/compare/{baseVersion}...{targetVersion}", _logger)) { @@ -1241,6 +1254,7 @@ public async Task RepoExistsAsync(string repoUri) { using (await ExecuteRemoteGitCommandAsync( HttpMethod.Get, + $"https://github.com/{owner}/{repo}", $"repos/{owner}/{repo}", _logger, logFailure: false)) { }