Ejemplo n.º 1
0
        public async Task <Tuple <CommitDto, string> > GitCommitAsync(string message, Guid repositoryId, IEnumerable <string> files)
        {
            CommitDto commitDto = new CommitDto();
            var       error     = string.Empty;
            await Task.Run(async() =>
            {
                var repository = await _repositoriesService.GetRepositoryAsync(repositoryId).ConfigureAwait(false);
                var branch     = await _gitService.GetCurrentBranchAsync(repository.Path).ConfigureAwait(false);
                var branchId   = await _branchService.GetBranchIdAsync(repositoryId, branch.Output).ConfigureAwait(false);
                await _gitService.StageAsync(repository.Path, files).ConfigureAwait(false);
                var commit = await _gitService.CommitAsync(repository.Path, message).ConfigureAwait(false);
                error      = await GitParser.ParseError(commit.Error);
                if (string.IsNullOrWhiteSpace(error))
                {
                    var lastCommit = await _gitService.LastCommitAsync(repository.Path).ConfigureAwait(false);
                    var addCommit  = new Models.Commit()
                    {
                        Id          = Guid.NewGuid(),
                        Message     = message,
                        GitCommitId = await GitParser.ParseCommitIdAsync(lastCommit.Output).ConfigureAwait(false),
                        UserEmail   = await GitParser.ParseCommitAuthorAsync(lastCommit.Output).ConfigureAwait(false),
                        Time        = DateTime.Now.Ticks
                    };
                    await _commitService.AddCommitAsync(repositoryId, branchId, addCommit).ConfigureAwait(false);
                    commitDto.Branch      = branch.Output;
                    commitDto.Author      = addCommit.UserEmail;
                    commitDto.Description = addCommit.Message;
                    commitDto.Time        = new DateTime(addCommit.Time);
                    commitDto.Id          = addCommit.GitCommitId;
                    error = null;
                }
                else
                {
                    commitDto = null;
                }
            }).ConfigureAwait(false);

            var result = Tuple.Create(commitDto, error);

            return(result);
        }