Merge remote-tracking branch 'upstream/master' into pr-multi-mailaddress

# Conflicts:
#	src/main/scala/gitbucket/core/GitBucketCoreModule.scala
This commit is contained in:
KOUNOIKE Yuusuke
2018-04-15 13:33:08 +09:00
7 changed files with 85 additions and 64 deletions

View File

@@ -1,6 +1,11 @@
# Changelog # Changelog
All changes to the project will be documented in this file. 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 ### 4.23.0 - 31 Mar 2018
- Allow tail slash in URL - Allow tail slash in URL
- Display commit message of tags at the releases page - Display commit message of tags at the releases page

View File

@@ -70,6 +70,11 @@ Support
What's New in 4.23.x 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 ### 4.23.0 - 31 Mar 2018
- Allow tail slash in URL - Allow tail slash in URL
- Display commit message of tags at the releases page - Display commit message of tags at the releases page

View File

@@ -3,7 +3,7 @@ import com.typesafe.sbt.pgp.PgpKeys._
val Organization = "io.github.gitbucket" val Organization = "io.github.gitbucket"
val Name = "gitbucket" val Name = "gitbucket"
val GitBucketVersion = "4.23.0" val GitBucketVersion = "4.23.1"
val ScalatraVersion = "2.6.1" val ScalatraVersion = "2.6.1"
val JettyVersion = "9.4.7.v20170914" val JettyVersion = "9.4.7.v20170914"

View File

@@ -1 +1 @@
sbt.version=1.1.2 sbt.version=1.1.3

View File

@@ -51,5 +51,7 @@ object GitBucketCoreModule
new Version("4.21.2"), new Version("4.21.2"),
new Version("4.22.0", new LiquibaseMigration("update/gitbucket-core_4.22.xml")), 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.0", new LiquibaseMigration("update/gitbucket-core_4.23.xml")),
new Version("4.23.1")
new Version("4.24.0", new LiquibaseMigration("update/gitbucket-core_4.24.xml")) new Version("4.24.0", new LiquibaseMigration("update/gitbucket-core_4.24.xml"))
) )

View File

@@ -158,10 +158,21 @@ trait ApiControllerBase extends ControllerBase {
}) getOrElse NotFound() }) 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 * https://developer.github.com/v3/repos/contents/#get-contents
*/ */
get("/api/v3/repos/:owner/:repo/contents/*")(referrersOnly { repository => 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] = { def getFileInfo(git: Git, revision: String, pathStr: String): Option[FileInfo] = {
val (dirName, fileName) = pathStr.lastIndexOf('/') match { val (dirName, fileName) = pathStr.lastIndexOf('/') match {
case -1 => case -1 =>
@@ -172,69 +183,61 @@ trait ApiControllerBase extends ControllerBase {
getFileList(git, revision, dirName).find(f => f.name.equals(fileName)) getFileList(git, revision, dirName).find(f => f.name.equals(fileName))
} }
val path = multiParams("splat").head match { using(Git.open(getRepositoryDir(params("owner"), params("repo")))) { git =>
case s if s.isEmpty => "." val fileList = getFileList(git, refStr, path)
case s => s if (fileList.isEmpty) { // file or NotFound
} getFileInfo(git, refStr, path)
val refStr = params.getOrElse("ref", repository.repository.defaultBranch) .flatMap { f =>
val largeFile = params.get("large_file").exists(s => s.equals("true"))
using(Git.open(getRepositoryDir(params("owner"), params("repo")))) { val content = getContentFromId(git, f.id, largeFile)
git => request.getHeader("Accept") match {
val fileList = getFileList(git, refStr, path) case "application/vnd.github.v3.raw" => {
if (fileList.isEmpty) { // file or NotFound contentType = "application/vnd.github.v3.raw"
getFileInfo(git, refStr, path) content
.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(
"<div data-path=\"",
path,
"\" id=\"file\">",
"<article>",
renderMarkup(path.split("/").toList, new String(c), refStr, repository, false, false, true).body,
"</article>",
"</div>"
).mkString
)
}
case "application/vnd.github.v3.html" => {
contentType = "application/vnd.github.v3.html"
content.map(
c =>
List(
"<div data-path=\"",
path,
"\" id=\"file\">",
"<div class=\"plain\">",
"<pre>",
play.twirl.api.HtmlFormat.escape(new String(c)).body,
"</pre>",
"</div>",
"</div>"
).mkString
)
}
case _ =>
Some(JsonFormat(ApiContents(f, RepositoryName(repository), content)))
} }
}) case "application/vnd.github.v3.html" if isRenderable(f.name) => {
.getOrElse(NotFound()) contentType = "application/vnd.github.v3.html"
} else { // directory content.map { c =>
JsonFormat(fileList.map { f => List(
ApiContents(f, RepositoryName(repository), None) "<div data-path=\"",
}) path,
} "\" id=\"file\">",
"<article>",
renderMarkup(path.split("/").toList, new String(c), refStr, repository, false, false, true).body,
"</article>",
"</div>"
).mkString
}
}
case "application/vnd.github.v3.html" => {
contentType = "application/vnd.github.v3.html"
content.map { c =>
List(
"<div data-path=\"",
path,
"\" id=\"file\">",
"<div class=\"plain\">",
"<pre>",
play.twirl.api.HtmlFormat.escape(new String(c)).body,
"</pre>",
"</div>",
"</div>"
).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 * https://developer.github.com/v3/git/refs/#get-a-reference

View File

@@ -82,7 +82,11 @@ $(function(){
$('#editor').text($('#initial').val()); $('#editor').text($('#initial').val());
var editor = ace.edit("editor"); var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai"); 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){ @if(fileName.isDefined){
editor.getSession().setMode("ace/mode/@helpers.editorType(fileName.get)"); editor.getSession().setMode("ace/mode/@helpers.editorType(fileName.get)");
@@ -106,8 +110,10 @@ $(function(){
$('#wrap').change(function(){ $('#wrap').change(function(){
if($('#wrap option:selected').val() == 'true'){ if($('#wrap option:selected').val() == 'true'){
editor.getSession().setUseWrapMode(true); editor.getSession().setUseWrapMode(true);
localStorage.setItem('gitbucket:editor:wrap', 'true');
} else { } else {
editor.getSession().setUseWrapMode(false); editor.getSession().setUseWrapMode(false);
localStorage.setItem('gitbucket:editor:wrap', 'false');
} }
}); });