mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 21:45:50 +01:00
Append commit message as issue comment by commit hook.
This commit is contained in:
@@ -67,24 +67,24 @@ class GitBucketReceivePackFactory extends ReceivePackFactory[HttpServletRequest]
|
||||
|
||||
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])
|
||||
|
||||
def onPostReceive(receivePack: ReceivePack, commands: java.util.Collection[ReceiveCommand]): Unit = {
|
||||
|
||||
JGitUtil.withGit(Directory.getRepositoryDir(owner, repository)) { git =>
|
||||
commands.asScala.foreach { command =>
|
||||
JGitUtil.getCommitLog(git, command.getOldId.name, command.getNewId.name).foreach { commit =>
|
||||
// TODO extract issue id and add comment to issue
|
||||
logger.debug(commit.id + ":" + commit.shortMessage)
|
||||
|
||||
println(owner + "/" + repository + " " + commit.id)
|
||||
println(commit.fullMessage)
|
||||
"(^|\\W)#(\\d+)(\\W|$)".r.findAllIn(commit.fullMessage).matchData.foreach { matchData =>
|
||||
val issueId = matchData.group(2)
|
||||
if(getAccountByUserName(commit.committer).isDefined && getIssue(owner, repository, issueId).isDefined){
|
||||
createComment(owner, repository, commit.committer, issueId.toInt, commit.fullMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update repository last modified time.
|
||||
updateLastActivityDate(owner, repository)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user