async private Task onNewDiscussionAsync(MergeRequestKey mrk, string title)
        {
            string caption = String.Format("Create a new thread in merge request \"{0}\"", title);
            DiscussionNoteEditPanel actions = new DiscussionNoteEditPanel();

            using (TextEditForm form = new TextEditForm(caption, "", true, true, actions))
            {
                actions.SetTextbox(form.TextBox);
                if (form.ShowDialog() == DialogResult.OK)
                {
                    if (form.Body.Length == 0)
                    {
                        MessageBox.Show("Discussion body cannot be empty", "Warning",
                                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }

                    DataCache dataCache = getDataCache(!isSearchMode());
                    if (dataCache == null)
                    {
                        Debug.Assert(false);
                        return;
                    }

                    labelWorkflowStatus.Text = "Creating a discussion...";
                    try
                    {
                        GitLabInstance     gitLabInstance = new GitLabInstance(mrk.ProjectKey.HostName, Program.Settings);
                        IDiscussionCreator creator        = Shortcuts.GetDiscussionCreator(
                            gitLabInstance, _modificationNotifier, mrk, getCurrentUser());
                        await creator.CreateDiscussionAsync(new NewDiscussionParameters(form.Body, null), false);
                    }
                    catch (DiscussionCreatorException)
                    {
                        MessageBox.Show("Cannot create a discussion at GitLab. Check your connection and try again",
                                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        labelWorkflowStatus.Text = "Cannot create a discussion";
                        return;
                    }
                    labelWorkflowStatus.Text = "Thread started";

                    dataCache.DiscussionCache?.RequestUpdate(mrk, Constants.DiscussionCheckOnNewThreadInterval, null);
                }
            }
        }
Exemple #2
0
        async private Task submitDiscussionAsync(MatchInfo matchInfo, Snapshot snapshot, DiffPosition position,
                                                 string body, bool includeContext)
        {
            if (body.Length == 0)
            {
                MessageBox.Show("Discussion text cannot be empty", "Warning",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
                return;
            }

            NewDiscussionParameters parameters = new NewDiscussionParameters(
                body, includeContext ? createPositionParameters(position) : new PositionParameters?());

            MergeRequestKey    mrk            = getMergeRequestKey(snapshot);
            GitLabInstance     gitLabInstance = new GitLabInstance(snapshot.Host, Program.Settings);
            IDiscussionCreator creator        = Shortcuts.GetDiscussionCreator(
                gitLabInstance, _modificationListener, mrk, _currentUser);

            try
            {
                await creator.CreateDiscussionAsync(parameters, true);
            }
            catch (DiscussionCreatorException ex)
            {
                Trace.TraceInformation(
                    "Additional information about exception:\n" +
                    "Position: {0}\n" +
                    "Include context: {1}\n" +
                    "Snapshot refs: {2}\n" +
                    "MatchInfo: {3}\n" +
                    "Body:\n{4}",
                    position.ToString(),
                    includeContext.ToString(),
                    snapshot.Refs.ToString(),
                    matchInfo.ToString(),
                    body);

                if (!ex.Handled)
                {
                    throw;
                }
            }
        }
Exemple #3
0
        async private static Task <bool> addComment(
            MergeRequestKey mrk, User currentUser, string commentBody, Shortcuts shortcuts)
        {
            if (String.IsNullOrEmpty(commentBody))
            {
                return(false);
            }

            try
            {
                IDiscussionCreator creator = shortcuts.GetDiscussionCreator(mrk, currentUser);
                await creator.CreateNoteAsync(new CreateNewNoteParameters(commentBody));

                return(true);
            }
            catch (DiscussionCreatorException ex)
            {
                MessageBox.Show("Failed to create a note in the new merge request", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                ExceptionHandlers.Handle("Failed to create a note", ex);
            }
            return(false);
        }
        async private Task onAddCommentAsync(MergeRequestKey mrk, string title)
        {
            string caption = String.Format("Add comment to merge request \"{0}\"", title);
            DiscussionNoteEditPanel actions = new DiscussionNoteEditPanel();

            using (TextEditForm form = new TextEditForm(caption, "", true, true, actions))
            {
                actions.SetTextbox(form.TextBox);
                if (form.ShowDialog() == DialogResult.OK)
                {
                    if (form.Body.Length == 0)
                    {
                        MessageBox.Show("Comment body cannot be empty", "Warning",
                                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }

                    labelWorkflowStatus.Text = "Adding a comment...";
                    try
                    {
                        GitLabInstance     gitLabInstance = new GitLabInstance(mrk.ProjectKey.HostName, Program.Settings);
                        IDiscussionCreator creator        = Shortcuts.GetDiscussionCreator(
                            gitLabInstance, _modificationNotifier, mrk, getCurrentUser());
                        await creator.CreateNoteAsync(new CreateNewNoteParameters(form.Body));
                    }
                    catch (DiscussionCreatorException)
                    {
                        MessageBox.Show("Cannot create a discussion at GitLab. Check your connection and try again",
                                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        labelWorkflowStatus.Text = "Cannot create a discussion";
                        return;
                    }
                    labelWorkflowStatus.Text = "Comment added";
                }
            }
        }