From 3fdb444961f6ed490279a1a740a7cac81fd5d35c Mon Sep 17 00:00:00 2001 From: Roy Li Date: Wed, 27 Jul 2016 11:23:29 -0700 Subject: [PATCH 001/165] Added new API to handle file upload to repository --- .../RepositoryViewerController.scala | 116 +++++++++++++++++- 1 file changed, 114 insertions(+), 2 deletions(-) diff --git a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala index 2563558d8..4c43b8b68 100644 --- a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala +++ b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala @@ -1,7 +1,8 @@ package gitbucket.core.controller -import javax.servlet.http.{HttpServletResponse, HttpServletRequest} +import javax.servlet.http.{HttpServletRequest, HttpServletResponse} +import gitbucket.core.api.UploadFiles import gitbucket.core.plugin.PluginRegistry import gitbucket.core.repo.html import gitbucket.core.helper @@ -16,7 +17,6 @@ import gitbucket.core.model.{Account, WebHook} import gitbucket.core.service.WebHookService._ import gitbucket.core.view import gitbucket.core.view.helpers - import io.github.gitbucket.scalatra.forms._ import org.apache.commons.io.FileUtils import org.eclipse.jgit.api.{ArchiveCommand, Git} @@ -526,6 +526,118 @@ trait RepositoryViewerControllerBase extends ControllerBase { } }) + /** + * Upload file to a branch. + */ + post("/:owner/:repository/files/upload")(collaboratorsOnly { repository => + defining(repository.owner, repository.name){ case (owner, name) => + (for { + data <- extractFromJsonBody[UploadFiles] if data.isValid + } yield { + Directory.getAttachedDir(owner, name) match { + case dir if (dir.exists && dir.isDirectory) => + val _commitFiles = data.fileIds.map { case (fileName, id) => + dir.listFiles.find(_.getName.startsWith(id + ".")).map { file => + val s = scala.io.Source.fromFile(file) // Codec ???? + val byteArray = s.map(_.toByte).toArray + + CommitFile(id, fileName, byteArray) + } + }.toList + + val finalCommitFiles = _commitFiles.flatten + if(finalCommitFiles.size == data.fileIds.size) { + commitFiles( + repository, + files = finalCommitFiles, + branch = data.branch, + path = data.path, + message = data.message) + } + else { + org.scalatra.NotAcceptable( + s"""{"message": + |"$repository doesn't contain all the files you specified in the body"}""".stripMargin) + } + + case _ => org.scalatra.NotFound(s"""{"message": "$repository doesn't contain any attached files"}""") + } + + }) getOrElse + org.scalatra.NotAcceptable("""{"message": "FileIds can't be an empty list"}""") + + } + }) + + /* +Roy Li modification + */ + + case class CommitFile(fileId: String, name: String, fileBytes: Array[Byte]) + + private def commitFiles(repository: RepositoryService.RepositoryInfo, + files: List[CommitFile], + branch: String, path: String, message: String) = { + + + LockUtil.lock(s"${repository.owner}/${repository.name}") { + using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git => + + val loginAccount = context.loginAccount.get + val builder = DirCache.newInCore.builder() + val inserter = git.getRepository.newObjectInserter() + val headName = s"refs/heads/${branch}" + val headTip = git.getRepository.resolve(headName) + + if(headTip != null){ + JGitUtil.processTree(git, headTip) { (path, tree) => + builder.add(JGitUtil.createDirCacheEntry(path, tree.getEntryFileMode, tree.getEntryObjectId)) + } + } + + files.foreach{item => + val fileName = item.name + val bytes = item.fileBytes + builder.add(JGitUtil.createDirCacheEntry(fileName, + FileMode.REGULAR_FILE, inserter.insert(Constants.OBJ_BLOB, bytes))) + builder.finish() + } + + val commitId = JGitUtil.createNewCommit(git, inserter, headTip, builder.getDirCache.writeTree(inserter), + headName, loginAccount.userName, loginAccount.mailAddress, message) + + inserter.flush() + inserter.close() + + // update refs + val refUpdate = git.getRepository.updateRef(headName) + refUpdate.setNewObjectId(commitId) + refUpdate.setForceUpdate(false) + refUpdate.setRefLogIdent(new PersonIdent(loginAccount.fullName, loginAccount.mailAddress)) + //refUpdate.setRefLogMessage("merged", true) + refUpdate.update() + + // update pull request + updatePullRequests(repository.owner, repository.name, branch) + + // record activity + recordPushActivity(repository.owner, repository.name, loginAccount.userName, branch, + List(new CommitInfo(JGitUtil.getRevCommitFromId(git, commitId)))) + + //call web hook + callPullRequestWebHookByRequestBranch("synchronize", repository, branch, context.baseUrl, loginAccount) + val commit = new JGitUtil.CommitInfo(JGitUtil.getRevCommitFromId(git, commitId)) + callWebHookOf(repository.owner, repository.name, WebHook.Push) { + getAccountByUserName(repository.owner).map{ ownerAccount => + WebHookPushPayload(git, loginAccount, headName, repository, List(commit), ownerAccount, + oldId = headTip, newId = commitId) + } + } + + } + } + } + private def splitPath(repository: RepositoryService.RepositoryInfo, path: String): (String, String) = { val id = repository.branchList.collectFirst { case branch if(path == branch || path.startsWith(branch + "/")) => branch From d6f8a458897b920382e419868dd8486deb193361 Mon Sep 17 00:00:00 2001 From: Roy Li Date: Wed, 27 Jul 2016 11:33:38 -0700 Subject: [PATCH 002/165] added helper case class for json body --- src/main/scala/gitbucket/core/api/UploadFiles.scala | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/scala/gitbucket/core/api/UploadFiles.scala diff --git a/src/main/scala/gitbucket/core/api/UploadFiles.scala b/src/main/scala/gitbucket/core/api/UploadFiles.scala new file mode 100644 index 000000000..e682011b6 --- /dev/null +++ b/src/main/scala/gitbucket/core/api/UploadFiles.scala @@ -0,0 +1,12 @@ +package gitbucket.core.api + + +case class UploadFiles(branch: String, path: String, fileIds : Map[String,String], message: String) +{ + def isValid: Boolean = { + + fileIds.size > 0 + } + + +} From a024491296578f00893857d3b704e9f28d7b9524 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Mon, 13 Mar 2017 11:24:02 +0900 Subject: [PATCH 003/165] Remove optimization option once --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index d219ff3a2..cf4c1303e 100644 --- a/build.sbt +++ b/build.sbt @@ -59,7 +59,7 @@ libraryDependencies ++= Seq( ) // Compiler settings -scalacOptions := Seq("-deprecation", "-language:postfixOps", "-opt:_") +scalacOptions := Seq("-deprecation", "-language:postfixOps") javacOptions in compile ++= Seq("-target", "8", "-source", "8") javaOptions in Jetty += "-Dlogback.configurationFile=/logback-dev.xml" From 0401488ab1355fd1648ca4f94cd6374967e920cd Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Mon, 13 Mar 2017 13:00:06 +0900 Subject: [PATCH 004/165] Fix styles --- src/main/twirl/gitbucket/core/settings/edithooks.scala.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/twirl/gitbucket/core/settings/edithooks.scala.html b/src/main/twirl/gitbucket/core/settings/edithooks.scala.html index 7df7107d9..812b929b8 100644 --- a/src/main/twirl/gitbucket/core/settings/edithooks.scala.html +++ b/src/main/twirl/gitbucket/core/settings/edithooks.scala.html @@ -33,9 +33,9 @@
- + +
From 7b8a5a482adb57ac93b257eefb6df09ada71670e Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Mon, 13 Mar 2017 13:00:54 +0900 Subject: [PATCH 005/165] (refs #1479)Url encode the branch name --- .../core/settings/branches.scala.html | 8 ++-- .../core/settings/branchprotection.scala.html | 44 +++++++++---------- .../webapp/assets/common/css/gitbucket.css | 14 ------ 3 files changed, 25 insertions(+), 41 deletions(-) diff --git a/src/main/twirl/gitbucket/core/settings/branches.scala.html b/src/main/twirl/gitbucket/core/settings/branches.scala.html index 75331a15e..69c3e19f5 100644 --- a/src/main/twirl/gitbucket/core/settings/branches.scala.html +++ b/src/main/twirl/gitbucket/core/settings/branches.scala.html @@ -46,14 +46,12 @@

- +
@protectedBranchList.map { branch => } @@ -64,4 +62,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/main/twirl/gitbucket/core/settings/branchprotection.scala.html b/src/main/twirl/gitbucket/core/settings/branchprotection.scala.html index 9fb7137ae..5bd54131d 100644 --- a/src/main/twirl/gitbucket/core/settings/branchprotection.scala.html +++ b/src/main/twirl/gitbucket/core/settings/branchprotection.scala.html @@ -33,30 +33,30 @@ Sorry, we couldn’t find any status checks in the last week for this repository.
Please create a commit status by API (Learn more about status checks on GitHub) - }else{ -
@branch - - Edit - + Edit
} - - + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + @repository.map { repository => } - +
diff --git a/src/main/twirl/gitbucket/core/pulls/compare.scala.html b/src/main/twirl/gitbucket/core/pulls/compare.scala.html index d97b36f0e..d390c17a2 100644 --- a/src/main/twirl/gitbucket/core/pulls/compare.scala.html +++ b/src/main/twirl/gitbucket/core/pulls/compare.scala.html @@ -43,7 +43,7 @@ }
@if(commits.nonEmpty && context.loginAccount.isDefined){ diff --git a/src/main/twirl/gitbucket/core/pulls/conversation.scala.html b/src/main/twirl/gitbucket/core/pulls/conversation.scala.html index 85e862c9c..1785c8929 100644 --- a/src/main/twirl/gitbucket/core/pulls/conversation.scala.html +++ b/src/main/twirl/gitbucket/core/pulls/conversation.scala.html @@ -21,7 +21,7 @@ @@ -63,4 +63,4 @@ $(function(){ }); } }); - \ No newline at end of file + diff --git a/src/main/twirl/gitbucket/core/repo/delete.scala.html b/src/main/twirl/gitbucket/core/repo/delete.scala.html index 57190ab82..fc7e77136 100644 --- a/src/main/twirl/gitbucket/core/repo/delete.scala.html +++ b/src/main/twirl/gitbucket/core/repo/delete.scala.html @@ -50,10 +50,10 @@ } } - - + + \ No newline at end of file + diff --git a/src/main/twirl/gitbucket/core/repo/editor.scala.html b/src/main/twirl/gitbucket/core/repo/editor.scala.html index cafbd29a1..282d0602a 100644 --- a/src/main/twirl/gitbucket/core/repo/editor.scala.html +++ b/src/main/twirl/gitbucket/core/repo/editor.scala.html @@ -72,9 +72,9 @@ } } - - - + + + + + From 46896da46e77f5e03a4d907be6f1ada07cb02a36 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Fri, 28 Apr 2017 08:26:50 +0900 Subject: [PATCH 086/165] Fix to avoid regular expression error in the filter box --- src/main/twirl/gitbucket/core/pulls/compare.scala.html | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/twirl/gitbucket/core/pulls/compare.scala.html b/src/main/twirl/gitbucket/core/pulls/compare.scala.html index 417717787..17a399a85 100644 --- a/src/main/twirl/gitbucket/core/pulls/compare.scala.html +++ b/src/main/twirl/gitbucket/core/pulls/compare.scala.html @@ -223,11 +223,12 @@ $(function(){ -} \ No newline at end of file + + } +} From a5971bbdde114c0d1216fe8f32e1b95eaf3a1229 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Sat, 6 May 2017 01:44:20 +0900 Subject: [PATCH 108/165] https://github.com/travis-ci/travis-ci/issues/7703 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 8eb0548f4..2843b3c68 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ before_script: - sudo apt-get install libaio1 - sudo /etc/init.d/mysql stop - sudo /etc/init.d/postgresql stop + - sudo chmod +x /usr/local/bin/sbt cache: directories: - $HOME/.ivy2/cache From b371f76cb6ecb65cb68ae4bd43840e55e3f183f6 Mon Sep 17 00:00:00 2001 From: t-tsutsumi Date: Sat, 6 May 2017 08:10:07 +0900 Subject: [PATCH 109/165] Fix incorrect font color when screen size 768px or less --- src/main/twirl/gitbucket/core/main.scala.html | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/twirl/gitbucket/core/main.scala.html b/src/main/twirl/gitbucket/core/main.scala.html index 13d0411c1..18fbb61c3 100644 --- a/src/main/twirl/gitbucket/core/main.scala.html +++ b/src/main/twirl/gitbucket/core/main.scala.html @@ -72,26 +72,34 @@