From 3daba4304dba818d54eb9b74d8d35df5aab8fee5 Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Fri, 22 Nov 2013 10:36:05 -0500 Subject: [PATCH] Add pull request linking in changelog to generated documentation --- src/main/java/com/gitblit/wicket/pages/SummaryPage.java | 69 ++++++++++++---------------------- 1 files changed, 24 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/gitblit/wicket/pages/SummaryPage.java b/src/main/java/com/gitblit/wicket/pages/SummaryPage.java index 17c41eb..5604be4 100644 --- a/src/main/java/com/gitblit/wicket/pages/SummaryPage.java +++ b/src/main/java/com/gitblit/wicket/pages/SummaryPage.java @@ -18,7 +18,6 @@ import java.awt.Color; import java.awt.Dimension; import java.text.MessageFormat; -import java.text.ParseException; import java.util.ArrayList; import java.util.List; @@ -44,16 +43,17 @@ import com.gitblit.GitBlit; import com.gitblit.Keys; import com.gitblit.models.Metric; -import com.gitblit.models.PathModel; import com.gitblit.models.RepositoryModel; import com.gitblit.models.UserModel; import com.gitblit.utils.JGitUtils; -import com.gitblit.utils.MarkdownUtils; import com.gitblit.utils.StringUtils; import com.gitblit.wicket.CacheControl; -import com.gitblit.wicket.GitBlitWebSession; -import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.CacheControl.LastModified; +import com.gitblit.wicket.GitBlitWebSession; +import com.gitblit.wicket.MarkupProcessor; +import com.gitblit.wicket.MarkupProcessor.MarkupDocument; +import com.gitblit.wicket.MarkupProcessor.MarkupSyntax; +import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.charting.SecureChart; import com.gitblit.wicket.panels.BranchesPanel; import com.gitblit.wicket.panels.LinkPanel; @@ -91,13 +91,14 @@ // repository description add(new Label("repositoryDescription", getRepositoryModel().description)); - + // owner links final List<String> owners = new ArrayList<String>(getRepositoryModel().owners); ListDataProvider<String> ownersDp = new ListDataProvider<String>(owners); DataView<String> ownersView = new DataView<String>("repositoryOwners", ownersDp) { private static final long serialVersionUID = 1L; int counter = 0; + @Override public void populateItem(final Item<String> item) { String ownername = item.getModelObject(); UserModel ownerModel = GitBlit.self().getUserModel(ownername); @@ -117,7 +118,7 @@ }; ownersView.setRenderBodyOnly(true); add(ownersView); - + add(WicketUtils.createTimestampLabel("repositoryLastChange", JGitUtils.getLastChange(r).when, getTimeZone(), getTimeUtils())); add(new Label("repositorySize", getRepositoryModel().size)); @@ -132,50 +133,28 @@ WicketUtils.newRepositoryParameter(repositoryName))); add(new RepositoryUrlPanel("repositoryUrlPanel", false, user, model)); - + add(new LogPanel("commitsPanel", repositoryName, getRepositoryModel().HEAD, r, numberCommits, 0, getRepositoryModel().showRemoteBranches)); add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs).hideIfEmpty()); add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs, false).hideIfEmpty()); - if (getRepositoryModel().showReadme) { - String htmlText = null; - String markdownText = null; - String readme = null; - try { - RevCommit head = JGitUtils.getCommit(r, null); - List<String> markdownExtensions = GitBlit.getStrings(Keys.web.markdownExtensions); - List<PathModel> paths = JGitUtils.getFilesInPath(r, null, head); - for (PathModel path : paths) { - if (!path.isTree()) { - String name = path.name.toLowerCase(); - - if (name.startsWith("readme")) { - if (name.indexOf('.') > -1) { - String ext = name.substring(name.lastIndexOf('.') + 1); - if (markdownExtensions.contains(ext)) { - readme = path.name; - break; - } - } - } - } - } - if (!StringUtils.isEmpty(readme)) { - String [] encodings = GitBlit.getEncodings(); - markdownText = JGitUtils.getStringContent(r, head.getTree(), readme, encodings); - htmlText = MarkdownUtils.transformMarkdown(markdownText); - } - } catch (ParseException p) { - markdownText = MessageFormat.format("<div class=\"alert alert-error\"><strong>{0}:</strong> {1}</div>{2}", getString("gb.error"), getString("gb.markdownFailure"), markdownText); - htmlText = StringUtils.breakLinesForHtml(markdownText); + if (GitBlit.getBoolean(Keys.web.summaryShowReadme, false)) { + // show a readme on the summary page + RevCommit head = JGitUtils.getCommit(r, null); + MarkupProcessor processor = new MarkupProcessor(GitBlit.getSettings()); + MarkupDocument markupDoc = processor.getReadme(r, repositoryName, getBestCommitId(head)); + if (markupDoc == null || markupDoc.markup == null) { + add(new Label("readme").setVisible(false)); + } else { + Fragment fragment = new Fragment("readme", MarkupSyntax.PLAIN.equals(markupDoc.syntax) ? "plaintextPanel" : "markdownPanel", this); + fragment.add(new Label("readmeFile", markupDoc.documentPath)); + // Add the html to the page + Component content = new Label("readmeContent", markupDoc.html).setEscapeModelStrings(false); + fragment.add(content.setVisible(!StringUtils.isEmpty(markupDoc.html))); + add(fragment); } - Fragment fragment = new Fragment("readme", "markdownPanel"); - fragment.add(new Label("readmeFile", readme)); - // Add the html to the page - Component content = new Label("readmeContent", htmlText).setEscapeModelStrings(false); - fragment.add(content.setVisible(!StringUtils.isEmpty(htmlText))); - add(fragment); } else { + // global, no readme on summary page add(new Label("readme").setVisible(false)); } -- Gitblit v1.9.1