mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-12-30 20:29:58 +01:00
Change the create tag form to a dialog
This commit is contained in:
@@ -117,6 +117,12 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
diff: Option[String]
|
||||
)
|
||||
|
||||
case class TagForm(
|
||||
commitId: String,
|
||||
tagName: String,
|
||||
message: Option[String]
|
||||
)
|
||||
|
||||
val uploadForm = mapping(
|
||||
"branch" -> trim(label("Branch", text(required))),
|
||||
"path" -> trim(label("Path", text())),
|
||||
@@ -153,6 +159,12 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
"diff" -> optional(text())
|
||||
)(CommentForm.apply)
|
||||
|
||||
val tagForm = mapping(
|
||||
"commitId" -> trim(label("Commit id", text(required))),
|
||||
"tagName" -> trim(label("Tag name", text(required))),
|
||||
"message" -> trim(label("Message", optional(text())))
|
||||
)(TagForm.apply)
|
||||
|
||||
/**
|
||||
* Returns converted HTML from Markdown for preview.
|
||||
*/
|
||||
@@ -794,21 +806,25 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
})
|
||||
|
||||
/**
|
||||
* Creates a tag
|
||||
* Displays the create tag dialog.
|
||||
*/
|
||||
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))
|
||||
get("/:owner/:repository/tag/:id")(writableUsersOnly { repository =>
|
||||
html.tag(params("id"), repository)
|
||||
})
|
||||
|
||||
/**
|
||||
* Creates a tag.
|
||||
*/
|
||||
post("/:owner/:repository/tag", tagForm)(writableUsersOnly { (form, repository) =>
|
||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||
JGitUtil.createTag(git, tagName, message, commitId)
|
||||
JGitUtil.createTag(git, form.tagName, form.message, form.commitId)
|
||||
} match {
|
||||
case Right(message) =>
|
||||
flash += "info" -> message
|
||||
redirect(s"/${repository.owner}/${repository.name}/commit/${commitId}")
|
||||
redirect(s"/${repository.owner}/${repository.name}/commit/${form.commitId}")
|
||||
case Left(message) =>
|
||||
flash += "error" -> message
|
||||
redirect(s"/${repository.owner}/${repository.name}/commit/${commitId}")
|
||||
redirect(s"/${repository.owner}/${repository.name}/commit/${form.commitId}")
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -831,15 +831,16 @@ object JGitUtil {
|
||||
.find(_._1 != null)
|
||||
}
|
||||
|
||||
def createTag(git: Git, name: String, message: String, commitId: String) = {
|
||||
def createTag(git: Git, name: String, message: Option[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)
|
||||
using(new RevWalk(git.getRepository)) { walk =>
|
||||
val tagCommand = git.tag().setName(name).setObjectId(walk.parseCommit(objectId))
|
||||
message.foreach { message =>
|
||||
tagCommand.setMessage(message)
|
||||
}
|
||||
tagCommand.call()
|
||||
}
|
||||
tagCommand.call()
|
||||
Right("Tag added.")
|
||||
} catch {
|
||||
case e: GitAPIException => Left("Sorry, some Git operation error occurs.")
|
||||
|
||||
@@ -20,21 +20,7 @@
|
||||
<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>
|
||||
<a href="@helpers.url(repository)/tag/@commit.id" class="btn btn-default" rel="facebox">Add tag</a>
|
||||
}
|
||||
</div>
|
||||
<div class="commit-log">@helpers.link(commit.summary, repository)</div>
|
||||
|
||||
26
src/main/twirl/gitbucket/core/repo/tag.scala.html
Normal file
26
src/main/twirl/gitbucket/core/repo/tag.scala.html
Normal file
@@ -0,0 +1,26 @@
|
||||
@(commitId: String,
|
||||
repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(implicit context: gitbucket.core.controller.Context)
|
||||
@import gitbucket.core.view.helpers
|
||||
<h2 class="facebox-header">
|
||||
Add tag
|
||||
</h2>
|
||||
<form action="@helpers.url(repository)/tag" id="tag" method="post" validate="true">
|
||||
<fieldset style="margin-top: 20px;">
|
||||
<div class="form-group">
|
||||
<label class="control-label" for="tagName">Tag name</label>
|
||||
<input type="text" id="tagName" name="tagName" class="form-control">
|
||||
<span class="error" id="error-tagName"></span>
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<div class="form-group">
|
||||
<label class="control-label" for="message">Message</label>
|
||||
<input type="text" id="message" name="message" class="form-control">
|
||||
<span class="error" id="error-message"></span>
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class="text-right">
|
||||
<input type="hidden" name="commitId" value="@commitId">
|
||||
<input type="submit" class="btn btn-success" value="Add tag">
|
||||
</div>
|
||||
</form>
|
||||
Reference in New Issue
Block a user