From 9bcc2a3202b05aa7c4f9a1b4cf9aa6c494965072 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Tue, 3 Apr 2018 02:00:07 +0900 Subject: [PATCH 1/6] Fix a bug that fails to get the list of files of the repository root --- .../core/controller/ApiController.scala | 125 +++++++++--------- 1 file changed, 64 insertions(+), 61 deletions(-) diff --git a/src/main/scala/gitbucket/core/controller/ApiController.scala b/src/main/scala/gitbucket/core/controller/ApiController.scala index 1cf042db6..79fd56ebe 100644 --- a/src/main/scala/gitbucket/core/controller/ApiController.scala +++ b/src/main/scala/gitbucket/core/controller/ApiController.scala @@ -158,10 +158,21 @@ trait ApiControllerBase extends ControllerBase { }) getOrElse NotFound() }) + /* + * https://developer.github.com/v3/repos/contents/#get-contents + */ + get("/api/v3/repos/:owner/:repo/contents")(referrersOnly { repository => + getContents(repository, ".", params.getOrElse("ref", repository.repository.defaultBranch)) + }) + /* * https://developer.github.com/v3/repos/contents/#get-contents */ get("/api/v3/repos/:owner/:repo/contents/*")(referrersOnly { repository => + getContents(repository, multiParams("splat").head, params.getOrElse("ref", repository.repository.defaultBranch)) + }) + + private def getContents(repository: RepositoryService.RepositoryInfo, path: String, refStr: String) = { def getFileInfo(git: Git, revision: String, pathStr: String): Option[FileInfo] = { val (dirName, fileName) = pathStr.lastIndexOf('/') match { case -1 => @@ -172,69 +183,61 @@ trait ApiControllerBase extends ControllerBase { getFileList(git, revision, dirName).find(f => f.name.equals(fileName)) } - val path = multiParams("splat").head match { - case s if s.isEmpty => "." - case s => s - } - val refStr = params.getOrElse("ref", repository.repository.defaultBranch) - - using(Git.open(getRepositoryDir(params("owner"), params("repo")))) { - git => - val fileList = getFileList(git, refStr, path) - if (fileList.isEmpty) { // file or NotFound - getFileInfo(git, refStr, path) - .flatMap(f => { - val largeFile = params.get("large_file").exists(s => s.equals("true")) - val content = getContentFromId(git, f.id, largeFile) - request.getHeader("Accept") match { - case "application/vnd.github.v3.raw" => { - contentType = "application/vnd.github.v3.raw" - content - } - case "application/vnd.github.v3.html" if isRenderable(f.name) => { - contentType = "application/vnd.github.v3.html" - content.map( - c => - List( - "
", - "
", - renderMarkup(path.split("/").toList, new String(c), refStr, repository, false, false, true).body, - "
", - "
" - ).mkString - ) - } - case "application/vnd.github.v3.html" => { - contentType = "application/vnd.github.v3.html" - content.map( - c => - List( - "
", - "
", - "
",
-                        play.twirl.api.HtmlFormat.escape(new String(c)).body,
-                        "
", - "
", - "
" - ).mkString - ) - } - case _ => - Some(JsonFormat(ApiContents(f, RepositoryName(repository), content))) + using(Git.open(getRepositoryDir(params("owner"), params("repo")))) { git => + val fileList = getFileList(git, refStr, path) + if (fileList.isEmpty) { // file or NotFound + getFileInfo(git, refStr, path) + .flatMap { f => + val largeFile = params.get("large_file").exists(s => s.equals("true")) + val content = getContentFromId(git, f.id, largeFile) + request.getHeader("Accept") match { + case "application/vnd.github.v3.raw" => { + contentType = "application/vnd.github.v3.raw" + content } - }) - .getOrElse(NotFound()) - } else { // directory - JsonFormat(fileList.map { f => - ApiContents(f, RepositoryName(repository), None) - }) - } + case "application/vnd.github.v3.html" if isRenderable(f.name) => { + contentType = "application/vnd.github.v3.html" + content.map { c => + List( + "
", + "
", + renderMarkup(path.split("/").toList, new String(c), refStr, repository, false, false, true).body, + "
", + "
" + ).mkString + } + } + case "application/vnd.github.v3.html" => { + contentType = "application/vnd.github.v3.html" + content.map { c => + List( + "
", + "
", + "
",
+                    play.twirl.api.HtmlFormat.escape(new String(c)).body,
+                    "
", + "
", + "
" + ).mkString + } + } + case _ => + Some(JsonFormat(ApiContents(f, RepositoryName(repository), content))) + } + } + .getOrElse(NotFound()) + + } else { // directory + JsonFormat(fileList.map { f => + ApiContents(f, RepositoryName(repository), None) + }) + } } - }) + } /* * https://developer.github.com/v3/git/refs/#get-a-reference From 170a48de36d57215f6d31c7f07fc30f24a925735 Mon Sep 17 00:00:00 2001 From: kenji yoshida <6b656e6a69@gmail.com> Date: Sun, 8 Apr 2018 14:45:37 +0900 Subject: [PATCH 2/6] sbt 1.1.3 --- project/build.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/build.properties b/project/build.properties index 05313438a..609a2d115 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.1.2 +sbt.version=1.1.3 From bd69821f1d895fc0a1c54a14451c3b5330658e3b Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Mon, 9 Apr 2018 19:45:47 +0900 Subject: [PATCH 3/6] Bump to 4.23.1 --- build.sbt | 2 +- src/main/scala/gitbucket/core/GitBucketCoreModule.scala | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/build.sbt b/build.sbt index 4b6145e96..10723d9f2 100644 --- a/build.sbt +++ b/build.sbt @@ -3,7 +3,7 @@ import com.typesafe.sbt.pgp.PgpKeys._ val Organization = "io.github.gitbucket" val Name = "gitbucket" -val GitBucketVersion = "4.23.0" +val GitBucketVersion = "4.23.1" val ScalatraVersion = "2.6.1" val JettyVersion = "9.4.7.v20170914" diff --git a/src/main/scala/gitbucket/core/GitBucketCoreModule.scala b/src/main/scala/gitbucket/core/GitBucketCoreModule.scala index 4c2a3c4a7..bcca99216 100644 --- a/src/main/scala/gitbucket/core/GitBucketCoreModule.scala +++ b/src/main/scala/gitbucket/core/GitBucketCoreModule.scala @@ -50,5 +50,6 @@ object GitBucketCoreModule new Version("4.21.1"), new Version("4.21.2"), new Version("4.22.0", new LiquibaseMigration("update/gitbucket-core_4.22.xml")), - new Version("4.23.0", new LiquibaseMigration("update/gitbucket-core_4.23.xml")) + new Version("4.23.0", new LiquibaseMigration("update/gitbucket-core_4.23.xml")), + new Version("4.23.1") ) From 5cb26247fc7f11943b28a0f80c8775f816a6e92b Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Tue, 10 Apr 2018 02:38:06 +0900 Subject: [PATCH 4/6] Update README.md and CHANGELOG.md for GitBucket 4.23.1 release --- CHANGELOG.md | 5 +++++ README.md | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8ac29d98..ecfed8f04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog All changes to the project will be documented in this file. +### 4.23.1 - 10 Apr 2018 +- Fix bug that the contents API doesn't work for the repository root +- Fix shutdown problem in Tomcat deployment +- Render by plugins at the blob view even if it's a binary file + ### 4.23.0 - 31 Mar 2018 - Allow tail slash in URL - Display commit message of tags at the releases page diff --git a/README.md b/README.md index e74498d2a..59c0b078f 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,11 @@ Support What's New in 4.23.x ------------- +### 4.23.1 - 10 Apr 2018 +- Fix bug that the contents API doesn't work for the repository root +- Fix shutdown problem in Tomcat deployment +- Render by plugins at the blob view even if it's a binary file + ### 4.23.0 - 31 Mar 2018 - Allow tail slash in URL - Display commit message of tags at the releases page From 3f1ea419d694f765ddea8d2b54cc382441a53705 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Sun, 15 Apr 2018 02:10:14 +0900 Subject: [PATCH 5/6] Keep wrap mode of Ace editor using localStorage --- src/main/twirl/gitbucket/core/repo/editor.scala.html | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/twirl/gitbucket/core/repo/editor.scala.html b/src/main/twirl/gitbucket/core/repo/editor.scala.html index 554a85adf..21e1d286e 100644 --- a/src/main/twirl/gitbucket/core/repo/editor.scala.html +++ b/src/main/twirl/gitbucket/core/repo/editor.scala.html @@ -82,7 +82,11 @@ $(function(){ $('#editor').text($('#initial').val()); var editor = ace.edit("editor"); editor.setTheme("ace/theme/monokai"); - //editor.getSession().setUseWrapMode(false); + + if(localStorage.getItem('gitbucket.editor.wrap') == 'true'){ + editor.getSession().setUseWrapMode(true); + $('#wrap').val('true'); + } @if(fileName.isDefined){ editor.getSession().setMode("ace/mode/@helpers.editorType(fileName.get)"); @@ -106,8 +110,10 @@ $(function(){ $('#wrap').change(function(){ if($('#wrap option:selected').val() == 'true'){ editor.getSession().setUseWrapMode(true); + localStorage.setItem('gitbucket.editor.wrap', 'true'); } else { editor.getSession().setUseWrapMode(false); + localStorage.setItem('gitbucket.editor.wrap', 'false'); } }); From 35655f33c7713f08515ed640ece0948acd6d6168 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Sun, 15 Apr 2018 12:11:31 +0900 Subject: [PATCH 6/6] Change local storage key --- src/main/twirl/gitbucket/core/repo/editor.scala.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/twirl/gitbucket/core/repo/editor.scala.html b/src/main/twirl/gitbucket/core/repo/editor.scala.html index 21e1d286e..9b984fe64 100644 --- a/src/main/twirl/gitbucket/core/repo/editor.scala.html +++ b/src/main/twirl/gitbucket/core/repo/editor.scala.html @@ -83,7 +83,7 @@ $(function(){ var editor = ace.edit("editor"); editor.setTheme("ace/theme/monokai"); - if(localStorage.getItem('gitbucket.editor.wrap') == 'true'){ + if(localStorage.getItem('gitbucket:editor:wrap') == 'true'){ editor.getSession().setUseWrapMode(true); $('#wrap').val('true'); } @@ -110,10 +110,10 @@ $(function(){ $('#wrap').change(function(){ if($('#wrap option:selected').val() == 'true'){ editor.getSession().setUseWrapMode(true); - localStorage.setItem('gitbucket.editor.wrap', 'true'); + localStorage.setItem('gitbucket:editor:wrap', 'true'); } else { editor.getSession().setUseWrapMode(false); - localStorage.setItem('gitbucket.editor.wrap', 'false'); + localStorage.setItem('gitbucket:editor:wrap', 'false'); } });