If you need to export your bug reports from your YouTrack instance, this is how to get it done using C#. Its a small example that will print all the issues,comments and attachments for each project in your instance.
Don’t forget to enable the REST API in your YourTrack settings page.
Create a new project called YouTrackExport and use NuGet to install the YouTrackSharp
package
PM> Install-Package YouTrackSharp
Attempting to resolve dependency 'EasyHttp (≥ 1.6.29.0)'.
Attempting to resolve dependency 'JsonFX (≥ 2.0.1209.2802)'.
Installing 'JsonFx 2.0.1209.2802'.
...
...
The following code will print out the information:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Dynamic; using YouTrackSharp.Infrastructure; using YouTrackSharp.Projects; using YouTrackSharp.Issues; using YouTrackSharp.Admin; using System.Net; namespace YouTrackExport { class Program { static void Main(string[] args) { String Username = "xxx"; String Password = "yyy"; String Site = "zzz.myjetbrains.com"; YouTrackSharp.Infrastructure.Connection Connection; YouTrackSharp.Projects.ProjectManagement ProjectManager; IEnumerable<YouTrackSharp.Projects.Project> Projects; YouTrackSharp.Issues.IssueManagement IssueManager; IEnumerable<YouTrackSharp.Issues.Issue> Issues; IEnumerable<YouTrackSharp.Issues.Comment> Comments; Connection = new Connection(Site, 80, false, "youtrack"); Connection.Authenticate(Username, Password); ProjectManager = new ProjectManagement(Connection); Projects = ProjectManager.GetProjects(); foreach (Project project in Projects) { Console.WriteLine(String.Format("Found project {0} - {1} ", project.ShortName, project.Name)); IssueManager = new IssueManagement(Connection); Issues = IssueManager.GetAllIssuesForProject(project.ShortName); //An issue in youtrack can have many fields that we dont know at compile time. //Therefore its a .Net DynamicObject foreach (dynamic Issue in Issues) { Console.WriteLine(String.Format("\tFound issue {0}", Issue.Id)); Comments = IssueManager.GetCommentsForIssue(Issue.Id); foreach (Comment Comment in Comments) { Console.WriteLine(String.Format("\t\tComment: {0} - {1} - {2}", Comment.Author, Comment.Created, Comment.Text)); } foreach (dynamic Attachment in Issue.Attachments) { String Name = Attachment.name; String Url = Attachment.url; String Author = Attachment.authorLogin; String Id = Attachment.id; String Group = Attachment.group; long Created = Attachment.created; Console.WriteLine(String.Format("\t\tAttachment: {0} - {1} - {2}", Name, Author, Url)); } } } } } }
Some gotcha’s that I encountered
The following code wont work if your YouTrack instance is hosted in the cloud:
var connection = new Connection("http://zzz.myjetbrains.com/youtrack"); var connection = new Connection("zzz.myjetbrains.com/youtrack"); var connection = new Connection("zzz.myjetbrains.com");
The following code will raise a HTTPException: NotFound Not Found
exception. You need to to use the ShortName
member:
Issues = IssueManager.GetAllIssuesForProject(project.Name);