Пример #1
0
        public void UploadSmokeTest()
        {
            using (var folder = new TemporaryFolder("Upload Smoke Test"))
            {
                File.WriteAllText(folder.Combine("hello there.txt"), "hello there");
                using (var bookZip = TempFile.WithFilenameInTempFolder("Upload Smoketest.zip"))
                {
                    var zip = new BloomZipFile(bookZip.Path);
                    zip.AddDirectory(folder.FolderPath);
                    zip.Save();

                    var progress = new StringBuilderProgress();
                    ProblemBookUploader.UploadBook(BloomS3Client.UnitTestBucketName, bookZip.Path, progress);
                    Assert.IsTrue(progress.Text.Contains("Success"), progress.Text);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Using YouTrackSharp here. We can't submit
        /// the report as if it were from this person, even if they have an account (well, not without
        /// asking them for credentials, which is just not gonna happen). So we submit with an
        /// account we created just for this purpose, "auto_report_creator".
        /// </summary>
        private bool SubmitToYouTrack()
        {
            try
            {
                ChangeState(State.Submitting);

                _youTrackConnection.Authenticate("auto_report_creator", "thisIsInOpenSourceCode");
                _issueManagement = new IssueManagement(_youTrackConnection);
                _youTrackIssue   = new Issue();
                _youTrackIssue.ProjectShortName = _youTrackProjectKey;
                _youTrackIssue.Type             = "Awaiting Classification";
                _youTrackIssue.Summary          = string.Format(Summary, _name.Text);
                _youTrackIssue.Description      = GetFullDescriptionContents(false);
                _youTrackIssueId = _issueManagement.CreateIssue(_youTrackIssue);

                // this could all be done in one go, but I'm doing it in stages so as to increase the
                // chance of success in bad internet situations
                if (_includeScreenshot.Checked)
                {
                    using (var file = TempFile.WithFilenameInTempFolder("screenshot.png"))
                    {
                        RobustImageIO.SaveImage(_screenshot, file.Path, ImageFormat.Png);
                        AddAttachment(file.Path);
                    }
                }

                if (Logger.Singleton != null)
                {
                    try
                    {
                        using (var logFile = GetLogFile())
                        {
                            AddAttachment(logFile.Path);
                        }
                    }
                    catch (Exception e)
                    {
                        _youTrackIssue.Description += System.Environment.NewLine + "***Got exception trying to attach log file: " + e.Message;
                        _issueManagement.UpdateIssue(_youTrackIssueId, _youTrackIssue.Summary, _youTrackIssue.Description);
                    }
                }


                if (_includeBook.Visible && _includeBook.Checked)                 // only Visible if Book is not null
                {
                    ChangeState(State.UploadingBook);
                    using (var bookZip = TempFile.WithFilenameInTempFolder(_youTrackIssueId + ".zip"))
                    {
                        var progress = new StatusProgress();
                        try
                        {
                            var zip = new BloomZipFile(bookZip.Path);
                            zip.AddDirectory(Book.FolderPath);
                            if (WantReaderInfo())
                            {
                                AddReaderInfo(zip);
                            }
                            AddCollectionSettings(zip);
                            zip.Save();
                        }
                        catch (Exception error)
                        {
                            _youTrackIssue.Description += System.Environment.NewLine + "***Error as ProblemReporterDialog attempted to zip up the book: " + error.Message;
                            _issueManagement.UpdateIssue(_youTrackIssueId, _youTrackIssue.Summary, _youTrackIssue.Description);
                            Logger.WriteEvent("*** Error as ProblemReporterDialog attempted to zip up the book. " + error.Message);
                            // if an error happens in the zipper, the zip file stays locked, so we just leak it
                            bookZip.Detach();
                            _shortErrorHtml += " Error Zipping Book ";
                            throw;
                        }

                        try
                        {
                            string url = ProblemBookUploader.UploadBook(BloomS3Client.ProblemBookUploadsBucketName, bookZip.Path,
                                                                        progress);
                            _youTrackIssue.Description += System.Environment.NewLine + url;
                            _issueManagement.UpdateIssue(_youTrackIssueId, _youTrackIssue.Summary, _youTrackIssue.Description);
                        }
                        catch (Exception error)
                        {
                            Logger.WriteError(progress.LastError, error);
                            _youTrackIssue.Description += System.Environment.NewLine + "***Got exception trying upload book: " + error.Message;
                            _issueManagement.UpdateIssue(_youTrackIssueId, _youTrackIssue.Summary, _youTrackIssue.Description);
                            _shortErrorHtml += " Uploading Book Failed ";
                        }
                    }
                }

                ChangeState(State.Success);
                return(true);
            }
            catch (Exception error)
            {
                Debug.Fail(error.Message);
                return(false);
            }
        }
Пример #3
0
        internal string SubmitToYouTrack(string reportKind, string userDesc, string userEmail, bool includeBook, bool includeScreenshot, IEnumerable <string> additionalPathsToInclude)
        {
            var subject = reportKind == "User" ? "User Problem" : reportKind == "Fatal" ? "Crash Report" : "Error Report";

            var issueSubmission = new YouTrackIssueSubmitter(YouTrackProjectKey);

            if (includeScreenshot && _reportInfo?.ScreenshotTempFile != null && RobustFile.Exists(_reportInfo.ScreenshotTempFile.Path))
            {
                issueSubmission.AddAttachmentWhenWeHaveAnIssue(_reportInfo.ScreenshotTempFile.Path);
            }
            if (additionalPathsToInclude != null)
            {
                foreach (var path in additionalPathsToInclude)
                {
                    issueSubmission.AddAttachmentWhenWeHaveAnIssue(path);
                }
            }
            string diagnosticInfo = GetDiagnosticInfo(includeBook, userDesc, userEmail);

            if (!string.IsNullOrWhiteSpace(userEmail))
            {
                // remember their email
                SIL.Windows.Forms.Registration.Registration.Default.Email = userEmail;
            }

            string issueId;

            try
            {
                issueId = issueSubmission.SubmitToYouTrack(subject, diagnosticInfo);
            }
            catch (Exception e)
            {
                Debug.Fail("Submitting problem report to YouTrack failed with '" + e.Message + "'.");
                issueId = kFailureResult;
            }

            string issueLink;

            if (issueId == kFailureResult)
            {
                var zipPath = MakeEmailableReportFile(includeBook, includeScreenshot, userDesc, diagnosticInfo);
                issueLink = kFailureResult + ":" + zipPath;
            }
            else
            {
                issueLink = "https://issues.bloomlibrary.org/youtrack/issue/" + issueId;
                if (includeBook || _additionalPathsToInclude?.Any() == true)
                {
                    try
                    {
                        string zipPath = CreateReportZipFile(issueId, userDesc, includeBook);
                        if (zipPath != null)
                        {
                            // This could be used provided the file is not too large (about 10M as of July 2020),
                            // but it seems simpler to do the same thing every time.
                            //issueSubmission.AttachFileToExistingIssue(issueId, zipPath);
                            var uploadUrl = ProblemBookUploader.UploadBook(
                                BloomS3Client.ProblemBookUploadsBucketName, zipPath,
                                new NullProgress());
                            diagnosticInfo += Environment.NewLine + "Problem book uploaded to " + uploadUrl;
                            // We don't want to change the summary, but currently the YouTrack API requires us to set both together.
                            issueSubmission.UpdateSummaryAndDescription(issueId, subject, diagnosticInfo);
                        }
                    }
                    catch (Exception error)
                    {
                        Debug.WriteLine($"Attaching book to new YouTrack issue failed with '{error.Message}'.");
                        var msg = "***Error as ProblemReportApi attempted to upload the zipped book: " +
                                  error.Message;
                        userDesc += Environment.NewLine + msg;
                        Logger.WriteEvent(userDesc);
                        diagnosticInfo += Environment.NewLine + "Uploading the problem book failed with exception " + error.Message;
                        // We don't want to change the summary, but currently the YouTrack API requires us to set both together.
                        issueSubmission.UpdateSummaryAndDescription(issueId, subject, diagnosticInfo);
                    }
                    finally
                    {
                        _reportZipFileTemp.Detach();
                    }
                }
            }
            return(issueLink);
        }