예제 #1
0
        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));
        }
예제 #2
0
        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)
                {
                }
            }
        }
예제 #3
0
 public static Process CreateProcess(this IGit git, StringBuilder args) => git.CreateProcess(args.ToString());