Esempio n. 1
0
        public void IncorrectPositionStringIsNotTransformedIntoDomainObjects()
        {
            IPositionConverter converter = new PositionConverter();
            PositionValue      retValue  = (PositionValue)converter.Convert("Stupid name that doesn't exist in the file");

            Assert.IsFalse(retValue.Value.HasValue, $"Value should have been null because the supplied name doesn't exist.");

            retValue = (PositionValue)converter.Convert(null);
            Assert.IsFalse(retValue.Value.HasValue, $"Value should have been null because null was supplied as the value to translate.");
        }
Esempio n. 2
0
        private void setDiffContextText(Control diffContextControl)
        {
            double fontSizePx = WinFormsHelpers.GetFontSizeInPixels(diffContextControl);

            DiscussionNote note = getNoteFromControl(diffContextControl);

            Debug.Assert(note.Type == "DiffNote");
            DiffPosition position = PositionConverter.Convert(note.Position);

            Debug.Assert(diffContextControl is HtmlPanel);
            HtmlPanel htmlPanel = diffContextControl as HtmlPanel;

            // We need to zero the control size before SetText call to allow HtmlPanel to compute the size
            int prevWidth = htmlPanel.Width;

            htmlPanel.Width  = 0;
            htmlPanel.Height = 0;

            string html = getContext(_panelContextMaker, position, _diffContextDepth, fontSizePx, out string css);

            htmlPanel.BaseStylesheet = css;
            htmlPanel.Text           = html;
            resizeLimitedWidthHtmlPanel(htmlPanel, prevWidth);

            string tooltipHtml = getContext(_tooltipContextMaker, position,
                                            _tooltipContextDepth, fontSizePx, out string tooltipCSS);

            _htmlDiffContextToolTip.BaseStylesheet =
                String.Format("{0} .htmltooltip {{ padding: 1px; }}", tooltipCSS);
            _htmlDiffContextToolTip.SetToolTip(htmlPanel, tooltipHtml);
        }
Esempio n. 3
0
        // Collect discussions started for lines within DiffContextDepth range near `position`
        private IEnumerable <ReportedDiscussionNote> getRelatedDiscussions(
            MergeRequestKey mrk, ReportedDiscussionNoteKey?keyOpt, DiffPosition position)
        {
            // Obtain a context for a passed position.
            DiffContext ctx = getDiffContext <CombinedContextMaker>(position, UnchangedLinePolicy.TakeFromRight);

            if (!ctx.IsValid())
            {
                return(Array.Empty <ReportedDiscussionNote>());
            }

            string leftFileName  = position.LeftPath;
            string rightFileName = position.RightPath;

            Core.Matching.DiffRefs refs = position.Refs;
            List <DiffPosition>    neighborPositions = new List <DiffPosition>();

            // CombinedContextMaker provides a context where line numbers are matched so no need to
            // match them manually here.
            foreach (DiffContext.Line line in ctx.Lines)
            {
                Debug.Assert(line.Left.HasValue || line.Right.HasValue);
                string leftLineNumber  = null;
                string rightLineNumber = null;
                if (line.Left.HasValue)
                {
                    leftLineNumber = line.Left.Value.Number.ToString();
                }
                if (line.Right.HasValue)
                {
                    rightLineNumber = line.Right.Value.Number.ToString();
                }
                neighborPositions.Add(new DiffPosition(leftFileName, rightFileName, leftLineNumber, rightLineNumber, refs));
            }

            // Find discussions that reported on each line from the diff context.
            List <ReportedDiscussionNote> relatedNotes = new List <ReportedDiscussionNote>();

            foreach (Discussion discussion in _getDiscussions(mrk))
            {
                DiscussionNote firstNote         = discussion.Notes.First();
                DiffPosition   firstNotePosition = PositionConverter.Convert(firstNote.Position);
                if (firstNotePosition != null)
                {
                    foreach (DiffPosition neighbor in neighborPositions)
                    {
                        if (doPositionsReferenceTheSameLine(neighbor, firstNotePosition) &&
                            (!keyOpt.HasValue || keyOpt.Value.Id != firstNote.Id))
                        {
                            ReportedDiscussionNote note = new ReportedDiscussionNote(firstNote.Id, discussion.Id,
                                                                                     firstNotePosition, firstNote.Body, firstNote.Author.Name, firstNote.Created_At);
                            relatedNotes.Add(note);
                        }
                    }
                }
            }
            return(relatedNotes.GroupBy(note => note.Key.Id).Select(c => c.First()));
        }
Esempio n. 4
0
        private IEnumerable <ReportedDiscussionNote> getReportedDiscussions(MergeRequestKey mrk)
        {
            DiscussionFilter discussionFilter = new DiscussionFilter(
                _currentUser, null, DiscussionFilterState.CurrentUserOnly);

            return(_getDiscussions(mrk)
                   .Where(discussion => discussionFilter.DoesMatchFilter(discussion))
                   .Where(discussion => !discussion.Notes.First().System)
                   .Select(discussion =>
            {
                DiscussionNote firstNote = discussion.Notes.First();
                Core.Matching.DiffPosition firstNotePosition = PositionConverter.Convert(firstNote.Position);
                return new ReportedDiscussionNote(firstNote.Id, discussion.Id, firstNotePosition,
                                                  firstNote.Body, firstNote.Author.Name, firstNote.Created_At);
            }));
        }