private static IEnumerable<GitIssue> GetGitIssuesFromTracTsv(GitRepos repos) { var req = WebRequest.Create(tracTsvUrl); var res = req.GetResponse() as HttpWebResponse; if (res == null) { throw new ApplicationException("Could not load trac tsv issues from "+tracTsvUrl); } if (res.StatusCode!=HttpStatusCode.OK) { throw new ArgumentException(String.Format( "Could not load trac tsv issues from {0}: Status code {1} - {2}", tracTsvUrl, res.StatusCode, res.StatusDescription)); } var tsvStream = res.GetResponseStream(); if (tsvStream == null) return new GitIssue[0]; var reader = new CsvReader(new StreamReader(tsvStream), true, '\t', '"', '"', '#', ValueTrimmingOptions.All) {SupportsMultiline = true}; var fieldHeaders = reader.GetFieldHeaders().ToList(); if (fieldHeaders.Count == 0) return new GitIssue[0]; int issueIndex = reader.GetFieldIndex("ticket"); int summaryIndex = reader.GetFieldIndex("summary"); int descriptionIndex = reader.GetFieldIndex("_description"); int statusIndex = reader.GetFieldIndex("status"); var labelFieldIndexes = new string[] {"type", "component", "version", "severity", "priority"} .Select(reader.GetFieldIndex) .Where(i => i > -1) .ToList(); var gitIssues = new List<GitIssue>(); var labels = repos.Labels; while (reader.ReadNextRecord()) { var i = new GitIssue(repos) { Title = (summaryIndex > -1) ? reader[summaryIndex] : "", IsOpen = true, Body = ((descriptionIndex > -1) ? reader[descriptionIndex] : "").Replace("\r", "").TrimEnd(new[] {'\n', ' ', '\t'}) }; if (issueIndex > -1) { int no; if (Int32.TryParse(reader[issueIndex], out no)) { i.Number = no; } i.Body += "\n\nTrac issue " + reader[issueIndex]; } if (statusIndex > 0) { if (reader[statusIndex]=="closed") i.IsOpen = false; } foreach (var label in labels.Where(l => labelFieldIndexes.Any(index => l.Name == reader[index]))) i.Labels.Add(label); gitIssues.Add(i); } return gitIssues.OrderBy(i => i.Number); }
static XElement GetHtmlScrumBoardIssue(GitIssue issue) { var points = issue.GetScrumPoints(); return new XElement( "div", new XAttribute("class", "scrum_board_issue"), new XElement( "h3", new XElement( "a", new XAttribute("href", issue.HtmlUrl), String.Format("{0}#{1}", issue.Repos.Name, issue.Number))), new XElement("p", issue.Title), new XElement( "p", "Assigned to: ", issue.Assignee==null ? null : new XElement("strong", issue.Assignee.Login)), new XElement( "p", "Points: ", points.HasValue ? new XElement("strong", points.Value.ToString("0.0")) : null)); }
/// <summary> /// Determines if a given <see cref="GitIssue"/> is a candidate to be in this state /// </summary> /// <param name="issue">The issue</param> /// <returns>A <see cref="bool"/> indicating if the issue is a candidate</returns> public bool CanBeInState(GitIssue issue) { return IssueInStateDelegate != null && IssueInStateDelegate(issue); }
static XElement GetHtmlScrumBoardIssue(GitIssue issue) { var points = issue.GetScrumPoints(); return new XElement( "div", new XAttribute("class", "scrum_board_issue"), new XElement( "h3", new XElement( "a", new XAttribute("href", issue.HtmlUrl), new XAttribute("target", "_blank"), String.Format("{0}#{1}", issue.Repos.Name, issue.Number))), new XElement("p", issue.Title), new XElement( "p", new XElement( "span", new XAttribute("class", points.HasValue?"estimated":"unestimated"), "Points: ", new XElement("strong", points.HasValue ? points.Value.ToString("0.0") : "-")), " ", new XElement( "span", new XAttribute("class", issue.Assignee==null?"unassigned":"assigned"), "Asigned to: ", new XElement("strong", issue.Assignee==null ? "none" : issue.Assignee.Login)))); }
/// <summary> /// Gets the <see cref="ScrumState"/> of a <see cref="GitIssue"/> /// </summary> /// <param name="issue">The issue</param> /// <returns>The <see cref="ScrumState"/> of the issue - <c>null</c> if no <see cref="ScrumState"/> applies</returns> public ScrumState GetStateOfIssue(GitIssue issue) { return States.LastOrDefault(s => s.CanBeInState(issue)); }
/// <summary> /// Constructor setting the issue on which the comment was made /// </summary> /// <param name="issue">The issue on which the comment was made</param> public GitComment(GitIssue issue) { if (issue == null) throw new ArgumentNullException("issue"); this.Issue = issue; }
/// <summary> /// Load a collection of <see cref="GitComment"/>s from a json array /// </summary> /// <param name="jsonComments">The json array</param> /// <param name="parent">The issue on which the loaded comments were made</param> /// <returns>The collection of <see cref="GitComment"/>s</returns> public static ICollection<GitComment> LoadFromJson(JArray jsonComments, GitIssue parent) { return LoadFromJson(jsonComments, () => new GitComment(parent)); }