Example #1
0
        public async Task <OperationResult <GitRepository> > CloneAsync(CancellationToken cancellationToken = default)
        {
            using var scope = logger.BeginScope("Clone");

            var arguments = new List <string>
            {
                "clone",
                GetUrlWithAccessToken(),
                gitProjectInformation.TargetDirectory,
                "--verbose"
            };

            if (gitProjectInformation.CloneRecursive)
            {
                arguments.Add("--recursive");
            }

            var processRunArgs     = new ShellRunnerArgs(gitProjectInformation.WorkingDirectory, "git", false, arguments.ToArray());
            var cloneProcessResult = await shellRunner.RunAsync(processRunArgs, cancellationToken);

            if (!cloneProcessResult.IsSuccessful)
            {
                return(OperationResult <GitRepository> .Failed(cloneProcessResult.Error));
            }

            logger.LogInformation(await cloneProcessResult.Value.Error.ReadToEndAsync());
            logger.LogInformation(await cloneProcessResult.Value.Output.ReadToEndAsync());

            var repositoryDirectory = Path.Combine(gitProjectInformation.WorkingDirectory,
                                                   gitProjectInformation.TargetDirectory);

            return(OperationResult <GitRepository> .Success(new GitRepository(shellRunner, repositoryDirectory, loggerFactory.CreateLogger <GitRepository>())));
        }
Example #2
0
        private async Task <OperationResult <AgentInformation> > RunAgentAsync(StartAgentInformation startAgentInformation, GitRepository agentRepository)
        {
            var args = new ShellRunnerArgs(agentRepository.Directory,
                                           "docker", false, $"run -p {startAgentInformation.Port}:80 -d agent:latest");
            var runAgentResult = await shellRunner.RunAsync(args);

            if (!runAgentResult.IsSuccessful)
            {
                return(OperationResult <AgentInformation> .Failed($"Cannot run container with agent. Error: {runAgentResult.Error}"));
            }

            logger.LogInformation(await runAgentResult.Value.Output.ReadToEndAsync());

            return(OperationResult <AgentInformation> .Success(new AgentInformation(new Uri($"http://localhost:{startAgentInformation.Port}"))));
        }
Example #3
0
        private async Task <VoidOperationResult> BuildAgentAsync(GitRepository agentRepository)
        {
            var args = new ShellRunnerArgs(agentRepository.Directory,
                                           "docker", false, $"build -f {Path.Combine("Elevator.Agent", "Dockerfile")} -t agent .");
            var buildAgentResult = await shellRunner.RunAsync(args);

            if (!buildAgentResult.IsSuccessful)
            {
                return(VoidOperationResult.Failed($"Cannot build agent image. Error: '{buildAgentResult.Error}'"));
            }

            logger.LogInformation(await buildAgentResult.Value.Output.ReadToEndAsync());

            return(VoidOperationResult.Success());
        }
Example #4
0
        public async Task <OperationResult <string> > GetCommitHashAsync()
        {
            using var scope = logger.BeginScope("Get commit hash");

            var shellRunnerArgs = new ShellRunnerArgs(Directory, "git", false, "rev-parse", "HEAD");

            var getCommitHashProcessResult = await shellRunner.RunAsync(shellRunnerArgs);

            if (!getCommitHashProcessResult.IsSuccessful)
            {
                return(OperationResult <string> .Failed(getCommitHashProcessResult.Error));
            }

            logger.LogInformation(await getCommitHashProcessResult.Value.Error.ReadToEndAsync());

            return(OperationResult <string> .Success(await getCommitHashProcessResult.Value.Output.ReadToEndAsync()));
        }
Example #5
0
        public async Task <VoidOperationResult> CheckoutAsync(string branch)
        {
            using var scope = logger.BeginScope("Checkout");

            var shellRunnerArgs = new ShellRunnerArgs(Directory, "git", false, "checkout", branch);

            var checkoutProcessResult = await shellRunner.RunAsync(shellRunnerArgs);

            if (!checkoutProcessResult.IsSuccessful)
            {
                return(VoidOperationResult.Failed(checkoutProcessResult.Error));
            }

            logger.LogInformation(await checkoutProcessResult.Value.Error.ReadToEndAsync());

            return(VoidOperationResult.Success());
        }