예제 #1
0
        public async Task PushAsync(string projectId, string branchName, 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));

            var username = project.GitCredential.Login;
            var password = project.GitCredential.PasswordHash;

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

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

                _gitRepository.PushCommits(tempFolder + "\\ProjectFolder", branchName, username, password);

                await ReturnGitToBlob(tempFolder, projectId);

                _projectStructureService.DeleteTempFolder(tempFolder + "\\ProjectFolder\\.git");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                _logger.LogError(ex.Message);
            }
            finally
            {
                _projectStructureService.DeleteTempFolder(tempFolder);
            }
        }