public void Test_Put_Request_With_Issue() { _restSharpConnection.Authenticate("*****@*****.**", "mozart"); dynamic issue = new Issue(); issue.Summary = "YT Test Issue"; issue.Description = "YT test description"; issue.ProjectShortName = "NAT"; var comments = new List <Comment>(); Comment comment = new Comment(); comment.Author = "Meagan"; comment.Text = "comment added from apitest"; issue.Comments = comments; issue.Subsystem = "Documentation"; issue.Type = "task"; issue.Assignee = "Meagan Combs"; issue.Priority = "Critical"; issue.WorkHours = 8; issue.CustomField = "customfield"; issue.Created = ""; var fieldList = issue.ToExpandoObject(); IssueManagement issueManagement = new IssueManagement(_restSharpConnection); // var issueId = issueManagement.CreateIssue(issue); issueManagement.ApplyCommand("NAT-41", "Assignee Meagan_Combs", ""); var issues = issueManagement.GetAllIssuesForProject("NAT"); }
public Issue GetIssueById(string issueId) { var issuesManagement = new IssueManagement(_connection); var issue = issuesManagement.GetIssue(issueId); return(issue); }
protected override void OnStop() { _log.Debug("OnStop"); _connection = null; _issueManagement = null; _timer.Elapsed -= OnTimer; _timer.Stop(); _timer = null; }
/// <summary> /// Simple query, yields <c>ShortComment</c> objects. /// </summary> /// <param name="issueId"></param> /// <returns></returns> public IList <ShortComment> QueryComments(string issueId) { var im = new IssueManagement(Connection); var mapper = new CommentToShortCommentMapper(); return(im.GetCommentsForIssue(issueId) .Select(mapper.Map) .ToList()); }
/// <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()); } }
public void Test_Post_File_To_Issue() { Uri uri = new Uri("http://yt.wolfgang.com/youtrack/"); RestClient rc = new RestClient { CookieContainer = new CookieContainer(), BaseUrl = uri }; rc.AddHandler("application/json", new NewtonsoftJsonDeserializer()); _restSharpConnection.Authenticate("*****@*****.**", "mozart"); IssueManagement issueManagement = new IssueManagement(_restSharpConnection); issueManagement.AttachFileToIssue("NAT-50", @"C:\Users\mecombs\Downloads\Grey-Wolf.jpg"); }
/// <summary> /// Simple query, yields <c>ShortIssue</c> objects. Can drill down later if needed. /// </summary> /// <param name="projectShortName"></param> /// <param name="query"></param> /// <returns></returns> public IList <ShortIssue> Query(string projectShortName, string query) { var im = new IssueManagement(Connection); if (!string.IsNullOrEmpty(projectShortName)) { query = string.Format("project: {0} {1}", projectShortName, query); } var mapper = new IssueToShortIssueMapper(BaseUrl); return(im.GetIssuesBySearch(query, sensibleQueryLimit, 0) .Select(mapper.Map) .ToList()); }
private static bool CheckIfIssueExists(IssueManagement issueManagement, string issue) { bool result; try { result = issueManagement.CheckIfIssueExists(issue); } catch { result = false; } return(result); }
protected override void OnStart(string[] args) { try { _sync = new object(); FileInfo f = new FileInfo("log4net.config"); log4net.Config.XmlConfigurator.Configure(f); _log = LogManager.GetLogger(typeof(Program)); _log.Debug("OnStart"); _connection = new Connection(HOST, port: PORT, useSSL: false, path: null); _connection.Authenticate(LOGIN, PASSWORD); _issueManagement = new IssueManagement(_connection); var iis = _issueManagement.GetAllIssuesForProject(PROJECT_IDENTIFICATOR, Int32.MaxValue, start: START_NUM_TASKS_FOR_FIND); foreach (dynamic issue in iis) { if (issue.assigneeName == "nitkin") { _dima.Add(issue.Id.ToString()); } if (issue.assigneeName == "denneeeee") { _den.Add(issue.Id.ToString()); } if (issue.assigneeName == "sgmm") { _srg.Add(issue.Id.ToString()); } if (issue.assigneeName == "Wlad-popow") { _wlad.Add(issue.Id.ToString()); } } _timer = new System.Timers.Timer(); _timer.Interval = 60000; // каждую минуту _timer.Elapsed += OnTimer; _timer.Start(); } catch (Exception ex) { _log.Error(ex); throw; } }
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); }
private static bool RequiredPreconditionsFulfilled(IEnumerable <IEntry <ShortTrackingFormatPayload> > entries, IssueManagement issueManagement) { var @continue = true; var entryExistence = entries.Select(e => new { e.Payload.Query, Exists = CheckIfIssueExists(issueManagement, e.Payload.Query) }).ToList(); if (entryExistence.Any(e => !e.Exists)) { var ticketQueries = string.Join(", ", entryExistence.Where(e => !e.Exists).Select(e => e.Query)); Interaction.Notice($"ERROR: There are entries that cannot be found: {ticketQueries}"); @continue = false; } return(@continue); }
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)); }
protected override void ProcessRecord() { var issue = IssueManagement.GetIssue(IssueId); WriteObject(issue); }
public void SubmitComment(string issueId, string text) { var im = new IssueManagement(Connection); im.ApplyCommand(issueId, null, text); }
protected override void BeginProcessing() { base.BeginProcessing(); IssueManagement = new IssueManagement(Connection); }
/// <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); } }
protected override void ProcessRecord() { IssueManagement.ApplyCommand(IssueId, Command, Comment); }
public void AttachFile(string issueId, string pathToFile) { var im = new IssueManagement(Connection); im.AttachFileToIssue(issueId, pathToFile); }
private static void PrintEntryList(IEnumerable <IEntry <ShortTrackingFormatPayload> > entries, IssueManagement issueManagement) { DateTime date = DateTime.MinValue; TimeSpan total = TimeSpan.Zero; foreach (var trakkrEntry in entries) { if (trakkrEntry.Timestamp.Date != date) { date = trakkrEntry.Timestamp.Date; total = TimeSpan.Zero; } var minutes = (int)Math.Round(trakkrEntry.Duration.TotalMinutes); total += TimeSpan.FromMinutes(minutes); dynamic issue = issueManagement.GetIssue(trakkrEntry.Payload.Query); string summary = issue.summary; Interaction.Notice($"{trakkrEntry.Timestamp.ToShortDateString()}\t// Task: {minutes}m\t// Day:{(int)total.TotalHours}h {total:mm}m\t// {trakkrEntry.Payload.Query}\t >> {summary} >> {trakkrEntry.Payload.Descrition}"); } }
private static bool UpdateWorkItems(IConnection connection, IEnumerable <IEntry <ShortTrackingFormatPayload> > entries, FileAppendLogger logger) { var issueManagement = new IssueManagement(connection); var errors = !RequiredPreconditionsFulfilled(entries, issueManagement); var warnings = !OptionalPreconditionsFulfilled(entries); if (errors) { if (warnings) { Interaction.Acknowledge("There have been errors and warnings. Cannot store entries."); return(false); } Interaction.Acknowledge("There have been errors. Cannot store entries."); return(false); } if (warnings && !Interaction.Confirm("There have been warnings. Continue?")) { return(false); } PrintEntryList(entries, issueManagement); if (!Interaction.Confirm("Please review the entries. Continue?")) { return(false); } foreach (var trakkrEntry in entries) { var minutes = (int)Math.Round(trakkrEntry.Duration.TotalMinutes); System.Console.Write($"Saving: {trakkrEntry.Timestamp.ToShortDateString()} : {trakkrEntry.Payload.Query} ... : {minutes} Minutes ({trakkrEntry.Payload.Descrition}) ... "); var doc = "<workItem>" + $"<date>{UnixTime.GetUnixTimestampMilliseconds(trakkrEntry.Timestamp)}</date>" + $"<duration>{minutes}</duration>" + $"<description>{HttpUtility.HtmlEncode(trakkrEntry.Payload.Descrition)}</description>" + "</workItem>"; var response = connection.PostXml($"issue/{trakkrEntry.Payload.Query}/timetracking/workitem", doc); if (response.StatusCode == HttpStatusCode.Created) { logger.Log($"Ticket {trakkrEntry.Payload.Query} ({trakkrEntry.Payload.Descrition}) : {minutes}m : {response.Location}"); System.Console.Write("SAVED!"); } else { System.Console.Write($"ERROR! Response Code: {response.StatusCode}"); logger.Log($"Ticket {trakkrEntry.Payload.Query} ({trakkrEntry.Payload.Descrition})" + $" : {minutes}m" + $" : ERROR! Response Code: {response.StatusCode}"); } //POST http://localhost:8081/rest/issue/HBR-63/timetracking/workitem System.Console.WriteLine(); //https://confluence.jetbrains.com/display/YTD6/Get+Available+Work+Items+of+Issue // get all workitems // GET /rest/issue/{issue}/timetracking/workitem/ //var result = connection.Get<object>($"issue/{trakkrEntry.Mark}/timetracking/workitem/"); // add a workitem //connection.Post($"issue/{trakkrEntry.Mark}/timetracking/workitem", "<xml/>"); //POST http://localhost:8081/rest/issue/HBR-63/timetracking/workitem } return(true); }
public YouTrackRepository(IssueManagement issueManagement) { this.issueManagement = issueManagement; }