Merge branch 'pr-create-tag' of https://github.com/kounoike/gitbucket into kounoike-pr-create-tag

This commit is contained in:
Naoki Takezoe
2018-07-23 11:25:35 +09:00
3 changed files with 63 additions and 10 deletions

View File

@@ -542,7 +542,9 @@ trait RepositoryViewerControllerBase extends ControllerBase {
repository,
diffs,
oldCommitId,
hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
hasDeveloperRole(repository.owner, repository.name, context.loginAccount),
flash.get("info"),
flash.get("error")
)
}
}
@@ -791,6 +793,25 @@ trait RepositoryViewerControllerBase extends ControllerBase {
html.branches(branches, hasDeveloperRole(repository.owner, repository.name, context.loginAccount), repository)
})
/**
* Creates a tag
*/
post("/:owner/:repository/tags")(writableUsersOnly { repository =>
val tagName = params.getOrElse("name", halt(400))
val message = params.getOrElse("message", halt(400))
val commitId = params.getOrElse("commit", halt(400))
using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
JGitUtil.createTag(git, tagName, message, commitId)
} match {
case Right(message) =>
flash += "info" -> message
redirect(s"/${repository.owner}/${repository.name}/commit/${commitId}")
case Left(message) =>
flash += "error" -> message
redirect(s"/${repository.owner}/${repository.name}/commit/${commitId}")
}
})
/**
* Creates a branch.
*/

View File

@@ -23,12 +23,7 @@ import java.util.concurrent.TimeUnit
import java.util.function.Consumer
import org.cache2k.Cache2kBuilder
import org.eclipse.jgit.api.errors.{
InvalidRefNameException,
JGitInternalException,
NoHeadException,
RefAlreadyExistsException
}
import org.eclipse.jgit.api.errors._
import org.eclipse.jgit.diff.{DiffEntry, DiffFormatter, RawTextComparator}
import org.eclipse.jgit.dircache.DirCacheEntry
import org.eclipse.jgit.util.io.DisabledOutputStream
@@ -836,6 +831,24 @@ object JGitUtil {
.find(_._1 != null)
}
def createTag(git: Git, name: String, message: String, commitId: String) = {
try {
val objectId: ObjectId = git.getRepository.resolve(commitId)
val walk: RevWalk = new RevWalk(git.getRepository)
val tagCommand = git.tag().setName(name).setObjectId(walk.parseCommit(objectId))
if (!message.isEmpty) {
tagCommand.setMessage(message)
}
tagCommand.call()
Right("Tag added.")
} catch {
case e: GitAPIException => Left("Sorry, some Git operation error occurs.")
case e: ConcurrentRefUpdateException => Left("Sorry some error occurs.")
case e: InvalidTagNameException => Left("Sorry, that name is invalid.")
case e: NoHeadException => Left("Sorry, this repo doesn't have HEAD reference")
}
}
def createBranch(git: Git, fromBranch: String, newBranch: String) = {
try {
git.branchCreate().setStartPoint(fromBranch).setName(newBranch).call()

View File

@@ -6,17 +6,36 @@
repository: gitbucket.core.service.RepositoryService.RepositoryInfo,
diffs: Seq[gitbucket.core.util.JGitUtil.DiffInfo],
oldCommitId: Option[String],
hasWritePermission: Boolean)(implicit context: gitbucket.core.controller.Context)
hasWritePermission: Boolean,
info: Option[Any] = None,
error: Option[Any] = None)(implicit context: gitbucket.core.controller.Context)
@import gitbucket.core.view.helpers
@import gitbucket.core.view.helpers.RichHtmlSeq
@import gitbucket.core.model._
@gitbucket.core.html.main(commit.shortMessage, Some(repository)){
@gitbucket.core.html.menu("files", repository){
@gitbucket.core.html.menu("files", repository, None, info, error){
<table class="table table-bordered">
<tr>
<th class="box-header">
<div class="pull-right align-right">
<div class="pull-right align-right btn-group">
<a href="@helpers.url(repository)/tree/@commit.id" class="btn btn-default">Browse code</a>
@if(hasWritePermission) {
<button class="dropdown-toggle btn btn-default" data-toggle="dropdown" aria-expanded="false">Add tag</button>
<ul class="dropdown-menu input-tag">
<form action="@helpers.url(repository)/tags" method="post">
<li>
<input type="text" name="name" placeholder="Tag name" class="form-control input-sm dropdown-filter-input">
</li>
<li>
<input type="text" name="message" placeholder="Message" class="form-control input-sm dropdown-filter-input">
</li>
<li>
<input type="hidden" name="commit" value="@commit.id">
<button type="submit" class="btn btn-default">Add tag</button>
</li>
</form>
</ul>
}
</div>
<div class="commit-log">@helpers.link(commit.summary, repository)</div>
@if(commit.description.isDefined){