public GetResponse <IBranch> TryReset(IGitRepository repo) { var master = repo.MainBranch; if (master == null) { return(GetResponse <IBranch> .Fail("Could not find main branch")); } repo.ResetHard(); repo.Checkout(master); repo.Pull(); return(GetResponse <IBranch> .Succeed(master)); }
public void GeneralPipelineOrder( IGitRepository repo, ResetToLatestMain sut) { var branch = Substitute.For <IBranch>(); repo.MainBranch.Returns(branch); sut.TryReset(repo); Received.InOrder(() => { repo.ResetHard(); repo.Checkout(Arg.Any <IBranch>()); repo.Pull(); }); }
public async Task <IActionResult> UpdatePostsAsync() { var signature = Request.Headers["X-Hub-Signature"]; using (var reader = new StreamReader(Request.Body)) { var payload = await reader.ReadToEndAsync(); if (_gitRepository.IsSecretValid(signature, payload)) { _gitRepository.Pull(); _fileParserService.ParseExistingFiles(); _rssFeedService.CreateRssFeed(); return(Ok()); } } return(Unauthorized()); }
public async Task PullAsync(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"); File.Delete(tempFolder + $"\\ProjectFolder\\g{projectId}.zip"); _gitRepository.FetchAll(tempFolder + "\\ProjectFolder", username, password); _gitRepository.Pull(tempFolder + "\\ProjectFolder", branchName, project.GitCredential.Login, author.Email); _gitRepository.StashUntracked(tempFolder + "\\ProjectFolder"); await _projectStructureService.UpdateProjectStructureFromTempFolder(projectId, tempFolder + "\\ProjectFolder", authorId, false); await ReturnGitToBlob(tempFolder, projectId); _projectStructureService.DeleteTempFolder(tempFolder + "\\ProjectFolder\\.git"); } catch (Exception ex) { Debug.WriteLine(ex.Message); _logger.LogError(ex.Message); } finally { _projectStructureService.DeleteTempFolder(tempFolder); } }