mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 21:45:50 +01:00
(refs #60)Mentioned issue reference from other issue or issue comment.
This commit is contained in:
@@ -4,10 +4,11 @@ import jp.sf.amateras.scalatra.forms._
|
|||||||
|
|
||||||
import service._
|
import service._
|
||||||
import IssuesService._
|
import IssuesService._
|
||||||
import util.{CollaboratorsAuthenticator, ReferrerAuthenticator, ReadableUsersAuthenticator, Notifier, Keys}
|
import util._
|
||||||
import util.Implicits._
|
import util.Implicits._
|
||||||
import util.ControlUtil._
|
import util.ControlUtil._
|
||||||
import org.scalatra.Ok
|
import org.scalatra.Ok
|
||||||
|
import model.Issue
|
||||||
|
|
||||||
class IssuesController extends IssuesControllerBase
|
class IssuesController extends IssuesControllerBase
|
||||||
with IssuesService with RepositoryService with AccountService with LabelsService with MilestonesService with ActivityService
|
with IssuesService with RepositoryService with AccountService with LabelsService with MilestonesService with ActivityService
|
||||||
@@ -110,6 +111,11 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
// record activity
|
// record activity
|
||||||
recordCreateIssueActivity(owner, name, userName, issueId, form.title)
|
recordCreateIssueActivity(owner, name, userName, issueId, form.title)
|
||||||
|
|
||||||
|
// extract references and create refer comment
|
||||||
|
getIssue(owner, name, issueId.toString).foreach { issue =>
|
||||||
|
createReferComment(owner, name, issue, form.title + " " + form.content.getOrElse(""))
|
||||||
|
}
|
||||||
|
|
||||||
// notifications
|
// notifications
|
||||||
Notifier().toNotify(repository, issueId, form.content.getOrElse("")){
|
Notifier().toNotify(repository, issueId, form.content.getOrElse("")){
|
||||||
Notifier.msgIssue(s"${baseUrl}/${owner}/${name}/issues/${issueId}")
|
Notifier.msgIssue(s"${baseUrl}/${owner}/${name}/issues/${issueId}")
|
||||||
@@ -123,7 +129,11 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
defining(repository.owner, repository.name){ case (owner, name) =>
|
defining(repository.owner, repository.name){ case (owner, name) =>
|
||||||
getIssue(owner, name, params("id")).map { issue =>
|
getIssue(owner, name, params("id")).map { issue =>
|
||||||
if(isEditable(owner, name, issue.openedUserName)){
|
if(isEditable(owner, name, issue.openedUserName)){
|
||||||
|
// update issue
|
||||||
updateIssue(owner, name, issue.issueId, form.title, form.content)
|
updateIssue(owner, name, issue.issueId, form.title, form.content)
|
||||||
|
// extract references and create refer comment
|
||||||
|
createReferComment(owner, name, issue, form.title + " " + form.content.getOrElse(""))
|
||||||
|
|
||||||
redirect(s"/${owner}/${name}/issues/_data/${issue.issueId}")
|
redirect(s"/${owner}/${name}/issues/_data/${issue.issueId}")
|
||||||
} else Unauthorized
|
} else Unauthorized
|
||||||
} getOrElse NotFound
|
} getOrElse NotFound
|
||||||
@@ -274,6 +284,15 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
redirect(s"/${repository.owner}/${repository.name}/issues")
|
redirect(s"/${repository.owner}/${repository.name}/issues")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private def createReferComment(owner: String, repository: String, fromIssue: Issue, message: String) = {
|
||||||
|
StringUtil.extractIssueId(message).foreach { issueId =>
|
||||||
|
if(getIssue(owner, repository, issueId).isDefined){
|
||||||
|
createComment(owner, repository, context.loginAccount.get.userName, issueId.toInt,
|
||||||
|
fromIssue.issueId + ":" + fromIssue.title, "refer")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see [[https://github.com/takezoe/gitbucket/wiki/CommentAction]]
|
* @see [[https://github.com/takezoe/gitbucket/wiki/CommentAction]]
|
||||||
*/
|
*/
|
||||||
@@ -313,6 +332,11 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
recordActivity foreach ( _ (owner, name, userName, issueId, issue.title) )
|
recordActivity foreach ( _ (owner, name, userName, issueId, issue.title) )
|
||||||
|
|
||||||
|
// extract references and create refer comment
|
||||||
|
content.map { content =>
|
||||||
|
createReferComment(owner, name, issue, content)
|
||||||
|
}
|
||||||
|
|
||||||
// notifications
|
// notifications
|
||||||
Notifier() match {
|
Notifier() match {
|
||||||
case f =>
|
case f =>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import org.slf4j.LoggerFactory
|
|||||||
import javax.servlet.ServletConfig
|
import javax.servlet.ServletConfig
|
||||||
import javax.servlet.ServletContext
|
import javax.servlet.ServletContext
|
||||||
import javax.servlet.http.HttpServletRequest
|
import javax.servlet.http.HttpServletRequest
|
||||||
import util.{Keys, JGitUtil, Directory}
|
import util.{StringUtil, Keys, JGitUtil, Directory}
|
||||||
import util.ControlUtil._
|
import util.ControlUtil._
|
||||||
import util.Implicits._
|
import util.Implicits._
|
||||||
import service._
|
import service._
|
||||||
@@ -167,8 +167,7 @@ class CommitLogHook(owner: String, repository: String, pusher: String, baseURL:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private def createIssueComment(commit: CommitInfo) = {
|
private def createIssueComment(commit: CommitInfo) = {
|
||||||
"(^|\\W)#(\\d+)(\\W|$)".r.findAllIn(commit.fullMessage).matchData.foreach { matchData =>
|
StringUtil.extractIssueId(commit.fullMessage).foreach { issueId =>
|
||||||
val issueId = matchData.group(2)
|
|
||||||
if(getIssue(owner, repository, issueId).isDefined){
|
if(getIssue(owner, repository, issueId).isDefined){
|
||||||
getAccountByMailAddress(commit.mailAddress).foreach { account =>
|
getAccountByMailAddress(commit.mailAddress).foreach { account =>
|
||||||
createComment(owner, repository, account.userName, issueId.toInt, commit.fullMessage + " " + commit.id, "commit")
|
createComment(owner, repository, account.userName, issueId.toInt, commit.fullMessage + " " + commit.id, "commit")
|
||||||
|
|||||||
@@ -45,4 +45,14 @@ object StringUtil {
|
|||||||
case e => e
|
case e => e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract issue id like ````#issueId``` from the given message.
|
||||||
|
*
|
||||||
|
*@param message the message which may contains issue id
|
||||||
|
* @return the iterator of issue id
|
||||||
|
*/
|
||||||
|
def extractIssueId(message: String): Iterator[String] =
|
||||||
|
"(^|\\W)#(\\d+)(\\W|$)".r.findAllIn(message).matchData.map { matchData => matchData.group(2) }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,16 @@
|
|||||||
<div class="box issue-comment-box" id="comment-@comment.commentId">
|
<div class="box issue-comment-box" id="comment-@comment.commentId">
|
||||||
<div class="box-header-small">
|
<div class="box-header-small">
|
||||||
<i class="icon-comment"></i>
|
<i class="icon-comment"></i>
|
||||||
@user(comment.commentedUserName, styleClass="username strong") commented
|
@user(comment.commentedUserName, styleClass="username strong")
|
||||||
|
@if(comment.action == "comment"){
|
||||||
|
commented
|
||||||
|
} else {
|
||||||
|
@if(pullreq.isEmpty){ referenced the issue } else { referenced the pull request }
|
||||||
|
}
|
||||||
<span class="pull-right">
|
<span class="pull-right">
|
||||||
@datetime(comment.registeredDate)
|
@datetime(comment.registeredDate)
|
||||||
@if(comment.action != "commit" && comment.action != "merge" && (hasWritePermission || loginAccount.map(_.userName == comment.commentedUserName).getOrElse(false))){
|
@if(comment.action != "commit" && comment.action != "merge" && comment.action != "refer" &&
|
||||||
|
(hasWritePermission || loginAccount.map(_.userName == comment.commentedUserName).getOrElse(false))){
|
||||||
<a href="#" data-comment-id="@comment.commentId"><i class="icon-pencil"></i></a>
|
<a href="#" data-comment-id="@comment.commentId"><i class="icon-pencil"></i></a>
|
||||||
<a href="#" data-comment-id="@comment.commentId"><i class="icon-remove-circle"></i></a>
|
<a href="#" data-comment-id="@comment.commentId"><i class="icon-remove-circle"></i></a>
|
||||||
}
|
}
|
||||||
@@ -26,9 +32,15 @@
|
|||||||
<div class="pull-right"><a href="@path/@repository.owner/@repository.name/commit/@id" class="monospace">@id.substring(0, 7)</a></div>
|
<div class="pull-right"><a href="@path/@repository.owner/@repository.name/commit/@id" class="monospace">@id.substring(0, 7)</a></div>
|
||||||
@markdown(comment.content.substring(0, comment.content.length - 41), repository, false, true)
|
@markdown(comment.content.substring(0, comment.content.length - 41), repository, false, true)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
@if(comment.action == "refer"){
|
||||||
|
@defining(comment.content.split(":")){ case Array(issueId, rest @ _*) =>
|
||||||
|
<strong><a href="@path/@repository.owner/@repository.name/issues/@issueId">Issue #@issueId</a>: @rest.mkString(":")</strong>
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
@markdown(comment.content, repository, false, true)
|
@markdown(comment.content, repository, false, true)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user