Skip to content

Bump to GitBucket 4.32, sbt-gitbucket-plugin 1.5.0 and Scala 2.13.0 #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This is a GitBucket plug-in which provides code snippet repository like Gist.

Plugin version | GitBucket version
:--------------|:--------------------
4.18.x | 4.32.x -
4.17.x | 4.30.x -
4.16.x | 4.26.x -
4.15.x | 4.25.x -
Expand All @@ -29,7 +30,7 @@ Plugin version | GitBucket version

## Installation

Download jar file from [plugin registry](https://plugins.gitbucket-community.org/releases/gitbucket-gist-plugin) and put into `GITBUCKET_HOME/plugins`.
Download jar file from [Releases page](https://github.com/gitbucket/gitbucket-gist-plugin/releases) and put into `GITBUCKET_HOME/plugins`.

**Note:** If you had used this plugin with GitBucket 3.x, it does not work after upgrading to GitBucket 4.x. Solution is below:

Expand Down
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
organization := "io.github.gitbucket"
name := "gitbucket-gist-plugin"
version := "4.18.0"
scalaVersion := "2.12.8"
gitbucketVersion := "4.31.2"
version := "4.18.0-SNAPSHOT"
scalaVersion := "2.13.0"
gitbucketVersion := "4.32.0"

scalacOptions := Seq("-deprecation", "-feature", "-language:postfixOps")
javacOptions in compile ++= Seq("-target", "8", "-source", "8")
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/Plugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class Plugin extends gitbucket.core.plugin.Plugin {
new Version("4.14.0"),
new Version("4.15.0"),
new Version("4.16.0"),
new Version("4.17.0")
new Version("4.17.0"),
new Version("4.18.0")
)

override def initialize(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Unit = {
Expand Down
15 changes: 8 additions & 7 deletions src/main/scala/gitbucket/gist/controller/GistController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.eclipse.jgit.lib._
import org.scalatra.Ok
import play.twirl.api.Html
import play.twirl.api.JavaScript
import scala.util.Using

class GistController extends GistControllerBase with GistService with GistCommentService with AccountService
with GistEditorAuthenticator with UsersAuthenticator
Expand Down Expand Up @@ -88,7 +89,7 @@ trait GistControllerBase extends ControllerBase {
val repoName = params("repoName")
val gitdir = new File(GistRepoDir, userName + "/" + repoName)
if(gitdir.exists){
using(Git.open(gitdir)){ git =>
Using.resource(Git.open(gitdir)){ git =>
val files: Seq[(String, JGitUtil.ContentInfo)] = JGitUtil.getFileList(git, "master", ".").map { file =>
(if(isGistFile(file.name)) "" else file.name) -> JGitUtil.getContentInfo(git, file.name, file.id)
}
Expand Down Expand Up @@ -126,7 +127,7 @@ trait GistControllerBase extends ControllerBase {
)

// Commit files
using(Git.open(gitdir)){ git =>
Using.resource(Git.open(gitdir)){ git =>
commitFiles(git, loginAccount, "Initial commit", files)
}

Expand Down Expand Up @@ -155,7 +156,7 @@ trait GistControllerBase extends ControllerBase {

// Commit files
val gitdir = new File(GistRepoDir, userName + "/" + repoName)
using(Git.open(gitdir)){ git =>
Using.resource(Git.open(gitdir)){ git =>
val commitId = commitFiles(git, loginAccount, "Update", files)

// update refs
Expand Down Expand Up @@ -189,7 +190,7 @@ trait GistControllerBase extends ControllerBase {
val repoName = params("repoName")
val gitdir = new File(GistRepoDir, userName + "/" + repoName)

using(Git.open(gitdir)){ git =>
Using.resource(Git.open(gitdir)){ git =>
JGitUtil.getCommitLog(git, "master") match {
case Right((revisions, hasNext)) => {
val commits = revisions.map { revision =>
Expand Down Expand Up @@ -222,7 +223,7 @@ trait GistControllerBase extends ControllerBase {
val fileName = params("fileName")
val gitdir = new File(GistRepoDir, userName + "/" + repoName)
if(gitdir.exists){
using(Git.open(gitdir)){ git =>
Using.resource(Git.open(gitdir)){ git =>
val gist = getGist(userName, repoName).get

if(gist.mode == "PUBLIC" || context.loginAccount.exists(x => x.isAdmin || x.userName == userName)){
Expand All @@ -245,7 +246,7 @@ trait GistControllerBase extends ControllerBase {
val userName = params("userName")
val repoName = params("repoName")

using(Git.open(new File(GistRepoDir, userName + "/" + repoName))){ git =>
Using.resource(Git.open(new File(GistRepoDir, userName + "/" + repoName))){ git =>
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve("master"))

contentType = "application/octet-stream"
Expand Down Expand Up @@ -521,7 +522,7 @@ trait GistControllerBase extends ControllerBase {

private def getGistFiles(userName: String, repoName: String, revision: String = "master"): Seq[(String, String)] = {
val gitdir = new File(GistRepoDir, userName + "/" + repoName)
using(Git.open(gitdir)){ git =>
Using.resource(Git.open(gitdir)){ git =>
JGitUtil.getFileList(git, revision, ".").map { file =>
file.name -> StringUtil.convertFromByteArray(JGitUtil.getContentFromId(git, file.id, true).get)
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/twirl/gitbucket/gist/edit.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ <h1 style="margin: 0px;">New snippet</h1>
<form id="form" method="POST" action="#">
<input type="text" name="description" id="description" class="form-control" style="margin-bottom: 8px;" value="@gist.map(_.description)" placeholder="Snippet descriptions..."/>
<div id="editors">
@files.zipWithIndex.map { case ((fileName, content), i) =>
@files.zipWithIndex.map { case ((fileName, content), i) => {
@gitbucket.gist.html.editor(i, fileName, content)
}
}}
</div>
<div>
<input type="button" value="Add file" class="btn btn-default" id="add_file">
Expand Down