Skip to content

Commit

Permalink
Request repro steps before submission
Browse files Browse the repository at this point in the history
Ask a user to provide more information before a report can be submitted.

Closes gitextensions#6607
  • Loading branch information
RussKie committed Jun 18, 2019
1 parent b1d7c51 commit 11c9f9e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
37 changes: 37 additions & 0 deletions GitUI/NBugReports/BugReportForm.cs
Expand Up @@ -10,6 +10,7 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using GitExtUtils.GitUI;
using GitUI.NBugReports.Info;
Expand All @@ -30,6 +31,7 @@ public partial class BugReportForm : GitExtensionsForm
private readonly TranslationString _toolTipCopy = new TranslationString("Copy the issue details into clipboard");
private readonly TranslationString _toolTipSendQuit = new TranslationString("Report the issue to GitHub and quit application.\r\nA valid GitHub account is required");
private readonly TranslationString _toolTipQuit = new TranslationString("Quit application without reporting the issue");
private readonly TranslationString _noReproStepsSuppliedErrorMessage = new TranslationString(@"Please provide as much as information as possible to help the developers solve this issue.");

private static readonly IErrorReportMarkDownBodyBuilder ErrorReportBodyBuilder;
private static readonly GitHubUrlBuilder UrlBuilder;
Expand Down Expand Up @@ -97,6 +99,18 @@ public DialogResult ShowDialog(Exception exception, string environmentInfo)
return result;
}

protected override void OnShown(EventArgs e)
{
base.OnShown(e);
descriptionTextBox.Focus();
}

private bool CheckContainsInfo(string input)
{
var text = Regex.Replace(input, @"\s*|\r|\n", string.Empty);
return !string.IsNullOrWhiteSpace(text);
}

private void QuitButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Abort;
Expand All @@ -105,6 +119,14 @@ private void QuitButton_Click(object sender, EventArgs e)

private void SendAndQuitButton_Click(object sender, EventArgs e)
{
var hasUserText = CheckContainsInfo(descriptionTextBox.Text);
if (!hasUserText)
{
MessageBox.Show(this, _noReproStepsSuppliedErrorMessage.Text, _title.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
descriptionTextBox.Focus();
return;
}

if (MessageBox.Show(this, _submitGitHubMessage.Text, _title.Text,
MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.No)
{
Expand All @@ -130,5 +152,20 @@ private void btnCopy_Click(object sender, EventArgs e)

DialogResult = DialogResult.None;
}

internal TestAccessor GetTestAccessor()
=> new TestAccessor(this);

public readonly struct TestAccessor
{
private readonly BugReportForm _form;

public TestAccessor(BugReportForm form)
{
_form = form;
}

public bool CheckContainsInfo(string input) => _form.CheckContainsInfo(input);
}
}
}
1 change: 1 addition & 0 deletions UnitTests/GitUITests/GitUITests.csproj
Expand Up @@ -64,6 +64,7 @@
<Compile Include="Avatars\InitialsAvatarGeneratorTests.cs" />
<Compile Include="Avatars\BackupAvatarProviderTests.cs" />
<Compile Include="BranchTreePanel\GitRefMenuItemsTest.cs" />
<Compile Include="NBugReports\BugReportFormTests.cs" />
<Compile Include="CancellationTokenSequenceTests.cs" />
<Compile Include="CommandsDialogs\FormBrowseTests.LeftPanel.ReorderNodes.cs" />
<Compile Include="CommandsDialogs\FormBrowseTests.LeftPanel.Submodules.cs" />
Expand Down
28 changes: 28 additions & 0 deletions UnitTests/GitUITests/NBugReports/BugReportFormTests.cs
@@ -0,0 +1,28 @@
using System.Threading;
using FluentAssertions;
using GitUI.NBugReports;
using NUnit.Framework;

namespace GitUITests.NBugReports
{
[Apartment(ApartmentState.STA)]
[TestFixture]
public class BugReportFormTests
{
private BugReportForm _form;

[SetUp]
public void Setup()
{
_form = new BugReportForm();
}

[TestCase("", false)]
[TestCase("\t\r\n\t\t \r \n \r", false)]
[TestCase("\t\r\n\t\t a \r \n \r", true)]
public void Test(string input, bool expected)
{
_form.GetTestAccessor().CheckContainsInfo(input).Should().Be(expected);
}
}
}

0 comments on commit 11c9f9e

Please sign in to comment.