Skip to content

Commit

Permalink
Submit issue to GitHub
Browse files Browse the repository at this point in the history
GitHub allows submitting issues by navigating a dedicated URL supplying
issue data via query string parameters.
More info: https://help.github.com/en/articles/about-automation-for-issues-and-pull-requests-with-query-parameters

Whenever Git Extensions experiences an issue that is handled by NBug, a
user is presented with an option to submit an issue to our GitHub repo.

By clicking "Send and quit" button the following occurs:
* an issue payload is generated,
* the payload gets encoded into a url, and
* the user is navigated to the generated url in a browser of their choice

Relates to gitextensions/gitextensions#5064
  • Loading branch information
RussKie committed Apr 9, 2019
1 parent de75820 commit 636dad4
Show file tree
Hide file tree
Showing 19 changed files with 505 additions and 74 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,4 @@ UpgradeLog*.XML
# NuGet
packages/
.vs/
*.received.*
35 changes: 28 additions & 7 deletions NBug.Tests/NBug.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,36 @@
<AssemblyOriginatorKeyFile>..\Signing.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Moq, Version=4.0.10827.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
<Private>True</Private>
<Reference Include="ApprovalTests, Version=3.0.0.0, Culture=neutral, PublicKeyToken=11bd7d124fc62e0f, processorArchitecture=MSIL">
<HintPath>..\packages\ApprovalTests.3.0.13\lib\net40\ApprovalTests.dll</HintPath>
</Reference>
<Reference Include="ApprovalUtilities, Version=3.0.0.0, Culture=neutral, PublicKeyToken=11bd7d124fc62e0f, processorArchitecture=MSIL">
<HintPath>..\packages\ApprovalUtilities.3.0.13\lib\net45\ApprovalUtilities.dll</HintPath>
</Reference>
<Reference Include="ApprovalUtilities.Net45, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ApprovalUtilities.3.0.13\lib\net45\ApprovalUtilities.Net45.dll</HintPath>
</Reference>
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.4.2.0\lib\net45\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="FluentAssertions, Version=5.2.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\packages\FluentAssertions.5.2.0\lib\net45\FluentAssertions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="NSubstitute, Version=3.1.0.0, Culture=neutral, PublicKeyToken=92dd2e9066daa5ca, processorArchitecture=MSIL">
<HintPath>..\packages\NSubstitute.3.1.0\lib\net46\NSubstitute.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\net461\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="xunit, Version=1.9.0.1566, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.1.9.0.1566\lib\xunit.dll</HintPath>
Expand Down Expand Up @@ -84,9 +103,11 @@
<Compile Include="Functional\WinFormsUITests.cs" />
<Compile Include="Integration\BugReportTests.cs" />
<Compile Include="Integration\HandlerTests.cs" />
<Compile Include="Unit\BugReportTests.cs" />
<Compile Include="Unit\Util\GitHubUrlBuilderTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Unit\Util\ErrorReportMarkDownBodyBuilderTests.cs" />
<Compile Include="Unit\Helpers\EmailDestinationBuilderTests.cs" />
<Compile Include="Unit\Util\Mock.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NBug\NBug.csproj">
Expand Down
4 changes: 4 additions & 0 deletions NBug.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

using System.Reflection;
using System.Runtime.InteropServices;
using ApprovalTests.Reporters;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
Expand All @@ -24,6 +25,9 @@
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("2063af3c-6402-4000-b41e-b0e14cc10ec0")]

[assembly: UseReporter(typeof(NUnitReporter), typeof(AppVeyorReporter), typeof(DiffReporter))]


// Version information for an assembly consists of the following four values:
// Major Version
// Minor Version
Expand Down
21 changes: 0 additions & 21 deletions NBug.Tests/Unit/BugReportTests.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Current behaviour

