The Unified and Autonomous Development Platform
Display readme file in directory list
robin shine409c01e6efa6
diff --git a/gitplex.core/src/main/resources/git-postreceive-hook b/gitplex.core/src/main/resources/git-postreceive-hookindex 942ff54983..50d9d7c747 100644--- a/gitplex.core/src/main/resources/git-postreceive-hook+++ b/gitplex.core/src/main/resources/git-postreceive-hook@@ -1,6 +1,6 @@#!/bin/shIFS=$'\r\n';-lines=($(curl -k -s -S -f -X POST -d @- ${GITOP_URL}/git-postreceive-callback/${GITOP_REPOSITORY_ID}/${GITOP_USER_ID} 2>&1))+lines=($(curl -k -s -S -f -X POST -d @- ${GITPLEX_URL}/git-postreceive-callback/${GITPLEX_REPOSITORY_ID}/${GITPLEX_USER_ID} 2>&1))returnCode=0;diff --git a/gitplex.core/src/main/resources/git-update-hook b/gitplex.core/src/main/resources/git-update-hookindex 3cdd9342a3..1403115e5c 100644--- a/gitplex.core/src/main/resources/git-update-hook+++ b/gitplex.core/src/main/resources/git-update-hook@@ -1,7 +1,7 @@-#!/bin/bash+#!/bin/shIFS=$'\r\n';lines=($(-curl -k -s -S -f -X POST -d @- ${GITOP_URL}/git-update-callback/${GITOP_REPOSITORY_ID}/${GITOP_USER_ID} 2>&1 <<EOF+curl -k -s -S -f -X POST -d @- ${GITPLEX_URL}/git-update-callback/${GITPLEX_REPOSITORY_ID}/${GITPLEX_USER_ID} 2>&1 <<EOF$1 $2 $3EOF))diff --git a/gitplex.http/src/main/java/com/pmease/gitplex/http/GitFilter.java b/gitplex.http/src/main/java/com/pmease/gitplex/http/GitFilter.javaindex 81d8dbecd1..1feb3aedd8 100644--- a/gitplex.http/src/main/java/com/pmease/gitplex/http/GitFilter.java+++ b/gitplex.http/src/main/java/com/pmease/gitplex/http/GitFilter.java@@ -31,7 +31,7 @@ import com.pmease.commons.git.command.AdvertiseReceiveRefsCommand;import com.pmease.commons.git.command.AdvertiseUploadRefsCommand;import com.pmease.commons.git.command.ReceiveCommand;import com.pmease.commons.git.command.UploadCommand;-import com.pmease.commons.util.GeneralException;+import com.pmease.commons.git.exception.GitException;import com.pmease.gitplex.core.manager.RepositoryManager;import com.pmease.gitplex.core.manager.StorageManager;import com.pmease.gitplex.core.setting.ServerConfig;@@ -77,7 +77,7 @@ public class GitFilter implements Filter {if (StringUtils.isBlank(ownerName) || StringUtils.isBlank(repositoryName)) {String url = request.getRequestURL().toString();String urlRoot = url.substring(0, url.length()-getPathInfo(request).length());- throw new GeneralException(String.format("Expecting url of format %s<owner name>/<repository name>", urlRoot));+ throw new GitException(String.format("Expecting url of format %s<owner name>/<repository name>", urlRoot));}if (repositoryName.endsWith(".git"))@@ -85,7 +85,7 @@ public class GitFilter implements Filter {Repository repository = repositoryManager.findBy(ownerName, repositoryName);if (repository == null) {- throw new GeneralException(String.format("Unable to find repository %s owned by %s.", repositoryName, ownerName));+ throw new GitException(String.format("Unable to find repository %s owned by %s.", repositoryName, ownerName));}return repository;@@ -115,9 +115,9 @@ public class GitFilter implements Filter {elseserverUrl = "https://localhost:" + serverConfig.getSslConfig().getPort();- environments.put("GITOP_URL", serverUrl);- environments.put("GITOP_USER_ID", User.getCurrentId().toString());- environments.put("GITOP_REPOSITORY_ID", repository.getId().toString());+ environments.put("GITPLEX_URL", serverUrl);+ environments.put("GITPLEX_USER_ID", User.getCurrentId().toString());+ environments.put("GITPLEX_REPOSITORY_ID", repository.getId().toString());File gitDir = storageManager.getRepoDir(repository);if (GitSmartHttpTools.isUploadPack(request)) {@@ -183,16 +183,16 @@ public class GitFilter implements Filter {if (gitPlex.isReady())processRefs(httpRequest, httpResponse);else- throw new GeneralException("Server is not ready");+ throw new GitException("Server is not ready");} else if (GitSmartHttpTools.isReceivePack(httpRequest) || GitSmartHttpTools.isUploadPack(httpRequest)) {if (gitPlex.isReady())processPacks(httpRequest, httpResponse);else- throw new GeneralException("Server is not ready");+ throw new GitException("Server is not ready");} else {chain.doFilter(request, response);}- } catch (GeneralException e) {+ } catch (GitException e) {logger.error("Error serving git request", e);GitSmartHttpTools.sendError(httpRequest, httpResponse, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filelist/FileListPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filelist/FileListPanel.htmlindex a4b3b1b714..f997f0217c 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filelist/FileListPanel.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filelist/FileListPanel.html@@ -1,6 +1,6 @@<wicket:panel><div class="file-list autofit">- <table>+ <table class="files"><tr wicket:id="parent" class="parent"><td colspan="3"><a wicket:id="link"><i class="fa fa-level-up"></i> <span>..</span></a>@@ -16,5 +16,11 @@<td class="last-commit message"></td></tr></table>+ <div wicket:id="readme" class="readme">+ <div class="head">+ <i class="fa fa-file-text-o"></i> <span wicket:id="title"></span>+ </div>+ <div wicket:id="body" class="body"></div>+ </div></div></wicket:panel>\ No newline at end of filediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filelist/FileListPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filelist/FileListPanel.javaindex 07372544c1..982c6e80da 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filelist/FileListPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filelist/FileListPanel.java@@ -19,6 +19,7 @@ import org.apache.wicket.markup.html.basic.Label;import org.apache.wicket.markup.html.list.ListItem;import org.apache.wicket.markup.html.list.ListView;import org.apache.wicket.markup.html.panel.Panel;+import org.apache.wicket.model.AbstractReadOnlyModel;import org.apache.wicket.model.IModel;import org.apache.wicket.model.LoadableDetachableModel;import org.apache.wicket.request.mapper.parameter.PageParameters;@@ -32,17 +33,81 @@ import org.eclipse.jgit.revwalk.RevWalk;import org.eclipse.jgit.treewalk.TreeWalk;import com.google.common.base.Preconditions;+import com.pmease.commons.git.Blob;import com.pmease.commons.git.BlobIdent;+import com.pmease.commons.wicket.component.markdown.MarkdownPanel;import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.web.page.repository.file.RepoFilePage;@SuppressWarnings("serial")public abstract class FileListPanel extends Panel {+ private static final String README_NAME = "readme.md";+private final IModel<Repository> repoModel;private final BlobIdent directory;+ private final IModel<List<BlobIdent>> childrenModel = new LoadableDetachableModel<List<BlobIdent>>() {++ @Override+ protected List<BlobIdent> load() {+ try ( FileRepository jgitRepo = repoModel.getObject().openAsJGitRepo();+ RevWalk revWalk = new RevWalk(jgitRepo)) {+ RevTree revTree = revWalk.parseCommit(getCommitId()).getTree();+ TreeWalk treeWalk;+ if (directory.path != null) {+ treeWalk = Preconditions.checkNotNull(TreeWalk.forPath(jgitRepo, directory.path, revTree));+ treeWalk.enterSubtree();+ } else {+ treeWalk = new TreeWalk(jgitRepo);+ treeWalk.addTree(revTree);+ }+ List<BlobIdent> children = new ArrayList<>();+ while (treeWalk.next())+ children.add(new BlobIdent(directory.revision, treeWalk.getPathString(), treeWalk.getRawMode(0)));+ for (int i=0; i<children.size(); i++) {+ BlobIdent child = children.get(i);+ while (child.isTree()) {+ treeWalk = TreeWalk.forPath(jgitRepo, child.path, revTree);+ Preconditions.checkNotNull(treeWalk);+ treeWalk.enterSubtree();+ if (treeWalk.next()) {+ BlobIdent grandChild = new BlobIdent(directory.revision,+ treeWalk.getPathString(), treeWalk.getRawMode(0));+ if (treeWalk.next())+ break;+ else+ child = grandChild;+ } else {+ break;+ }+ }+ children.set(i, child);+ }++ Collections.sort(children);+ return children;+ } catch (IOException e) {+ throw new RuntimeException(e);+ }+ }++ };++ private final IModel<BlobIdent> readmeModel = new LoadableDetachableModel<BlobIdent>() {++ @Override+ protected BlobIdent load() {+ for (BlobIdent blobIdent: childrenModel.getObject()) {+ if (blobIdent.getName().toLowerCase().equals(README_NAME))+ return blobIdent;+ }+ return null;+ }++ };+public FileListPanel(String id, IModel<Repository> repoModel, BlobIdent directory) {super(id);@@ -93,52 +158,7 @@ public abstract class FileListPanel extends Panel {});add(parent);- add(new ListView<BlobIdent>("children", new LoadableDetachableModel<List<BlobIdent>>() {-- @Override- protected List<BlobIdent> load() {- try ( FileRepository jgitRepo = repoModel.getObject().openAsJGitRepo();- RevWalk revWalk = new RevWalk(jgitRepo)) {- RevTree revTree = revWalk.parseCommit(getCommitId()).getTree();- TreeWalk treeWalk;- if (directory.path != null) {- treeWalk = Preconditions.checkNotNull(TreeWalk.forPath(jgitRepo, directory.path, revTree));- treeWalk.enterSubtree();- } else {- treeWalk = new TreeWalk(jgitRepo);- treeWalk.addTree(revTree);- }- List<BlobIdent> children = new ArrayList<>();- while (treeWalk.next())- children.add(new BlobIdent(directory.revision, treeWalk.getPathString(), treeWalk.getRawMode(0)));- for (int i=0; i<children.size(); i++) {- BlobIdent child = children.get(i);- while (child.isTree()) {- treeWalk = TreeWalk.forPath(jgitRepo, child.path, revTree);- Preconditions.checkNotNull(treeWalk);- treeWalk.enterSubtree();- if (treeWalk.next()) {- BlobIdent grandChild = new BlobIdent(directory.revision,- treeWalk.getPathString(), treeWalk.getRawMode(0));- if (treeWalk.next())- break;- else- child = grandChild;- } else {- break;- }- }- children.set(i, child);- }-- Collections.sort(children);- return children;- } catch (IOException e) {- throw new RuntimeException(e);- }- }-- }) {+ add(new ListView<BlobIdent>("children", childrenModel) {@Overrideprotected void populateItem(ListItem<BlobIdent> item) {@@ -189,6 +209,39 @@ public abstract class FileListPanel extends Panel {});+ WebMarkupContainer readmeContainer = new WebMarkupContainer("readme") {++ @Override+ protected void onConfigure() {+ super.onConfigure();++ setVisible(readmeModel.getObject() != null);+ }++ };+ readmeContainer.add(new Label("title", new AbstractReadOnlyModel<String>() {++ @Override+ public String getObject() {+ return readmeModel.getObject().getName();+ }++ }));+ readmeContainer.add(new MarkdownPanel("body", new LoadableDetachableModel<String>() {++ @Override+ protected String load() {+ Blob blob = repoModel.getObject().getBlob(readmeModel.getObject());+ Blob.Text text = blob.getText();+ if (text != null)+ return text.getContent();+ else+ return "This seems like a binary file!";+ }++ }));+ add(readmeContainer);+setOutputMarkupId(true);}@@ -215,6 +268,8 @@ public abstract class FileListPanel extends Panel {@Overrideprotected void onDetach() {+ childrenModel.detach();+ readmeModel.detach();repoModel.detach();super.onDetach();diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filelist/file-list.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filelist/file-list.cssindex c09b17d06e..a6d9063401 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filelist/file-list.css+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filelist/file-list.css@@ -36,3 +36,15 @@.file-list>table tr.parent td a span {font-size: 18px;}+.file-list>.readme {+ border-top: 1px solid #BBB;+}+.file-list>.readme>.head {+ padding: 6px 12px;+ background: #EEE;+ font-weight: bold;+ border-bottom: 1px solid #BBB;+}+.file-list>.readme>.body {+ padding: 20px;+}\ No newline at end of filediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/repository.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/repository.jsindex d5ddc32b51..37efcddb37 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/repository.js+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/repository.js@@ -3,11 +3,7 @@ $(function() {function enableTooltip() {$nav.find("li a").each(function() {- $(this).tooltip({- title: $(this).find(".text").text(),- placement: "right",- delay: 300- });+ $(this).attr("title", $(this).find(".text").text());});}@@ -24,7 +20,7 @@ $(function() {enableTooltip();} else {Cookies.set(cookieKey, "no", {expires: Infinity});- $nav.find("li a").tooltip("destroy");+ $nav.find("li a").removeAttr("title");}$(window).resize();});