mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 13:35:50 +01:00
Disable the post commit hook for Wiki repository.
This commit is contained in:
@@ -69,7 +69,9 @@ class GitBucketReceivePackFactory extends ReceivePackFactory[HttpServletRequest]
|
|||||||
logger.debug("repository:" + owner + "/" + repository)
|
logger.debug("repository:" + owner + "/" + repository)
|
||||||
logger.debug("baseURL:" + baseURL)
|
logger.debug("baseURL:" + baseURL)
|
||||||
|
|
||||||
receivePack.setPostReceiveHook(new CommitLogHook(owner, repository, pusher, baseURL))
|
if(!repository.endsWith(".wiki")){
|
||||||
|
receivePack.setPostReceiveHook(new CommitLogHook(owner, repository, pusher, baseURL))
|
||||||
|
}
|
||||||
receivePack
|
receivePack
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,78 +85,85 @@ class CommitLogHook(owner: String, repository: String, pusher: String, baseURL:
|
|||||||
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 = {
|
||||||
using(Git.open(Directory.getRepositoryDir(owner, repository))) { git =>
|
try {
|
||||||
commands.asScala.foreach { command =>
|
using(Git.open(Directory.getRepositoryDir(owner, repository))) { git =>
|
||||||
logger.debug(s"commandType: ${command.getType}, refName: ${command.getRefName}")
|
commands.asScala.foreach { command =>
|
||||||
val commits = command.getType match {
|
logger.debug(s"commandType: ${command.getType}, refName: ${command.getRefName}")
|
||||||
case ReceiveCommand.Type.DELETE => Nil
|
val commits = command.getType match {
|
||||||
case _ => JGitUtil.getCommitLog(git, command.getOldId.name, command.getNewId.name)
|
case ReceiveCommand.Type.DELETE => Nil
|
||||||
}
|
case _ => JGitUtil.getCommitLog(git, command.getOldId.name, command.getNewId.name)
|
||||||
val refName = command.getRefName.split("/")
|
|
||||||
val branchName = refName.drop(2).mkString("/")
|
|
||||||
|
|
||||||
// Extract new commit and apply issue comment
|
|
||||||
val newCommits = if(commits.size > 1000){
|
|
||||||
val existIds = getAllCommitIds(owner, repository)
|
|
||||||
commits.flatMap { commit =>
|
|
||||||
if(!existIds.contains(commit.id)){
|
|
||||||
createIssueComment(commit)
|
|
||||||
Some(commit)
|
|
||||||
} else None
|
|
||||||
}
|
}
|
||||||
} else {
|
val refName = command.getRefName.split("/")
|
||||||
commits.flatMap { commit =>
|
val branchName = refName.drop(2).mkString("/")
|
||||||
if(!existsCommitId(owner, repository, commit.id)){
|
|
||||||
createIssueComment(commit)
|
|
||||||
Some(commit)
|
|
||||||
} else None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// batch insert all new commit id
|
// Extract new commit and apply issue comment
|
||||||
insertAllCommitIds(owner, repository, newCommits.map(_.id))
|
val newCommits = if(commits.size > 1000){
|
||||||
|
val existIds = getAllCommitIds(owner, repository)
|
||||||
// record activity
|
commits.flatMap { commit =>
|
||||||
if(refName(1) == "heads"){
|
if(!existIds.contains(commit.id)){
|
||||||
command.getType match {
|
createIssueComment(commit)
|
||||||
case ReceiveCommand.Type.CREATE => recordCreateBranchActivity(owner, repository, pusher, branchName)
|
Some(commit)
|
||||||
case ReceiveCommand.Type.UPDATE => recordPushActivity(owner, repository, pusher, branchName, newCommits)
|
} else None
|
||||||
case ReceiveCommand.Type.DELETE => recordDeleteBranchActivity(owner, repository, pusher, branchName)
|
|
||||||
case _ =>
|
|
||||||
}
|
|
||||||
} else if(refName(1) == "tags"){
|
|
||||||
command.getType match {
|
|
||||||
case ReceiveCommand.Type.CREATE => recordCreateTagActivity(owner, repository, pusher, branchName, newCommits)
|
|
||||||
case ReceiveCommand.Type.DELETE => recordDeleteTagActivity(owner, repository, pusher, branchName, newCommits)
|
|
||||||
case _ =>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(refName(1) == "heads"){
|
|
||||||
command.getType match {
|
|
||||||
case ReceiveCommand.Type.CREATE |
|
|
||||||
ReceiveCommand.Type.UPDATE |
|
|
||||||
ReceiveCommand.Type.UPDATE_NONFASTFORWARD =>
|
|
||||||
updatePullRequests(branchName)
|
|
||||||
case _ =>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// call web hook
|
|
||||||
getWebHookURLs(owner, repository) match {
|
|
||||||
case webHookURLs if(webHookURLs.nonEmpty) =>
|
|
||||||
for(pusherAccount <- getAccountByUserName(pusher);
|
|
||||||
ownerAccount <- getAccountByUserName(owner);
|
|
||||||
repositoryInfo <- getRepository(owner, repository, baseURL)){
|
|
||||||
callWebHook(owner, repository, webHookURLs,
|
|
||||||
WebHookPayload(git, pusherAccount, command.getRefName, repositoryInfo, newCommits, ownerAccount))
|
|
||||||
}
|
}
|
||||||
case _ =>
|
} else {
|
||||||
|
commits.flatMap { commit =>
|
||||||
|
if(!existsCommitId(owner, repository, commit.id)){
|
||||||
|
createIssueComment(commit)
|
||||||
|
Some(commit)
|
||||||
|
} else None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// batch insert all new commit id
|
||||||
|
insertAllCommitIds(owner, repository, newCommits.map(_.id))
|
||||||
|
|
||||||
|
// record activity
|
||||||
|
if(refName(1) == "heads"){
|
||||||
|
command.getType match {
|
||||||
|
case ReceiveCommand.Type.CREATE => recordCreateBranchActivity(owner, repository, pusher, branchName)
|
||||||
|
case ReceiveCommand.Type.UPDATE => recordPushActivity(owner, repository, pusher, branchName, newCommits)
|
||||||
|
case ReceiveCommand.Type.DELETE => recordDeleteBranchActivity(owner, repository, pusher, branchName)
|
||||||
|
case _ =>
|
||||||
|
}
|
||||||
|
} else if(refName(1) == "tags"){
|
||||||
|
command.getType match {
|
||||||
|
case ReceiveCommand.Type.CREATE => recordCreateTagActivity(owner, repository, pusher, branchName, newCommits)
|
||||||
|
case ReceiveCommand.Type.DELETE => recordDeleteTagActivity(owner, repository, pusher, branchName, newCommits)
|
||||||
|
case _ =>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(refName(1) == "heads"){
|
||||||
|
command.getType match {
|
||||||
|
case ReceiveCommand.Type.CREATE |
|
||||||
|
ReceiveCommand.Type.UPDATE |
|
||||||
|
ReceiveCommand.Type.UPDATE_NONFASTFORWARD =>
|
||||||
|
updatePullRequests(branchName)
|
||||||
|
case _ =>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// call web hook
|
||||||
|
getWebHookURLs(owner, repository) match {
|
||||||
|
case webHookURLs if(webHookURLs.nonEmpty) =>
|
||||||
|
for(pusherAccount <- getAccountByUserName(pusher);
|
||||||
|
ownerAccount <- getAccountByUserName(owner);
|
||||||
|
repositoryInfo <- getRepository(owner, repository, baseURL)){
|
||||||
|
callWebHook(owner, repository, webHookURLs,
|
||||||
|
WebHookPayload(git, pusherAccount, command.getRefName, repositoryInfo, newCommits, ownerAccount))
|
||||||
|
}
|
||||||
|
case _ =>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// update repository last modified time.
|
||||||
|
updateLastActivityDate(owner, repository)
|
||||||
|
} catch {
|
||||||
|
case ex: Exception => {
|
||||||
|
logger.error(ex.toString, ex)
|
||||||
|
throw ex
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// update repository last modified time.
|
|
||||||
updateLastActivityDate(owner, repository)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private def createIssueComment(commit: CommitInfo) = {
|
private def createIssueComment(commit: CommitInfo) = {
|
||||||
|
|||||||
Reference in New Issue
Block a user