/// <summary> /// Ons the given event. /// </summary> /// <param name="event"> The event.</param> public void On(Event <LogEventData> @event) { var connection = GetConnection(); if (connection == null) { return; } try { var issueManagement = new IssueManagement(connection); dynamic issue = new Issue(); var payload = GetPayload(@event); issue.Summary = this._summaryTemplate.Value(payload); issue.Description = this._bodyTemplate.Value(payload); issue.ProjectShortName = this.ProjectId; issue.Type = this.YouTrackIssueType.IsSet() ? this.YouTrackIssueType : "Auto-reported Exception"; string issueNumber = issueManagement.CreateIssue(issue); if (issueNumber.IsSet()) { Log.Information( "Issue {YouTrackIssueNumber} Created in YouTrack {IssueUrl}", issueNumber, $"{GetYouTrackUri().ToFormattedUrl()}/issue/{issueNumber}"); issueManagement.ApplyCommand(issueNumber, "comment", $"Posted from Seq Event Timestamp UTC: {@event.TimestampUtc}"); if (AttachCopyOfEventToIssue) { var file = GetJsonEventFile(@event, issueNumber); issueManagement.AttachFileToIssue(issueNumber, file); try { File.Delete(file); } catch { // can't say I care too much... } } } } catch (System.Exception ex) { // failure creating issue this.Log.Error(ex, "Failure Creating Issue on YouTrack {YouTrackUrl}", GetYouTrackUri().ToFormattedUrl()); } }
private static string SubmitToYouTrack(string summary, string description) { Connection youTrackConnection = new Connection(_issueTrackingBackend, 0, true, "youtrack"); youTrackConnection.Authenticate("auto_report_creator", "thisIsInOpenSourceCode"); var issueManagement = new IssueManagement(youTrackConnection); dynamic youTrackIssue = new Issue(); youTrackIssue.ProjectShortName = _youTrackProjectKey; youTrackIssue.Type = "Awaiting Classification"; youTrackIssue.Summary = summary; youTrackIssue.Description = description; string youTrackIssueId = issueManagement.CreateIssue(youTrackIssue); return(youTrackIssueId); }
protected override void ProcessRecord() { if (!Force) { var similarIssues = IssueManagement.GetIssuesBySearch(string.Format("project: {0} \"{1}\" \"{2}\"", ProjectShortName, Summary, Description)); var issueList = from si in similarIssues select new { IssueId = si.Id, Summary = si.Summary, Description = si.Description }; if (issueList.Count() > 0) { WriteWarning("Found similar issues. If you still want to create it, use -Force=true"); WriteObject(issueList); return; } } var newIssue = new Issue { Summary = Summary, Description = Description, Priority = Priority, ProjectShortName = ProjectShortName, ReporterName = Connection.GetCurrentAuthenticatedUser().Username, State = "Submitted", Type = Type, Subsystem = Subsystem }; var id = IssueManagement.CreateIssue(newIssue); WriteObject(string.Format("Issue Created with id: {0}", id)); }
protected override void ProcessRecord() { if (!Force) { var similarIssues = IssueManagement.GetIssuesBySearch(string.Format("project: {0} \"{1}\" \"{2}\"", ProjectShortName, Summary, Description)); // TODO: Fix this once issues work again with dynamic type //var issueList = from si in similarIssues // select new {IssueId = si.Id, Summary = si.Summary, Description = si.Description}; //if (issueList.Count() > 0) //{ // WriteWarning("Found similar issues. If you still want to create it, use -Force=true"); // WriteObject(issueList); // return; //} } dynamic newIssue = new Issue(); newIssue.Summary = Summary; newIssue.Description = Description; newIssue.Priority = new[] { Priority }; newIssue.ProjectShortName = ProjectShortName; newIssue.ReporterName = Connection.GetCurrentAuthenticatedUser().Username; newIssue.State = "Submitted"; newIssue.Type = Type; newIssue.Subsystem = Subsystem; var id = IssueManagement.CreateIssue(newIssue); WriteObject(string.Format("Issue Created with id: {0}", id)); }
/// <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); } }