From a1ea877042b93949ef244b96e8affd65cc3f89c1 Mon Sep 17 00:00:00 2001 From: James Moger Date: Wed, 1 Jun 2011 20:19:51 -0400 Subject: [PATCH] Readme markdown on summary page per-repository. --- docs/00_setup.mkd | 1 + src/com/gitblit/GitBlit.java | 2 + src/com/gitblit/models/RepositoryModel.java | 1 + .../gitblit/wicket/GitBlitWebApp.properties | 4 +- .../wicket/pages/EditRepositoryPage.html | 7 +-- .../wicket/pages/EditRepositoryPage.java | 1 + .../gitblit/wicket/pages/MarkdownPage.html | 2 +- src/com/gitblit/wicket/pages/SummaryPage.html | 8 ++++ src/com/gitblit/wicket/pages/SummaryPage.java | 43 ++++++++++++++++++- 9 files changed, 63 insertions(+), 6 deletions(-) diff --git a/docs/00_setup.mkd b/docs/00_setup.mkd index 99fd05fc..2eddd44f 100644 --- a/docs/00_setup.mkd +++ b/docs/00_setup.mkd @@ -29,6 +29,7 @@ All repository settings are stored within the repository `.git/config` file unde showRemoteBranches = false accessRestriction = clone isFrozen = false + showReadme = false #### Repository Names Repository names must be unique and are case-insensitive. The name must be composed of letters, digits, or `/ _ - .`
diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java index 52dd9dbb..c6eb613d 100644 --- a/src/com/gitblit/GitBlit.java +++ b/src/com/gitblit/GitBlit.java @@ -203,6 +203,7 @@ public class GitBlit implements ServletContextListener { "accessRestriction", null)); model.showRemoteBranches = getConfig(config, "showRemoteBranches", false); model.isFrozen = getConfig(config, "isFrozen", false); + model.showReadme = getConfig(config, "showReadme", false); } r.close(); return model; @@ -278,6 +279,7 @@ public class GitBlit implements ServletContextListener { repository.accessRestriction.name()); config.setBoolean("gitblit", null, "showRemoteBranches", repository.showRemoteBranches); config.setBoolean("gitblit", null, "isFrozen", repository.isFrozen); + config.setBoolean("gitblit", null, "showReadme", repository.showReadme); try { config.save(); } catch (IOException e) { diff --git a/src/com/gitblit/models/RepositoryModel.java b/src/com/gitblit/models/RepositoryModel.java index afe1b5a2..97ae5184 100644 --- a/src/com/gitblit/models/RepositoryModel.java +++ b/src/com/gitblit/models/RepositoryModel.java @@ -35,6 +35,7 @@ public class RepositoryModel implements Serializable { public boolean useDocs; public AccessRestrictionType accessRestriction; public boolean isFrozen; + public boolean showReadme; public RepositoryModel() { this("", "", "", new Date(0)); diff --git a/src/com/gitblit/wicket/GitBlitWebApp.properties b/src/com/gitblit/wicket/GitBlitWebApp.properties index ac45a257..16f2aa0a 100644 --- a/src/com/gitblit/wicket/GitBlitWebApp.properties +++ b/src/com/gitblit/wicket/GitBlitWebApp.properties @@ -89,4 +89,6 @@ gb.canAdminDescription = can administer Git:Blit server gb.permittedUsers = permitted users gb.isFrozen = is frozen gb.isFrozenDescription = deny push operations -gb.zip = zip \ No newline at end of file +gb.zip = zip +gb.showReadme = show readme +gb.showReadmeDescription = show a \"readme\" markdown file on the summary page \ No newline at end of file diff --git a/src/com/gitblit/wicket/pages/EditRepositoryPage.html b/src/com/gitblit/wicket/pages/EditRepositoryPage.html index 763d46fb..775a5d22 100644 --- a/src/com/gitblit/wicket/pages/EditRepositoryPage.html +++ b/src/com/gitblit/wicket/pages/EditRepositoryPage.html @@ -21,10 +21,11 @@       -   +   +   - + diff --git a/src/com/gitblit/wicket/pages/EditRepositoryPage.java b/src/com/gitblit/wicket/pages/EditRepositoryPage.java index a1a42d00..eb2a8e64 100644 --- a/src/com/gitblit/wicket/pages/EditRepositoryPage.java +++ b/src/com/gitblit/wicket/pages/EditRepositoryPage.java @@ -164,6 +164,7 @@ public class EditRepositoryPage extends BasePage { form.add(new CheckBox("useTickets")); form.add(new CheckBox("useDocs")); form.add(new CheckBox("showRemoteBranches")); + form.add(new CheckBox("showReadme")); form.add(usersPalette); add(form); diff --git a/src/com/gitblit/wicket/pages/MarkdownPage.html b/src/com/gitblit/wicket/pages/MarkdownPage.html index b8c9cfba..a0f60904 100644 --- a/src/com/gitblit/wicket/pages/MarkdownPage.html +++ b/src/com/gitblit/wicket/pages/MarkdownPage.html @@ -19,7 +19,7 @@ -
[markdown content]
+
[markdown content]
\ No newline at end of file diff --git a/src/com/gitblit/wicket/pages/SummaryPage.html b/src/com/gitblit/wicket/pages/SummaryPage.html index ed94192a..7d5629b6 100644 --- a/src/com/gitblit/wicket/pages/SummaryPage.html +++ b/src/com/gitblit/wicket/pages/SummaryPage.html @@ -4,6 +4,12 @@ xml:lang="en" lang="en"> + + + + + + @@ -38,6 +44,8 @@
[tags panel]
+ +
\ No newline at end of file diff --git a/src/com/gitblit/wicket/pages/SummaryPage.java b/src/com/gitblit/wicket/pages/SummaryPage.java index f8206941..c054fcca 100644 --- a/src/com/gitblit/wicket/pages/SummaryPage.java +++ b/src/com/gitblit/wicket/pages/SummaryPage.java @@ -18,6 +18,7 @@ package com.gitblit.wicket.pages; import java.awt.Color; import java.awt.Dimension; import java.text.MessageFormat; +import java.text.ParseException; import java.util.ArrayList; import java.util.List; @@ -27,6 +28,7 @@ import org.apache.wicket.PageParameters; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.protocol.http.WebRequest; import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.revwalk.RevCommit; import org.wicketstuff.googlecharts.Chart; import org.wicketstuff.googlecharts.ChartAxis; import org.wicketstuff.googlecharts.ChartAxisType; @@ -42,7 +44,9 @@ import com.gitblit.Constants.AccessRestrictionType; import com.gitblit.GitBlit; import com.gitblit.Keys; import com.gitblit.models.Metric; +import com.gitblit.models.PathModel; import com.gitblit.utils.JGitUtils; +import com.gitblit.utils.MarkdownUtils; import com.gitblit.utils.MetricUtils; import com.gitblit.utils.StringUtils; import com.gitblit.utils.TimeUtils; @@ -140,6 +144,42 @@ public class SummaryPage extends RepositoryPage { add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs)); add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs)); + if (getRepositoryModel().showReadme) { + String htmlText = null; + try { + RevCommit head = JGitUtils.getCommit(r, null); + List markdownExtensions = GitBlit.getStrings(Keys.web.markdownExtensions); + List paths = JGitUtils.getFilesInPath(r, null, head); + String readme = null; + 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 markdownText = JGitUtils.getRawContentAsString(r, head, readme); + htmlText = MarkdownUtils.transformMarkdown(markdownText); + } + } catch (ParseException p) { + error(p.getMessage()); + } + // Add the html to the page + add(new Label("readme", htmlText).setEscapeModelStrings(false).setVisible( + !StringUtils.isEmpty(htmlText))); + } else { + add(new Label("readme").setVisible(false)); + } + // Display an activity line graph insertActivityGraph(metrics); } @@ -162,7 +202,8 @@ public class SummaryPage extends RepositoryPage { provider.addAxis(dateAxis); ChartAxis commitAxis = new ChartAxis(ChartAxisType.LEFT); - commitAxis.setLabels(new String[] { "", String.valueOf((int) WicketUtils.maxValue(metrics)) }); + commitAxis.setLabels(new String[] { "", + String.valueOf((int) WicketUtils.maxValue(metrics)) }); provider.addAxis(commitAxis); provider.setLineStyles(new LineStyle[] { new LineStyle(2, 4, 0), new LineStyle(0, 4, 1) }); -- 2.39.5