예제 #1
0
        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..."));
        }
예제 #2
0
        /// <summary>
        /// Generates a URL to create a new issue on GitHub.
        /// </summary>
        /// <see href="https://help.github.com/en/articles/about-automation-for-issues-and-pull-requests-with-query-parameters"/>
        public string Build(string url, Exception exception, string environmentInfo, string additionalInfo)
        {
            if (string.IsNullOrWhiteSpace(url) || exception is null)
            {
                return(null);
            }

            if (!Uri.TryCreate(url, UriKind.Absolute, out Uri validatedUri) ||
                !(validatedUri.Scheme == Uri.UriSchemeHttp || validatedUri.Scheme == Uri.UriSchemeHttps))
            {
                return(null);
            }

            string separator = !string.IsNullOrWhiteSpace(validatedUri.Query) ? "&" : "?";

            string subject = $"[NBug] {exception.Message}";

            if (subject.Length > 69)
            {
                // if the subject is longer than 70 characters, trim it
                subject = subject.Substring(0, 66) + "...";
            }

            string body = Uri.EscapeDataString(_errorReportMarkDownBodyBuilder.Build(exception, environmentInfo, additionalInfo));

            return($"{validatedUri}{separator}title={Uri.EscapeDataString(subject)}&body={body}");
        }
예제 #3
0
        private void btnCopy_Click(object sender, EventArgs e)
        {
            var report = ErrorReportBodyBuilder.Build(_lastException.OriginalException, descriptionTextBox.Text);

            if (string.IsNullOrWhiteSpace(report))
            {
                return;
            }

            Clipboard.SetDataObject(report, true, 5, 100);
        }