Example #1
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);
        }
Example #2
0
        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";
                }
            }
        }