public async Task AddCommitAsync(Guid repositoryId, Guid branchId, Models.Commit commit) { var branches = await _branchService.GetBranchFromRepositoryAsync(repositoryId); branches.FirstOrDefault(b => b.Id == branchId).Commits.Add(commit); var repo = await _repositoriesService.GetRepositoryAsync(repositoryId).ConfigureAwait(false); repo.Branches = branches; await _context.Repositories.ReplaceOneAsync(r => r.Id == repositoryId, repo); }
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); }
public async Task <List <Branch> > GetBranchFromRepositoryAsync(Guid repositoryId) { var repository = await _repositoryService.GetRepositoryAsync(repositoryId).ConfigureAwait(false); return(repository.Branches); }