```
System.ApplicationException: Failed ---> System.ArgumentOutOfRangeException: Opps ---> System.DivideByZeroException: Boom!
--- End of inner exception stack trace ---
--- End of inner exception stack trace ---
at NBug.Tests.Unit.Util.Mock.Method1() in C:\Development\gitextensions\Externals\NBug\NBug.Tests\Unit\Util\Mock.cs:line 13
at NBug.Tests.Unit.Util.Mock.Method2() in C:\Development\gitextensions\Externals\NBug\NBug.Tests\Unit\Util\Mock.cs:line 16
at NBug.Tests.Unit.Util.Mock.Method3() in C:\Development\gitextensions\Externals\NBug\NBug.Tests\Unit\Util\Mock.cs:line 17
at NBug.Tests.Unit.Util.Mock.Method4() in C:\Development\gitextensions\Externals\NBug\NBug.Tests\Unit\Util\Mock.cs:line 18
at NBug.Tests.Unit.Util.Mock.DoWork() in C:\Development\gitextensions\Externals\NBug\NBug.Tests\Unit\Util\Mock.cs:line 7
at NBug.Tests.Unit.Util.ErrorReportMarkDownBodyBuilderTests.Build_should_build_report_with_system_and_additional_info() in C:\Development\gitextensions\Externals\NBug\NBug.Tests\Unit\Util\ErrorReportMarkDownBodyBuilderTests.cs:line 77
```


## Additional information

It happened when I was arguing with someone on the Internet.
I was right and they were absolutely wrong!
I win! But the app crashed!
PLEASE HELP!!!


## Environment

System information is not supplied
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## Current behaviour

```
System.ApplicationException: Failed ---> System.ArgumentOutOfRangeException: Opps ---> System.DivideByZeroException: Boom!
--- End of inner exception stack trace ---
--- End of inner exception stack trace ---
at NBug.Tests.Unit.Util.Mock.Method1() in C:\Development\gitextensions\Externals\NBug\NBug.Tests\Unit\Util\Mock.cs:line 13
at NBug.Tests.Unit.Util.Mock.Method2() in C:\Development\gitextensions\Externals\NBug\NBug.Tests\Unit\Util\Mock.cs:line 16
at NBug.Tests.Unit.Util.Mock.Method3() in C:\Development\gitextensions\Externals\NBug\NBug.Tests\Unit\Util\Mock.cs:line 17
at NBug.Tests.Unit.Util.Mock.Method4() in C:\Development\gitextensions\Externals\NBug\NBug.Tests\Unit\Util\Mock.cs:line 18
at NBug.Tests.Unit.Util.Mock.DoWork() in C:\Development\gitextensions\Externals\NBug\NBug.Tests\Unit\Util\Mock.cs:line 7
at NBug.Tests.Unit.Util.ErrorReportMarkDownBodyBuilderTests.Build_should_build_report_with_system_without_additional_info() in C:\Development\gitextensions\Externals\NBug\NBug.Tests\Unit\Util\ErrorReportMarkDownBodyBuilderTests.cs:line 61
```


## Environment


- Git Extensions 0.0.2.5232
- Build 23b6f51905006ccdde8701591df706284b4155dc
- Git 2.19.0.windows.1
- Microsoft Windows NT 10.0.17134.0
- .NET Framework 4.7.3324.0
- DPI 144dpi (150% scaling)

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Current behaviour

```
System.ApplicationException: Failed ---> System.ArgumentOutOfRangeException: Opps ---> System.DivideByZeroException: Boom!
--- End of inner exception stack trace ---
--- End of inner exception stack trace ---
at NBug.Tests.Unit.Util.Mock.Method1() in C:\Development\gitextensions\Externals\NBug\NBug.Tests\Unit\Util\Mock.cs:line 13
at NBug.Tests.Unit.Util.Mock.Method2() in C:\Development\gitextensions\Externals\NBug\NBug.Tests\Unit\Util\Mock.cs:line 16
at NBug.Tests.Unit.Util.Mock.Method3() in C:\Development\gitextensions\Externals\NBug\NBug.Tests\Unit\Util\Mock.cs:line 17
at NBug.Tests.Unit.Util.Mock.Method4() in C:\Development\gitextensions\Externals\NBug\NBug.Tests\Unit\Util\Mock.cs:line 18
at NBug.Tests.Unit.Util.Mock.DoWork() in C:\Development\gitextensions\Externals\NBug\NBug.Tests\Unit\Util\Mock.cs:line 7
at NBug.Tests.Unit.Util.ErrorReportMarkDownBodyBuilderTests.Build_should_build_report_without_system_or_additional_info() in C:\Development\gitextensions\Externals\NBug\NBug.Tests\Unit\Util\ErrorReportMarkDownBodyBuilderTests.cs:line 36
```


