// CreateIssue public static bool CreateIssue(BearerTokenConnection connection, Issue issue) { // Create new YoutrackSharp Issue and Set Standard Fields var newIssue = new YouTrackSharp.Issues.Issue() { Summary = issue.Summary, Description = issue.Description, }; // Set CustomFields foreach (var customField in issue.CustomFields) { newIssue.SetField(customField.Name, customField.Value); } try { connection.CreateIssuesService().CreateIssue("OTHER", newIssue).Wait(); } catch (Exception) { return(false); } return(true); }
public YouTrackService() { serverUrl = "https://kpfu-net.myjetbrains.com/youtrack"; connection = new BearerTokenConnection(serverUrl, "perm:YW5nZWxh.NTUtMw==.PBKFTDQmoWvoxdzM7t5TPWPtKrTeOI"); issueService = connection.CreateIssuesService(); timeService = connection.CreateTimeTrackingService(); projectService = connection.CreateProjectsService(); }
public static async Task Main(string[] args) { try { await Task.Run(() => Parser.Default.ParseArguments <Config>(args) .WithParsed(c => { ourConfig = c; }) .WithNotParsed(HandleParseError)); if (ourConfig == null) { return; } var textBuilder = new TextBuilder(); var connection = new BearerTokenConnection(ourConfig.HostUrl, ourConfig.Token); var commentThreshold = ourConfig.CommentThreshold; var sw = Stopwatch.StartNew(); var issuesService = connection.CreateIssuesService(); var taggedIssues = new List <Issue>(); if (!string.IsNullOrEmpty(ourConfig.TagForHotIssues)) { taggedIssues.AddRange(await issuesService.GetIssues($"tag: {ourConfig.TagForHotIssues}", take: 100)); } var list = new List <Issue>(); for (int i = 0; i < 20; i++) { try { var dexpIssues = await issuesService.GetIssuesInProject( "DEXP", $"{SearchFiler} {ourConfig.SearchCondition}", skip : i *100, take : 100, updatedAfter : DateTime.Now - TimeThreshold); list.AddRange(dexpIssues); } catch (Exception e) { Console.Error.WriteLine(e); } } await RemoveTags(taggedIssues, list, issuesService); var dexpHotIssues = list .Where(it => it.Comments.Count > commentThreshold || it.GetField("created").AsDateTime() > DateTime.Now - TimeSpan.FromDays(15) && it.Comments.Count > commentThreshold / 2) .OrderByDescending(it => it.Comments.Count) .ToList(); if (!string.IsNullOrEmpty(ourConfig.TagForHotIssues)) { var tasks = dexpHotIssues.Select(issue => issuesService.SetTag(issue, ourConfig.TagForHotIssues)); //await Task.WhenAll(tasks); // too many network requests simultaneously would fail Console.WriteLine($"Setting tags {ourConfig.TagForHotIssues}"); foreach (var task in tasks) { Console.Write("."); await task; } Console.WriteLine("Finished."); } var topHotTextBuilder = new TextBuilder(); var dexpTopHotIssues = dexpHotIssues.Take(ourConfig.HotIssuesAmount); var dexpHotAggregated = Aggregate(dexpHotIssues); var dexpTopAggregated = AggregateTop(dexpTopHotIssues); sw.Stop(); textBuilder.AppendHeader("DEXP HOT (" + dexpHotIssues.Count + ")"); var maxCount = dexpHotIssues.Count >= ourConfig.HotIssuesAmount ? ourConfig.HotIssuesAmount : dexpHotIssues.Count; topHotTextBuilder.AppendHeader($"Top {maxCount} of {dexpHotIssues.Count} hot issues"); textBuilder.AppendLine(dexpHotAggregated.ToPlainText(), dexpHotAggregated.ToHtml()); textBuilder.AppendHeader("Statistics"); textBuilder.AppendKeyValue("Time", $"{sw.Elapsed.TotalSeconds:0.00} sec"); textBuilder.AppendKeyValue("dexpIssues.Count", list.Count.ToString()); textBuilder.AppendKeyValue("dexpHotIssues.Count", dexpHotIssues.Count.ToString()); topHotTextBuilder.AppendLine(dexpTopAggregated, dexpTopAggregated); await File.WriteAllTextAsync("report.html", textBuilder.ToHtml()); await File.WriteAllTextAsync("report.txt", textBuilder.ToPlainText()); Console.WriteLine(topHotTextBuilder.ToPlainText()); using (var writer = new TeamCityServiceMessages().CreateWriter(Console.WriteLine)) { writer.WriteBuildParameter("env.short_report", topHotTextBuilder.ToPlainText()); } } catch (UnauthorizedConnectionException e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Can't establish a connection to YouTrack"); Console.WriteLine(e.Demystify()); Console.ResetColor(); } }
// GetIssues public static ICollection <YouTrackSharp.Issues.Issue> GetIssues(BearerTokenConnection connection, string query) { var issues = connection.CreateIssuesService().GetIssues(query); return(issues.Result); }
// GetIssue public static YouTrackSharp.Issues.Issue GetIssue(BearerTokenConnection connection, string issueId) { var issue = connection.CreateIssuesService().GetIssue(issueId); return(issue.Result); }
private bool IsIssueExists(BearerTokenConnection connection, string issueId) { var issueService = connection.CreateIssuesService(); return(issueService.Exists(issueId).Result); }