mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 05:55:51 +01:00
Append commit message as issue comment by commit hook.
This commit is contained in:
@@ -50,7 +50,7 @@ class GitBucketReceivePackFactory extends ReceivePackFactory[HttpServletRequest]
|
|||||||
override def create(req: HttpServletRequest, db: Repository): ReceivePack = {
|
override def create(req: HttpServletRequest, db: Repository): ReceivePack = {
|
||||||
val receivePack = new ReceivePack(db)
|
val receivePack = new ReceivePack(db)
|
||||||
val userName = req.getAttribute("USER_NAME")
|
val userName = req.getAttribute("USER_NAME")
|
||||||
|
|
||||||
logger.debug("requestURI: " + req.getRequestURI)
|
logger.debug("requestURI: " + req.getRequestURI)
|
||||||
logger.debug("userName:" + userName)
|
logger.debug("userName:" + userName)
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ class GitBucketReceivePackFactory extends ReceivePackFactory[HttpServletRequest]
|
|||||||
val repository = pathList(3).replaceFirst("\\.git$", "")
|
val repository = pathList(3).replaceFirst("\\.git$", "")
|
||||||
|
|
||||||
logger.debug("repository:" + owner + "/" + repository)
|
logger.debug("repository:" + owner + "/" + repository)
|
||||||
|
|
||||||
receivePack.setPostReceiveHook(new CommitLogHook(owner, repository))
|
receivePack.setPostReceiveHook(new CommitLogHook(owner, repository))
|
||||||
receivePack
|
receivePack
|
||||||
}
|
}
|
||||||
@@ -67,24 +67,24 @@ class GitBucketReceivePackFactory extends ReceivePackFactory[HttpServletRequest]
|
|||||||
|
|
||||||
import scala.collection.JavaConverters._
|
import scala.collection.JavaConverters._
|
||||||
|
|
||||||
class CommitLogHook(owner: String, repository: String) extends PostReceiveHook with RepositoryService with AccountService {
|
class CommitLogHook(owner: String, repository: String) extends PostReceiveHook
|
||||||
|
with RepositoryService with AccountService with IssuesService {
|
||||||
|
|
||||||
private val logger = LoggerFactory.getLogger(classOf[CommitLogHook])
|
private val logger = LoggerFactory.getLogger(classOf[CommitLogHook])
|
||||||
|
|
||||||
def onPostReceive(receivePack: ReceivePack, commands: java.util.Collection[ReceiveCommand]): Unit = {
|
def onPostReceive(receivePack: ReceivePack, commands: java.util.Collection[ReceiveCommand]): Unit = {
|
||||||
|
|
||||||
JGitUtil.withGit(Directory.getRepositoryDir(owner, repository)) { git =>
|
JGitUtil.withGit(Directory.getRepositoryDir(owner, repository)) { git =>
|
||||||
commands.asScala.foreach { command =>
|
commands.asScala.foreach { command =>
|
||||||
JGitUtil.getCommitLog(git, command.getOldId.name, command.getNewId.name).foreach { commit =>
|
JGitUtil.getCommitLog(git, command.getOldId.name, command.getNewId.name).foreach { commit =>
|
||||||
// TODO extract issue id and add comment to issue
|
"(^|\\W)#(\\d+)(\\W|$)".r.findAllIn(commit.fullMessage).matchData.foreach { matchData =>
|
||||||
logger.debug(commit.id + ":" + commit.shortMessage)
|
val issueId = matchData.group(2)
|
||||||
|
if(getAccountByUserName(commit.committer).isDefined && getIssue(owner, repository, issueId).isDefined){
|
||||||
println(owner + "/" + repository + " " + commit.id)
|
createComment(owner, repository, commit.committer, issueId.toInt, commit.fullMessage)
|
||||||
println(commit.fullMessage)
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// update repository last modified time.
|
// update repository last modified time.
|
||||||
updateLastActivityDate(owner, repository)
|
updateLastActivityDate(owner, repository)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user