Exemplo n.º 1
0
        private void showNewDiscussionDialog(MatchInfo matchInfo, Snapshot snapshot, MergeRequestKey mrk,
                                             DiffPosition initialNewDiscussionPosition)
        {
            DiffPosition fnOnScroll(DiffPosition position, bool scrollUp) =>
            scrollPosition(position, scrollUp, matchInfo.IsLeftSideLineNumber);

            async Task fnOnSubmitNewDiscussion(string body, bool includeContext, DiffPosition position) =>
            await actOnGitLab("create", () =>
                              submitDiscussionAsync(mrk, matchInfo, snapshot.Refs, position, body, includeContext));

            async Task fnOnEditOldNote(ReportedDiscussionNoteKey notePosition, ReportedDiscussionNoteContent content) =>
            await actOnGitLab("edit", () =>
                              editDiscussionNoteAsync(mrk, notePosition.DiscussionId, notePosition.Id, content.Body));

            async Task fnOnDeleteOldNote(ReportedDiscussionNoteKey notePosition) =>
            await actOnGitLab("delete", () =>
                              deleteDiscussionNoteAsync(mrk, notePosition.DiscussionId, notePosition.Id));

            IEnumerable <ReportedDiscussionNote> fnGetRelatedDiscussions(ReportedDiscussionNoteKey?keyOpt, DiffPosition position) =>
            getRelatedDiscussions(mrk, keyOpt, position).ToArray();

            // We need separate functors for `new` and `old` positions because for a new discussion we need
            // to distinct cases when user points at unchanged line at left and right sides because it is
            // important to show proper file content in a diff context window.
            // And for old discussions we don't have a chance to guess at what side they were created.
            DiffContext fnGetNewDiscussionDiffContext(DiffPosition position) =>
            getDiffContext <EnhancedContextMaker>(position,
                                                  matchInfo.IsLeftSideLineNumber ? UnchangedLinePolicy.TakeFromLeft : UnchangedLinePolicy.TakeFromRight);

            DiffContext fnGetDiffContext(DiffPosition position) =>
            getDiffContext <EnhancedContextMaker>(position, UnchangedLinePolicy.TakeFromRight);

            void fnOnDialogClosed() =>
            _onDiscussionSubmitted?.Invoke(mrk);

            ReportedDiscussionNote[] reportedDiscussions = getReportedDiscussions(mrk).ToArray();

            NewDiscussionForm form = new NewDiscussionForm(
                initialNewDiscussionPosition,
                reportedDiscussions,
                fnOnScroll,
                fnOnDialogClosed,
                fnOnSubmitNewDiscussion,
                fnOnEditOldNote,
                fnOnDeleteOldNote,
                fnGetRelatedDiscussions,
                fnGetNewDiscussionDiffContext,
                fnGetDiffContext);

            form.Show();
        }
Exemplo n.º 2
0
        public void Handle(MatchInfo matchInfo, Snapshot snapshot)
        {
            FileNameMatcher   fileNameMatcher   = getFileNameMatcher(_git, getMergeRequestKey(snapshot));
            LineNumberMatcher lineNumberMatcher = new LineNumberMatcher(_git);

            DiffPosition position = new DiffPosition(null, null, null, null, snapshot.Refs);

            try
            {
                if (!fileNameMatcher.Match(matchInfo, position, out position))
                {
                    return;
                }

                lineNumberMatcher.Match(matchInfo, position, out position);
            }
            catch (Exception ex)
            {
                if (ex is ArgumentException || ex is MatchingException)
                {
                    ExceptionHandlers.Handle("Cannot create DiffPosition", ex);
                    MessageBox.Show("Cannot create a discussion. Unexpected file name and/or line number passed",
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error,
                                    MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
                    return;
                }
                throw;
            }

            NewDiscussionForm form = new NewDiscussionForm(
                matchInfo.LeftFileName, matchInfo.RightFileName, position, _git,
                async(body, includeContext) =>
            {
                try
                {
                    await submitDiscussionAsync(matchInfo, snapshot, position, body, includeContext);
                    _onDiscussionSubmitted?.Invoke(getMergeRequestKey(snapshot));
                }
                catch (DiscussionCreatorException ex)
                {
                    string message = "Cannot create a discussion at GitLab";
                    ExceptionHandlers.Handle(message, ex);
                    MessageBox.Show(String.Format("{0}. Check your connection and try again.", message),
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error,
                                    MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
                }
            });

            form.Show();
        }
Exemplo n.º 3
0
        public void Handle(Snapshot snapshot)
        {
            using (GitClientFactory factory = new GitClientFactory(snapshot.TempFolder, null))
            {
                IGitRepository gitRepository = factory.GetClient(snapshot.Host, snapshot.Project);

                DiffToolInfoProcessor processor = new DiffToolInfoProcessor(gitRepository);

                DiffToolInfo diffToolInfo;
                if (!processor.Process(_originalDiffToolInfo, snapshot.Refs, out diffToolInfo))
                {
                    return;
                }

                RefToLineMatcher matcher  = new RefToLineMatcher(gitRepository);
                DiffPosition     position = matcher.Match(snapshot.Refs, diffToolInfo);

                NewDiscussionForm form = new NewDiscussionForm(snapshot, diffToolInfo, position, gitRepository);
                if (form.ShowDialog() == DialogResult.OK)
                {
                    submitDiscussion(snapshot, diffToolInfo, position, form.Body, form.IncludeContext);
                }
            }
        }