// Creates the HTML for a feed item for an individual comment. private string CreateCommentHtml(int version, GitHubCommentModel model) { using (StringWriter writer = new StringWriter()) { ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, version == 2 ? "Commit" : "Simple"); ViewContext viewContext = new ViewContext(ControllerContext, viewResult.View, new ViewDataDictionary(model), new TempDataDictionary(), writer); viewResult.View.Render(viewContext, writer); return writer.ToString(); } }
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 static string RenderCommitForSubject(GitHubCommentModel model) { string message = Regex.Replace(model.CommitMessage, @"\s+", " ").Trim(); const int maxLength = 100; if (message.Length > maxLength) message = message.Substring(0, maxLength) + "\u2026"; return message; }