## Environment

System information is not supplied
88 changes: 88 additions & 0 deletions NBug.Tests/Unit/Util/ErrorReportMarkDownBodyBuilderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="GitHubUrlBuilderTests.cs" company="Git Extensions">
// Copyright (c) 2019 Igor Velikorossov. Licensed under MIT license.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using System;
using ApprovalTests;
using FluentAssertions;
using NBug.Core.Util;
using Xunit;

namespace NBug.Tests.Unit.Util
{
public class ErrorReportMarkDownBodyBuilderTests
{
private readonly ErrorReportMarkDownBodyBuilder _errorReportMarkDownBodyBuilder;

public ErrorReportMarkDownBodyBuilderTests()
{
Settings.GetSystemInfo = null;
_errorReportMarkDownBodyBuilder = new ErrorReportMarkDownBodyBuilder();
}

[Fact]
public void Build_should_throw_ArgumentNullException_if_exception_null()
{
((Action)(() => _errorReportMarkDownBodyBuilder.Build(null, null))).Should().Throw<ArgumentNullException>();
}

[Fact]
public void Build_should_build_report_without_system_or_additional_info()
{
try
{
Mock.DoWork();

Assert.True(false, "Expected an exception to be thrown");
}
catch (Exception ex)
{
var report = _errorReportMarkDownBodyBuilder.Build(ex, null);
Approvals.Verify(report);
}
}

[Fact]
public void Build_should_build_report_with_system_without_additional_info()
{
Settings.GetSystemInfo = () => @"
- Git Extensions 0.0.2.5232
- Build 23b6f51905006ccdde8701591df706284b4155dc
- Git 2.19.0.windows.1
- Microsoft Windows NT 10.0.17134.0
- .NET Framework 4.7.3324.0
- DPI 144dpi (150% scaling)
";

try
{
Mock.DoWork();

Assert.True(false, "Expected an exception to be thrown");
}
catch (Exception ex)
{
var report = _errorReportMarkDownBodyBuilder.Build(ex, null);
Approvals.Verify(report);
}
}

[Fact]
public void Build_should_build_report_with_system_and_additional_info()
{
try
{
Mock.DoWork();

Assert.True(false, "Expected an exception to be thrown");
}
catch (Exception ex)
{
var report = _errorReportMarkDownBodyBuilder.Build(ex, "It happened when I was arguing with someone on the Internet.\r\nI was right and they were absolutely wrong!\r\nI win! But the app crashed!\r\nPLEASE HELP!!!");
Approvals.Verify(report);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http://localhost/issues/new?title=%5BNBug%5D%20BAU-863%20adding%20settings%20and%20organisations%20if%20they%20are%20not%20a...&body=%23%23%20Current%20behaviour%0D%0A%0D%0A%60%60%60%0D%0ASystem.ApplicationException%3A%20Failed%20---%3E%20System.ArgumentOutOfRangeException%3A%20Opps%20---%3E%20System.DivideByZeroException%3A%20Boom%21%0D%0A%20%20%20---%20End%20of%20inner%20exception%20stack%20trace%20---%0D%0A%20%20%20---%20End%20of%20inner%20exception%20stack%20trace%20---%0D%0A%20%20%20at%20NBug.Tests.Unit.Util.Mock.Method1%28%29%20in%20C%3A%5CDevelopment%5Cgitextensions%5CExternals%5CNBug%5CNBug.Tests%5CUnit%5CUtil%5CMock.cs%3Aline%2013%0D%0A%20%20%20at%20NBug.Tests.Unit.Util.Mock.Method2%28%29%20in%20C%3A%5CDevelopment%5Cgitextensions%5CExternals%5CNBug%5CNBug.Tests%5CUnit%5CUtil%5CMock.cs%3Aline%2016%0D%0A%20%20%20at%20NBug.Tests.Unit.Util.Mock.Method3%28%29%20in%20C%3A%5CDevelopment%5Cgitextensions%5CExternals%5CNBug%5CNBug.Tests%5CUnit%5CUtil%5CMock.cs%3Aline%2017%0D%0A%20%20%20at%20NBug.Tests.Unit.Util.Mock.Method4%28%29%20in%20C%3A%5CDevelopment%5Cgitextensions%5CExternals%5CNBug%5CNBug.Tests%5CUnit%5CUtil%5CMock.cs%3Aline%2018%0D%0A%20%20%20at%20NBug.Tests.Unit.Util.Mock.DoWork%28%29%20in%20C%3A%5CDevelopment%5Cgitextensions%5CExternals%5CNBug%5CNBug.Tests%5CUnit%5CUtil%5CMock.cs%3Aline%207%0D%0A%20%20%20at%20NBug.Tests.Unit.Util.ErrorReportMarkDownBodyBuilderTests.Build_should_build_report_without_system_or_additional_info%28%29%20in%20C%3A%5CDevelopment%5Cgitextensions%5CExternals%5CNBug%5CNBug.Tests%5CUnit%5CUtil%5CErrorReportMarkDownBodyBuilderTests.cs%3Aline%2036%0D%0A%60%60%60%0D%0A%0D%0A%23%23%20Additional%20information%0D%0A%0D%0AIt%20happened%20when%20I%20was%20arguing%20with%20someone%20on%20the%20Internet.%0D%0AI%20was%20right%20and%20they%20were%20absolutely%20wrong%21%0D%0AI%20win%21But%20the%20app%20crashed%21%0D%0APLEASE%20HELP%21%21%21%0D%0A%0D%0A%0D%0A%23%23%20Environment%0D%0A%0D%0A-%20Git%20Extensions%200.0.2.5232%0D%0A-%20Build%2023b6f51905006ccdde8701591df706284b4155dc%0D%0A-%20Git%202.19.0.windows.1%0D%0A-%20Microsoft%20Windows%20NT%2010.0.17134.0%0D%0A-%20.NET%20Framework%204.7.3324.0%0D%0A-%20DPI%20144dpi%20%28150%25%20scaling%29%0D%0A
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http://localhost/issues/new?foo=bar&title=%5BNBug%5D%20BAU-863%20adding%20settings%20and%20organisations%20if%20they%20are%20not%20a...&body=%23%23%20Current%20behaviour
117 changes: 117 additions & 0 deletions NBug.Tests/Unit/Util/GitHubUrlBuilderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="BugReportTests.cs" company="NBug Project">
// Copyright (c) 2019 Igor Velikorossov. Licensed under MIT license.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using System;
using System.Linq;
using ApprovalTests;
using FluentAssertions;
using NBug.Core.Util;
using NSubstitute;
using Xunit;
using Xunit.Extensions;

namespace NBug.Tests.Unit.Util
{
public class GitHubUrlBuilderTests
{
private readonly IErrorReportMarkDownBodyBuilder _errorReportMarkDownBodyBuilder;
private readonly GitHubUrlBuilder _gitHubUrlBuilder;

public GitHubUrlBuilderTests()
{
_errorReportMarkDownBodyBuilder = Substitute.For<IErrorReportMarkDownBodyBuilder>();
_gitHubUrlBuilder = new GitHubUrlBuilder(_errorReportMarkDownBodyBuilder);
}

[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData("\t")]
public void Build_should_return_null_if_url_unset(string url)
{
_gitHubUrlBuilder.Build(url, null, null).Should().BeNull();
}

[Fact]
public void Build_should_return_null_if_exception_unset()
{
_gitHubUrlBuilder.Build("http://", null, null).Should().BeNull();
}

[Theory]
[InlineData("./page/new")]
[InlineData("ftp://api.github.com/issues/new")]
[InlineData("file:////c:/development/file.txt")]
public void Build_should_return_null_if_url_not_absolute_or_http_https(string url)
{
_gitHubUrlBuilder.Build(url, null, null).Should().BeNull();
}

[Fact]
public void Build_should_trim_subject_if_longer_70_char()
{
_errorReportMarkDownBodyBuilder.Build(Arg.Any<Exception>(), Arg.Any<string>()).Returns(x => @"## Current behaviour");
var ex = new ApplicationException("BAU-863 adding settings and organisations if they are not already exist in the set");

var url = _gitHubUrlBuilder.Build("http://localhost/issues/new?foo=bar", ex, null);

var subject = url.Split('&', '?').First(x => x.StartsWith("title=")).Substring("title=".Length);
subject.Should().Be(Uri.EscapeDataString("[NBug] BAU-863 adding settings and organisations if they are not a..."));
}

[Fact]
public void Build_should_return_preserve_url_querystring()
{
_errorReportMarkDownBodyBuilder.Build(Arg.Any<Exception>(), Arg.Any<string>()).Returns(x => @"## Current behaviour");
var ex = new ApplicationException("BAU-863 adding settings and organisations if they are not already exist in the set");

var url = _gitHubUrlBuilder.Build("http://localhost/issues/new?foo=bar", ex, null);

Approvals.Verify(url);
}

[Fact]
public void Build_should_return_full_url()
{
_errorReportMarkDownBodyBuilder.Build(Arg.Any<Exception>(), Arg.Any<string>()).Returns(x => @"## Current behaviour
```
System.ApplicationException: Failed ---> System.ArgumentOutOfRangeException: Opps ---> System.DivideByZeroException: Boom!
--- End of inner exception stack trace ---
--- End of inner exception stack trace ---
at NBug.Tests.Unit.Util.Mock.Method1() in C:\Development\gitextensions\Externals\NBug\NBug.Tests\Unit\Util\Mock.cs:line 13
at NBug.Tests.Unit.Util.Mock.Method2() in C:\Development\gitextensions\Externals\NBug\NBug.Tests\Unit\Util\Mock.cs:line 16
at NBug.Tests.Unit.Util.Mock.Method3() in C:\Development\gitextensions\Externals\NBug\NBug.Tests\Unit\Util\Mock.cs:line 17
at NBug.Tests.Unit.Util.Mock.Method4() in C:\Development\gitextensions\Externals\NBug\NBug.Tests\Unit\Util\Mock.cs:line 18
at NBug.Tests.Unit.Util.Mock.DoWork() in C:\Development\gitextensions\Externals\NBug\NBug.Tests\Unit\Util\Mock.cs:line 7
at NBug.Tests.Unit.Util.ErrorReportMarkDownBodyBuilderTests.Build_should_build_report_without_system_or_additional_info() in C:\Development\gitextensions\Externals\NBug\NBug.Tests\Unit\Util\ErrorReportMarkDownBodyBuilderTests.cs:line 36
```
## Additional information
It happened when I was arguing with someone on the Internet.
I was right and they were absolutely wrong!
I win!But the app crashed!
PLEASE HELP!!!
## Environment
- Git Extensions 0.0.2.5232
- Build 23b6f51905006ccdde8701591df706284b4155dc
- Git 2.19.0.windows.1
- Microsoft Windows NT 10.0.17134.0
- .NET Framework 4.7.3324.0
- DPI 144dpi (150% scaling)
");
var ex = new ApplicationException("BAU-863 adding settings and organisations if they are not already exist in the set");

var url = _gitHubUrlBuilder.Build("http://localhost/issues/new", ex, null);

Approvals.Verify(url);
}
}
}

0 comments on commit 636dad4

Please sign in to comment.