Skip to content

Commit

Permalink
Rollout 2024-12-03 (#4207)
Browse files Browse the repository at this point in the history
Co-authored-by: Pavel Purma <[email protected]>
Co-authored-by: Přemek Vysoký <[email protected]>
Co-authored-by: Oleksandr Didyk <[email protected]>
  • Loading branch information
4 people authored Dec 3, 2024
1 parent 7256251 commit c66800d
Show file tree
Hide file tree
Showing 110 changed files with 1,107 additions and 719 deletions.
1 change: 1 addition & 0 deletions docs/DevGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
('https://github.com/maestro-auth-test/maestro-test', 289474),
('https://github.com/maestro-auth-test/maestro-test2', 289474),
('https://github.com/maestro-auth-test/maestro-test3', 289474),
('https://github.com/maestro-auth-test/maestro-test-vmr', 289474),
('https://github.com/maestro-auth-test/arcade', 289474),
('https://github.com/maestro-auth-test/dnceng-vmr', 289474);
```
Expand Down
2 changes: 1 addition & 1 deletion src/Maestro/DependencyUpdater/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static void Configure(IServiceCollection services)

services.AddTransient<IProcessManager>(sp => ActivatorUtilities.CreateInstance<ProcessManager>(sp, "git"));
services.AddTransient<IVersionDetailsParser, VersionDetailsParser>();
services.AddScoped<IRemoteFactory, DarcRemoteFactory>();
services.AddScoped<IRemoteFactory, RemoteFactory>();
services.AddTransient<IBasicBarClient, SqlBarClient>();
services.AddKustoClientProvider("Kusto");
// TODO (https://github.com/dotnet/arcade-services/issues/3880) - Remove subscriptionIdGenerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,53 +13,56 @@

namespace Maestro.DataProviders;

public class DarcRemoteFactory : IRemoteFactory
public class RemoteFactory : IRemoteFactory
{
private readonly IVersionDetailsParser _versionDetailsParser;
private readonly OperationManager _operations;
private readonly IProcessManager _processManager;
private readonly ILoggerFactory _loggerFactory;
private readonly BuildAssetRegistryContext _context;
private readonly DarcRemoteMemoryCache _cache;
private readonly IGitHubTokenProvider _gitHubTokenProvider;
private readonly IAzureDevOpsTokenProvider _azdoTokenProvider;

public DarcRemoteFactory(
public RemoteFactory(
BuildAssetRegistryContext context,
IGitHubTokenProvider gitHubTokenProvider,
IAzureDevOpsTokenProvider azdoTokenProvider,
IVersionDetailsParser versionDetailsParser,
DarcRemoteMemoryCache memoryCache,
OperationManager operations,
IProcessManager processManager)
IProcessManager processManager,
ILoggerFactory loggerFactory)
{
_operations = operations;
_processManager = processManager;
_loggerFactory = loggerFactory;
_versionDetailsParser = versionDetailsParser;
_context = context;
_gitHubTokenProvider = gitHubTokenProvider;
_azdoTokenProvider = azdoTokenProvider;
_cache = memoryCache;
}

public async Task<IRemote> GetRemoteAsync(string repoUrl, ILogger logger)
public async Task<IRemote> CreateRemoteAsync(string repoUrl)
{
using (_operations.BeginOperation($"Getting remote for repo {repoUrl}."))
{
IRemoteGitRepo remoteGitClient = await GetRemoteGitClient(repoUrl, logger);
return new Remote(remoteGitClient, _versionDetailsParser, logger);
IRemoteGitRepo remoteGitClient = await GetRemoteGitClient(repoUrl);
return new Remote(remoteGitClient, _versionDetailsParser, _loggerFactory.CreateLogger<IRemote>());
}
}

public async Task<IDependencyFileManager> GetDependencyFileManagerAsync(string repoUrl, ILogger logger)
public async Task<IDependencyFileManager> CreateDependencyFileManagerAsync(string repoUrl)
{
using (_operations.BeginOperation($"Getting remote file manager for repo {repoUrl}."))
{
IRemoteGitRepo remoteGitClient = await GetRemoteGitClient(repoUrl, logger);
return new DependencyFileManager(remoteGitClient, _versionDetailsParser, logger);
IRemoteGitRepo remoteGitClient = await GetRemoteGitClient(repoUrl);
return new DependencyFileManager(remoteGitClient, _versionDetailsParser, _loggerFactory.CreateLogger<IRemote>());
}
}

private async Task<IRemoteGitRepo> GetRemoteGitClient(string repoUrl, ILogger logger)
private async Task<IRemoteGitRepo> GetRemoteGitClient(string repoUrl)
{
// Normalize the url with the AzDO client prior to attempting to
// get a token. When we do coherency updates we build a repo graph and
Expand All @@ -81,10 +84,13 @@ private async Task<IRemoteGitRepo> GetRemoteGitClient(string repoUrl, ILogger lo
: new GitHubClient(
new Microsoft.DotNet.DarcLib.GitHubTokenProvider(_gitHubTokenProvider),
_processManager,
logger,
_loggerFactory.CreateLogger<GitHubClient>(),
_cache.Cache),

GitRepoType.AzureDevOps => new AzureDevOpsClient(_azdoTokenProvider, _processManager, logger),
GitRepoType.AzureDevOps => new AzureDevOpsClient(
_azdoTokenProvider,
_processManager,
_loggerFactory.CreateLogger<AzureDevOpsClient>()),

_ => throw new NotImplementedException($"Unknown repo url type {normalizedUrl}"),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public async Task<IActionResult> GetCommit(int buildId)
return NotFound();
}

IRemote remote = await Factory.GetRemoteAsync(build.AzureDevOpsRepository ?? build.GitHubRepository, null);
IRemote remote = await Factory.CreateRemoteAsync(build.AzureDevOpsRepository ?? build.GitHubRepository);
Microsoft.DotNet.DarcLib.Commit commit = await remote.GetCommitAsync(build.AzureDevOpsRepository ?? build.GitHubRepository, build.Commit);
return Ok(new Maestro.Api.Model.v2020_02_20.Commit(commit.Author, commit.Sha, commit.Message));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Maestro/Maestro.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public override void ConfigureServices(IServiceCollection services)
sp.GetRequiredService<ILogger<ProcessManager>>(),
"git"));
services.AddTransient<IVersionDetailsParser, VersionDetailsParser>();
services.AddScoped<IRemoteFactory, DarcRemoteFactory>();
services.AddScoped<IRemoteFactory, RemoteFactory>();
services.AddTransient<IBasicBarClient, SqlBarClient>();
services.AddSingleton(typeof(IActorProxyFactory<>), typeof(ActorProxyFactory<>));

Expand Down
23 changes: 13 additions & 10 deletions src/Maestro/SubscriptionActorService/DarcRemoteFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class DarcRemoteFactory : IRemoteFactory
private readonly IVersionDetailsParser _versionDetailsParser;
private readonly IProcessManager _processManager;
private readonly OperationManager _operations;
private readonly ILoggerFactory _loggerFactory;

public DarcRemoteFactory(
IConfiguration configuration,
Expand All @@ -37,38 +38,40 @@ public DarcRemoteFactory(
TemporaryFiles tempFiles,
IVersionDetailsParser versionDetailsParser,
IProcessManager processManager,
OperationManager operations)
OperationManager operations,
ILoggerFactory loggerFactory)
{
_tempFiles = tempFiles;
_versionDetailsParser = versionDetailsParser;
_processManager = processManager;
_operations = operations;
_loggerFactory = loggerFactory;
_configuration = configuration;
_gitHubTokenProvider = gitHubTokenProvider;
_azureDevOpsTokenProvider = azureDevOpsTokenProvider;
_cache = memoryCache;
_context = context;
}

public async Task<IRemote> GetRemoteAsync(string repoUrl, ILogger logger)
public async Task<IRemote> CreateRemoteAsync(string repoUrl)
{
using (_operations.BeginOperation($"Getting remote for repo {repoUrl}."))
{
IRemoteGitRepo remoteGitClient = await GetRemoteGitClient(repoUrl, logger);
return new Remote(remoteGitClient, _versionDetailsParser, logger);
IRemoteGitRepo remoteGitClient = await CreateRemoteGitClient(repoUrl);
return new Remote(remoteGitClient, _versionDetailsParser, _loggerFactory.CreateLogger<IRemote>());
}
}

public async Task<IDependencyFileManager> GetDependencyFileManagerAsync(string repoUrl, ILogger logger)
public async Task<IDependencyFileManager> CreateDependencyFileManagerAsync(string repoUrl)
{
using (_operations.BeginOperation($"Getting remote file manager for repo {repoUrl}."))
{
IRemoteGitRepo remoteGitClient = await GetRemoteGitClient(repoUrl, logger);
return new DependencyFileManager(remoteGitClient, _versionDetailsParser, logger);
IRemoteGitRepo remoteGitClient = await CreateRemoteGitClient(repoUrl);
return new DependencyFileManager(remoteGitClient, _versionDetailsParser, _loggerFactory.CreateLogger<IRemote>());
}
}

private async Task<IRemoteGitRepo> GetRemoteGitClient(string repoUrl, ILogger logger)
private async Task<IRemoteGitRepo> CreateRemoteGitClient(string repoUrl)
{
// Normalize the url with the AzDO client prior to attempting to
// get a token. When we do coherency updates we build a repo graph and
Expand Down Expand Up @@ -98,14 +101,14 @@ private async Task<IRemoteGitRepo> GetRemoteGitClient(string repoUrl, ILogger lo
: new GitHubClient(
new ResolvedTokenProvider(await _gitHubTokenProvider.GetTokenForInstallationAsync(installationId)),
_processManager,
logger,
_loggerFactory.CreateLogger<IRemote>(),
temporaryRepositoryRoot,
_cache.Cache),

GitRepoType.AzureDevOps => new AzureDevOpsClient(
_azureDevOpsTokenProvider,
_processManager,
logger,
_loggerFactory.CreateLogger<IRemote>(),
temporaryRepositoryRoot),

_ => throw new NotImplementedException($"Unknown repo url type {normalizedUrl}"),
Expand Down
8 changes: 4 additions & 4 deletions src/Maestro/SubscriptionActorService/PullRequestActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ private async Task<ActionResult<SynchronizePullRequestResult>> SynchronizePullRe
}

(string targetRepository, _) = await GetTargetAsync();
IRemote remote = await _remoteFactory.GetRemoteAsync(targetRepository, _logger);
IRemote remote = await _remoteFactory.CreateRemoteAsync(targetRepository);

_logger.LogInformation("Getting status for Pull Request: {url}", prUrl);
PrStatus status = await remote.GetPullRequestStatusAsync(prUrl);
Expand Down Expand Up @@ -704,7 +704,7 @@ public async Task<ActionResult<object>> UpdateAssetsAsync(
{
(string targetRepository, string targetBranch) = await GetTargetAsync();

IRemote darcRemote = await _remoteFactory.GetRemoteAsync(targetRepository, _logger);
IRemote darcRemote = await _remoteFactory.CreateRemoteAsync(targetRepository);

TargetRepoDependencyUpdate repoDependencyUpdate =
await GetRequiredUpdates(updates, _remoteFactory, targetRepository, prBranch: null, targetBranch);
Expand Down Expand Up @@ -805,7 +805,7 @@ private async Task UpdatePullRequestAsync(InProgressPullRequest pr, List<UpdateA

_logger.LogInformation("Updating Pull Request {url} branch {targetBranch} in {targetRepository}", pr.Url, targetBranch, targetRepository);

IRemote darcRemote = await _remoteFactory.GetRemoteAsync(targetRepository, _logger);
IRemote darcRemote = await _remoteFactory.CreateRemoteAsync(targetRepository);
PullRequest pullRequest = await darcRemote.GetPullRequestAsync(pr.Url);

TargetRepoDependencyUpdate targetRepositoryUpdates =
Expand Down Expand Up @@ -955,7 +955,7 @@ private async Task<TargetRepoDependencyUpdate> GetRequiredUpdates(
{
_logger.LogInformation("Getting Required Updates for {branch} of {targetRepository}", targetBranch, targetRepository);
// Get a remote factory for the target repo
IRemote darc = await remoteFactory.GetRemoteAsync(targetRepository, _logger);
IRemote darc = await remoteFactory.CreateRemoteAsync(targetRepository);

TargetRepoDependencyUpdate repoDependencyUpdate = new();

Expand Down
2 changes: 1 addition & 1 deletion src/Maestro/SubscriptionActorService/PullRequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public async Task<string> CalculatePRDescriptionAndCommitUpdatesAsync(
(UpdateAssetsParameters update, List<DependencyUpdate> deps) coherencyUpdate =
requiredUpdates.Where(u => u.update.IsCoherencyUpdate).SingleOrDefault();

IRemote remote = await _remoteFactory.GetRemoteAsync(targetRepository, _logger);
IRemote remote = await _remoteFactory.CreateRemoteAsync(targetRepository);
var locationResolver = new AssetLocationResolver(_barClient);

// To keep a PR to as few commits as possible, if the number of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async Task TagSourceRepositoryGitHubContactsAsync(InProgressPullRequest p
return;
}

var darcRemote = await _remoteFactory.GetRemoteAsync($"https://github.com/{owner}/{repo}", _logger);
var darcRemote = await _remoteFactory.CreateRemoteAsync($"https://github.com/{owner}/{repo}");
var darcSubscriptionObject = await _barClient.GetSubscriptionAsync(subscriptionFromPr.SubscriptionId);
string sourceRepository = darcSubscriptionObject.SourceRepository;
string targetRepository = darcSubscriptionObject.TargetRepository;
Expand Down
37 changes: 15 additions & 22 deletions src/Microsoft.DotNet.Darc/Darc/Helpers/RemoteFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,29 @@ namespace Microsoft.DotNet.Darc.Helpers;

internal class RemoteFactory : IRemoteFactory
{
private readonly ILoggerFactory _loggerFactory;
private readonly ICommandLineOptions _options;

public RemoteFactory(ICommandLineOptions options)
public RemoteFactory(ILoggerFactory loggerFactory, ICommandLineOptions options)
{
_loggerFactory = loggerFactory;
_options = options;
}

public static IRemote GetRemote(ICommandLineOptions options, string repoUrl, ILogger logger)
public Task<IRemote> CreateRemoteAsync(string repoUrl)
{
IRemoteGitRepo gitClient = GetRemoteGitClient(options, repoUrl, logger);
return new Remote(gitClient, new VersionDetailsParser(), logger);
IRemoteGitRepo gitClient = CreateRemoteGitClient(_options, repoUrl);
return Task.FromResult<IRemote>(new Remote(gitClient, new VersionDetailsParser(), _loggerFactory.CreateLogger<IRemote>()));
}

public static IBarApiClient GetBarClient(ICommandLineOptions options)
=> new BarApiClient(
options.BuildAssetRegistryToken,
managedIdentityId: null,
options.IsCi,
options.BuildAssetRegistryBaseUri);

public Task<IRemote> GetRemoteAsync(string repoUrl, ILogger logger)
=> Task.FromResult(GetRemote(_options, repoUrl, logger));

public Task<IDependencyFileManager> GetDependencyFileManagerAsync(string repoUrl, ILogger logger)
public Task<IDependencyFileManager> CreateDependencyFileManagerAsync(string repoUrl)
{
IRemoteGitRepo gitClient = GetRemoteGitClient(_options, repoUrl, logger);
return Task.FromResult<IDependencyFileManager>(new DependencyFileManager(gitClient, new VersionDetailsParser(), logger));
IRemoteGitRepo gitClient = CreateRemoteGitClient(_options, repoUrl);
var dfm = new DependencyFileManager(gitClient, new VersionDetailsParser(), _loggerFactory.CreateLogger<IDependencyFileManager>());
return Task.FromResult<IDependencyFileManager>(dfm);
}

private static IRemoteGitRepo GetRemoteGitClient(ICommandLineOptions options, string repoUrl, ILogger logger)
private IRemoteGitRepo CreateRemoteGitClient(ICommandLineOptions options, string repoUrl)
{
string temporaryRepositoryRoot = Path.GetTempPath();

Expand All @@ -52,17 +45,17 @@ private static IRemoteGitRepo GetRemoteGitClient(ICommandLineOptions options, st
GitRepoType.GitHub =>
new GitHubClient(
options.GetGitHubTokenProvider(),
new ProcessManager(logger, options.GitLocation),
logger,
new ProcessManager(_loggerFactory.CreateLogger<IProcessManager>(), options.GitLocation),
_loggerFactory.CreateLogger<GitHubClient>(),
temporaryRepositoryRoot,
// Caching not in use for Darc local client.
null),

GitRepoType.AzureDevOps =>
new AzureDevOpsClient(
options.GetAzdoTokenProvider(),
new ProcessManager(logger, options.GitLocation),
logger,
new ProcessManager(_loggerFactory.CreateLogger<IProcessManager>(), options.GitLocation),
_loggerFactory.CreateLogger<AzureDevOpsClient>(),
temporaryRepositoryRoot),

_ => throw new System.InvalidOperationException($"Cannot create a remote of type {repoType}"),
Expand Down
10 changes: 5 additions & 5 deletions src/Microsoft.DotNet.Darc/Darc/Helpers/UxManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public UxManager(string gitLocation, ILogger logger)
/// </summary>
/// <param name="popUp">Popup to run</param>
/// <returns>Success or error code</returns>
public int ReadFromStdIn(EditorPopUp popUp)
public async Task<int> ReadFromStdIn(EditorPopUp popUp)
{
int result;
try
Expand All @@ -46,7 +46,7 @@ public int ReadFromStdIn(EditorPopUp popUp)
string dirPath = Path.GetDirectoryName(path);

Directory.CreateDirectory(dirPath);
using (StreamWriter streamWriter = new StreamWriter(path))
using (var streamWriter = new StreamWriter(path))
{
string line;
while ((line = Console.ReadLine()) != null)
Expand All @@ -57,7 +57,7 @@ public int ReadFromStdIn(EditorPopUp popUp)

// Now run the closed event and process the contents
IList<Line> contents = EditorPopUp.OnClose(path);
result = popUp.ProcessContents(contents);
result = await popUp.ProcessContents(contents);
Directory.Delete(dirPath, true);
if (result != Constants.SuccessCode)
{
Expand Down Expand Up @@ -107,11 +107,11 @@ public int PopUp(EditorPopUp popUp)
{
_popUpClosed = false;
process.EnableRaisingEvents = true;
process.Exited += (sender, e) =>
process.Exited += async (sender, e) =>
{
IList<Line> contents = EditorPopUp.OnClose(path);

result = popUp.ProcessContents(contents);
result = await popUp.ProcessContents(contents);

// If succeeded, delete the temp file, otherwise keep it around
// for another popup iteration.
Expand Down
Loading

0 comments on commit c66800d

Please sign in to comment.