private GitHubCommentModel CreateCommentModel(int version, GitHubComment comment) { // create URL for the commit from the comment URL string commentUrl = comment.html_url.AbsoluteUri; int hashIndex = commentUrl.IndexOf('#'); string commitUrl = hashIndex == -1 ? commentUrl : commentUrl.Substring(0, hashIndex); // create basic model GitHubCommentModel model = new GitHubCommentModel { CommentUrl = commentUrl, CommitUrl = commitUrl, CommentBody = new HtmlString(comment.body_html), CommitId = comment.commit_id.Substring(0, 8), FilePath = comment.path, LineNumber = comment.line.GetValueOrDefault() == 0 ? null : comment.line, Commenter = comment.user.login, }; // add extra details if present if (version == 2) { GitHubCommit commit = m_commits[comment.commit_id]; string author = commit.author != null ? commit.author.login : "******"; model.Author = author; model.CommitMessage = commit.commit.message; model.CommitFiles = commit.files.Select(f => f.filename).OrderBy(f => f, StringComparer.OrdinalIgnoreCase).ToList(); } return(model); }
private SyndicationItem CreateCommentItem(ListParameters p, GitHubComment comment) { GitHubCommentModel model = CreateCommentModel(p.Version, comment); string title = p.Version == 1 ? "{0} commented on {1}/{2}".FormatWith(model.Commenter, p.User, p.Repo) : "{0}’s commit: {1}".FormatWith(model.Author, RenderCommitForSubject(model)); return(new SyndicationItem { Authors = { new SyndicationPerson(null, comment.user.login, null) }, Content = new TextSyndicationContent(CreateCommentHtml(p.Version, model), TextSyndicationContentKind.Html), Id = comment.url.AbsoluteUri, LastUpdatedTime = comment.updated_at, Links = { SyndicationLink.CreateAlternateLink(comment.html_url), new SyndicationLink(new Uri(model.CommitUrl)) { RelationshipType = "related", Title= "CommitUrl" } }, PublishDate = comment.created_at, Title = new TextSyndicationContent(HttpUtility.HtmlEncode(title), TextSyndicationContentKind.Html), }); }