private RepositoryCommitModel ConvertToRepositoryCommitModel(Commit commit, bool withDiff = false) { var model = new RepositoryCommitModel { Author = commit.Author.Name, AuthorEmail = commit.Author.Email, Date = commit.Author.When.LocalDateTime, ID = commit.Sha, Message = commit.MessageShort, TreeID = commit.Tree.Sha, Parents = commit.Parents.Select(i => i.Sha).ToArray(), }; if (withDiff) { TreeChanges changes = commit.Parents.Count() == 0 ? _repository.Diff.Compare(null, commit.Tree) : _repository.Diff.Compare(commit.Parents.First().Tree, commit.Tree); model.Changes = changes.OrderBy(s => s.Path).Select(i => new RepositoryCommitChangeModel { //Name = i.Name, Path = i.Path.Replace('\\', '/'), Status = i.Status, }); } return(model); }
private RepositoryCommitModel ToModel(Commit commit, bool withDiff = false) { string tagsString = string.Empty; var tags = _repository.Tags.Where(o => o.Target.Sha == commit.Sha).Select(o => o.Name).ToList(); var shortMessageDetails = RepositoryCommitModelHelpers.MakeCommitMessage(commit.Message, 50); IEnumerable <string> links = null; if (UserConfiguration.Current.HasLinks) { links = Regex.Matches(commit.Message, UserConfiguration.Current.LinksRegex).OfType <Match>().Select(m => m.Value); } var model = new RepositoryCommitModel { Author = commit.Author.Name, AuthorEmail = commit.Author.Email, AuthorAvatar = commit.Author.GetAvatar(), Date = commit.Author.When.LocalDateTime, ID = commit.Sha, Message = shortMessageDetails.ShortTitle, MessageShort = shortMessageDetails.ExtraTitle, TreeID = commit.Tree.Sha, Parents = commit.Parents.Select(i => i.Sha).ToArray(), Tags = tags, Notes = (from n in commit.Notes select new RepositoryCommitNoteModel(n.Message, n.Namespace)).ToList(), Links = links }; if (!withDiff) { return(model); } TreeChanges changes = !commit.Parents.Any() ? _repository.Diff.Compare <TreeChanges>(null, commit.Tree) : _repository.Diff.Compare <TreeChanges>(commit.Parents.First().Tree, commit.Tree); Patch patches = !commit.Parents.Any() ? _repository.Diff.Compare <Patch>(null, commit.Tree) : _repository.Diff.Compare <Patch>(commit.Parents.First().Tree, commit.Tree); model.Changes = changes.OrderBy(s => s.Path).Select(i => { var patch = patches[i.Path]; return(new RepositoryCommitChangeModel { ChangeId = i.Oid.Sha, Path = i.Path.Replace('\\', '/'), Status = i.Status, LinesAdded = patch.LinesAdded, LinesDeleted = patch.LinesDeleted, Patch = patch.Patch, }); }); return(model); }
private RepositoryCommitModel ToModel(Commit commit, bool withDiff = false) { string tagsString = string.Empty; var tags = _repository.Tags.Where(o => o.Target.Sha == commit.Sha); if (tags != null && tags.Any()) { tagsString = tags.Select(o => o.Name).Aggregate((o, p) => o + " " + p); } var shortMessageDetails = RepositoryCommitModelHelpers.MakeCommitMessage(commit.Message, 30); var model = new RepositoryCommitModel { Author = commit.Author.Name, AuthorEmail = commit.Author.Email, AuthorAvatar = commit.Author.GetAvatar(), Date = commit.Author.When.LocalDateTime, ID = commit.Sha, Message = shortMessageDetails.ShortTitle, MessageShort = shortMessageDetails.ExtraTitle, TreeID = commit.Tree.Sha, Parents = commit.Parents.Select(i => i.Sha).ToArray(), TagName = tagsString, Notes = (from n in commit.Notes select new RepositoryCommitNoteModel(n.Message, n.Namespace)).ToList(), }; if (!withDiff) { return(model); } TreeChanges changes = !commit.Parents.Any() ? _repository.Diff.Compare <TreeChanges>(null, commit.Tree) : _repository.Diff.Compare <TreeChanges>(commit.Parents.First().Tree, commit.Tree); Patch patches = !commit.Parents.Any() ? _repository.Diff.Compare <Patch>(null, commit.Tree) : _repository.Diff.Compare <Patch>(commit.Parents.First().Tree, commit.Tree); model.Changes = changes.OrderBy(s => s.Path).Select(i => { var patch = patches[i.Path]; return(new RepositoryCommitChangeModel { ChangeId = i.Oid.Sha, Path = i.Path.Replace('\\', '/'), Status = i.Status, LinesAdded = patch.LinesAdded, LinesDeleted = patch.LinesDeleted, Patch = patch.Patch, }); }); return(model); }
/// <summary> /// Generates a Commit object based on information about the repository and commit. /// </summary> /// <param name="repository">A LibGit2Sharp.Repository object containing information about a repository.</param> /// <param name="commitSha">The sha of the commit itself.</param> /// <returns></returns> public Commit Create(Repository repository, string commitSha) { //Most of this code comes from https://github.com/jakubgarfield/Bonobo-Git-Server Commit model = null; var commit = repository.Commits.SingleOrDefault(c => c.Sha == commitSha); if (commit != null) { string tagsString = string.Empty; var tags = repository.Tags.Where(o => o.Target.Sha == commit.Sha).Select(o => o.FriendlyName).ToList(); model = new Commit { Author = commit.Author.Name, AuthorEmail = commit.Author.Email, Date = commit.Author.When.LocalDateTime, ID = commit.Sha, Message = commit.Message, TreeID = commit.Tree.Sha, Parents = commit.Parents.Select(i => i.Sha).ToArray(), Tags = tags, Branches = ListBranchesContainingCommit(repository, commitSha), Notes = (from n in commit.Notes select new CommitNote(n.Message, n.Namespace)).ToList() }; TreeChanges changes = !commit.Parents.Any() ? repository.Diff.Compare <TreeChanges>(null, commit.Tree) : repository.Diff.Compare <TreeChanges>(commit.Parents.First().Tree, commit.Tree); Patch patches = !commit.Parents.Any() ? repository.Diff.Compare <Patch>(null, commit.Tree) : repository.Diff.Compare <Patch>(commit.Parents.First().Tree, commit.Tree); model.Changes = changes.OrderBy(s => s.Path).Select(i => { var patch = patches[i.Path]; return(new CommitChange { ChangeId = i.Oid.Sha, Path = i.Path.Replace('\\', '/'), Status = i.Status, LinesAdded = patch.LinesAdded, LinesDeleted = patch.LinesDeleted, Patch = patch.Patch }); }); } return(model); }
private RepositoryCommitModel ToModel(Commit commit, bool withDiff = false) { var model = new RepositoryCommitModel { Author = commit.Author.Name, AuthorEmail = commit.Author.Email, AuthorAvatar = commit.Author.GetAvatar(), Date = commit.Author.When.LocalDateTime, ID = commit.Sha, Message = commit.Message, TreeID = commit.Tree.Sha, Parents = commit.Parents.Select(i => i.Sha).ToArray(), Notes = (from n in commit.Notes select new RepositoryCommitNoteModel(n.Message, n.Namespace)).ToList(), }; if (!withDiff) { return(model); } TreeChanges changes = !commit.Parents.Any() ? _repository.Diff.Compare <TreeChanges>(null, commit.Tree) : _repository.Diff.Compare <TreeChanges>(commit.Parents.First().Tree, commit.Tree); Patch patches = !commit.Parents.Any() ? _repository.Diff.Compare <Patch>(null, commit.Tree) : _repository.Diff.Compare <Patch>(commit.Parents.First().Tree, commit.Tree); model.Changes = changes.OrderBy(s => s.Path).Select(i => { var patch = patches[i.Path]; return(new RepositoryCommitChangeModel { Path = i.Path.Replace('\\', '/'), Status = i.Status, LinesAdded = patch.LinesAdded, LinesDeleted = patch.LinesDeleted, Patch = patch.Patch, }); }); return(model); }