Ejemplo n.º 1
0
        public async Task CreateCommitAsync(string projectId, string message, int authorId)
        {
            var author = await _context.Users.SingleOrDefaultAsync(u => u.Id == authorId);

            var project = await _context.Projects
                          .Include(p => p.GitCredential)
                          .SingleOrDefaultAsync(p => p.Id == Convert.ToInt32(projectId));

            string tempFolder = Path.Combine(Directory.GetCurrentDirectory(), "..\\GitTemp", Guid.NewGuid().ToString());
            await _projectStructureService.ProjectStructureForGit(projectId, tempFolder);

            try
            {
                await AddGitToFolder(tempFolder, projectId, "gitcontainer");

                _gitRepository.AddToGitRepository(tempFolder + "\\ProjectFolder");
                _gitRepository.CommitAllChanges(tempFolder + "\\ProjectFolder", message, project.GitCredential.Login, author.Email);

                await ReturnGitToBlob(tempFolder, projectId);

                _projectStructureService.DeleteTempFolder(tempFolder + "\\ProjectFolder\\.git");

                await _projectStructureService.UpdateAsync(await _projectStructureService.GetByIdAsync(projectId));
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                _logger.LogError(ex.Message);
            }
            finally
            {
                _projectStructureService.DeleteTempFolder(tempFolder);
            }
        }