internal OutgoingSourceFile GetSelectedFileById(int fileId, int branch) { var file = Context.Files .Include(x => x.AssociatedCommitFiles) .ThenInclude(AssociatedCommitFiles => AssociatedCommitFiles.Commit) .FirstOrDefault(x => x.Id == fileId); var commitKey = file.AssociatedCommitFiles.FirstOrDefault().Commit.CommitKey; var repository = Context.Repository .Include(x => x.AssociatedRepositoryBranches) .ThenInclude(AssociatedRepositoryBranches => AssociatedRepositoryBranches.Branch) .ThenInclude(Branch => Branch.AssociatedBranchCommits) .ThenInclude(AssociatedBranchCommits => AssociatedBranchCommits.Commit) .FirstOrDefault(x => x.AssociatedRepositoryBranches .Any(z => z.Branch.AssociatedBranchCommits .Any(y => y.Commit.CommitKey == commitKey))); var fileName = file.FilePath.Split('/').LastOrDefault(); var fileLanauge = GitRepositoryManager.GetFileLanaguage(fileName); var fileData = ExecuteSingle($"{Program.Configuration.ShellScripts.FirstOrDefault(x => x.Name == "GetCommitFile.sh").Path}", $"{repository.FolderPath} {commitKey}:{file.FilePath}"); return(new OutgoingSourceFile { Data = fileData, LanguageType = fileLanauge }); }
static void Main(string[] args) { GitRepositoryManager git = new GitRepositoryManager("UserName", "Name", "Repo", @"localRepo"); git.CommitAllChanges("Name"); git.PushCommits("origin", "master"); }
internal OutgoingSourceFile GetSelectedFileByName(string fileName, int projectId, int branchId) { var project = Context.Projects.Include(x => x.Repository).FirstOrDefault(x => x.Id == projectId); var branch = Context.Branches.FirstOrDefault(x => x.Id == branchId); var fileLanauge = GitRepositoryManager.GetFileLanaguage(fileName); var branchCommits = Execute($"{Program.Configuration.ShellScripts.FirstOrDefault(x => x.Name == "GetGitList.sh").Path}", $"{project.Repository.FolderPath} {branch.BranchName}"); var fileData = ExecuteSingle($"{Program.Configuration.ShellScripts.FirstOrDefault(x => x.Name == "GetCommitFile.sh").Path}", $"{project.Repository.FolderPath} {branchCommits.FirstOrDefault()}:{fileName}"); return(new OutgoingSourceFile { Data = fileData, LanguageType = fileLanauge }); }
// POST: api/Commit public IHttpActionResult Post([FromBody] Body value) { string username = ConfigurationManager.AppSettings["Username"]; string password = ConfigurationManager.AppSettings["Password"]; string remote = ConfigurationManager.AppSettings["RemoteName"]; string branch = ConfigurationManager.AppSettings["RefName"]; value.LocalFolder = value.LocalFolder.Replace("\\", @"\"); GitRepositoryManager manager = new GitRepositoryManager(username, password, value.RepoUrl, value.LocalFolder); bool result = manager.CommitAllChanges(value.Comment); if (result) { manager.PushCommits(remote, branch); return(Ok()); } return(StatusCode(HttpStatusCode.NoContent)); }