protected override Task <bool> RunInternalAsync(StringBuilder log, IList <string> additionalFiles) { log.Append("Getting Git version..."); GitVersion gitVersion = _git.Version; log.AppendLine(" OK"); log.AppendLine($"Git version is '{gitVersion.OriginalString}'"); log.Append("Locating current repository..."); string thisRepo = _git.GetCurrentRepository(); log.AppendLine(" OK"); log.AppendLine(thisRepo is null ? "Not inside a Git repository." : $"Git repository at '{thisRepo}'"); log.Append("Listing all Git configuration..."); Process configProc = _git.CreateProcess("config --list --show-origin"); configProc.Start(); configProc.WaitForExit(); string gitConfig = configProc.StandardOutput.ReadToEnd().TrimEnd(); log.AppendLine(" OK"); log.AppendLine("Git configuration:"); log.AppendLine(gitConfig); log.AppendLine(); return(Task.FromResult(true)); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { TimeSpan interval; string? intervalStr = _git.GetConfig("policy.interval"); if (!string.IsNullOrWhiteSpace(intervalStr) && int.TryParse(intervalStr, out int intervalSec)) { interval = TimeSpan.FromSeconds(intervalSec); } else { interval = TimeSpan.FromMinutes(30); } _logger.LogInformation("Using polling interval of {0} seconds", interval.TotalSeconds); while (!stoppingToken.IsCancellationRequested) { _logger.LogInformation("Syncing policies..."); using Process proc = _git.CreateProcess("policy sync"); proc.Start(); proc.WaitForExit(); if (proc.ExitCode != 0) { _logger.LogError("Failed to sync policies (exit: {0})", proc.ExitCode); _logger.LogError("stdout: {0}", proc.StandardOutput.ReadToEnd()); _logger.LogError("stderr: {0}", proc.StandardError.ReadToEnd()); } else { _logger.LogInformation("Policies synced OK"); } try { await Task.Delay(interval, stoppingToken); } catch (OperationCanceledException) { } } }
public static Process CreateProcess(this IGit git, StringBuilder args) => git.CreateProcess(args.ToString());