Example #1
0
        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);
        }
Example #2
0
        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);
        }
        private RepositoryTreeDetailModel CreateRepositoryDetailModel(TreeEntry entry, Commit ancestor, string treeName)
        {
            var maximumMessageLength = 50; //FIXME Propbably in appSettings?
            var originMessage        = ancestor != null ? ancestor.Message : String.Empty;
            var commitMessage        = !String.IsNullOrEmpty(originMessage)
                ? RepositoryCommitModelHelpers.MakeCommitMessage(originMessage, maximumMessageLength).ShortTitle : String.Empty;

            return(new RepositoryTreeDetailModel
            {
                Name = entry.Name,
                CommitDate = ancestor != null ? ancestor.Author.When.LocalDateTime : default(DateTime?),
                CommitMessage = commitMessage,
                Author = ancestor != null ? ancestor.Author.Name : String.Empty,
                IsTree = entry.TargetType == TreeEntryTargetType.Tree,
                IsLink = entry.TargetType == TreeEntryTargetType.GitLink,
                TreeName = treeName,
                Path = entry.Path.Replace('\\', '/'),
                IsImage = FileDisplayHandler.IsImage(entry.Name),
            });
        }