Exemplo n.º 1
0
 async Task <string> GetBaseFileName(IPullRequestSession session, IPullRequestSessionFile file)
 {
     using (var changes = await pullRequestService.GetTreeChanges(
                session.LocalRepository,
                session.PullRequest))
     {
         var fileChange = changes.FirstOrDefault(x => x.Path == file.RelativePath);
         return(fileChange?.Status == LibGit2Sharp.ChangeKind.Renamed ?
                fileChange.OldPath : file.RelativePath);
     }
 }
Exemplo n.º 2
0
        /// <inheritdoc/>
        public async Task InitializeAsync(
            IPullRequestSession session,
            Func <IInlineCommentThreadModel, bool> filter = null)
        {
            Guard.ArgumentNotNull(session, nameof(session));

            subscriptions?.Dispose();
            this.pullRequestSession = session;
            this.commentFilter      = filter;
            subscriptions           = new CompositeDisposable();
            subscriptions.Add(session.WhenAnyValue(x => x.IsCheckedOut).Subscribe(isBranchCheckedOut));

            var dirs = new Dictionary <string, PullRequestDirectoryNode>
            {
                { string.Empty, new PullRequestDirectoryNode(string.Empty) }
            };

            using (var changes = await service.GetTreeChanges(session.LocalRepository, session.PullRequest))
            {
                foreach (var changedFile in session.PullRequest.ChangedFiles)
                {
                    var node = new PullRequestFileNode(
                        session.LocalRepository.LocalPath,
                        changedFile.FileName,
                        changedFile.Sha,
                        changedFile.Status,
                        GetOldFileName(changedFile, changes));
                    var file = await session.GetFile(changedFile.FileName);

                    if (file != null)
                    {
                        subscriptions.Add(file.WhenAnyValue(x => x.InlineCommentThreads)
                                          .Subscribe(x => node.CommentCount = CountComments(x, filter)));
                    }

                    var dir = GetDirectory(Path.GetDirectoryName(node.RelativePath), dirs);
                    dir.Files.Add(node);
                }
            }

            ChangedFilesCount = session.PullRequest.ChangedFiles.Count;
            Items             = dirs[string.Empty].Children.ToList();
        }