Skip issue id extraction if the repository has no issues

This commit is contained in:
takezoe
2014-03-30 20:52:39 +09:00
parent 5317ac5e03
commit 84ac2974fb

View File

@@ -16,6 +16,7 @@ import service._
import WebHookService._ import WebHookService._
import org.eclipse.jgit.api.Git import org.eclipse.jgit.api.Git
import util.JGitUtil.CommitInfo import util.JGitUtil.CommitInfo
import service.IssuesService.IssueSearchCondition
/** /**
* Provides Git repository via HTTP. * Provides Git repository via HTTP.
@@ -110,19 +111,28 @@ class CommitLogHook(owner: String, repository: String, pusher: String, baseUrl:
} }
} }
// Retrieve all issue count in the repository
val issueCount =
countIssue(IssueSearchCondition(state = "open"), Map.empty, false, owner -> repository) +
countIssue(IssueSearchCondition(state = "closed"), Map.empty, false, owner -> repository)
// Extract new commit and apply issue comment // Extract new commit and apply issue comment
val newCommits = if(commits.size > 1000){ val newCommits = if(commits.size > 1000){
val existIds = getAllCommitIds(owner, repository) val existIds = getAllCommitIds(owner, repository)
commits.flatMap { commit => commits.flatMap { commit =>
if(!existIds.contains(commit.id)){ if(!existIds.contains(commit.id)){
if(issueCount > 0) {
createIssueComment(commit) createIssueComment(commit)
}
Some(commit) Some(commit)
} else None } else None
} }
} else { } else {
commits.flatMap { commit => commits.flatMap { commit =>
if(!existsCommitId(owner, repository, commit.id)){ if(!existsCommitId(owner, repository, commit.id)){
if(issueCount > 0) {
createIssueComment(commit) createIssueComment(commit)
}
Some(commit) Some(commit)
} else None } else None
} }
@@ -158,12 +168,15 @@ class CommitLogHook(owner: String, repository: String, pusher: String, baseUrl:
} }
// close issues // close issues
if(issueCount > 0) {
val defaultBranch = getRepository(owner, repository, baseUrl).get.repository.defaultBranch val defaultBranch = getRepository(owner, repository, baseUrl).get.repository.defaultBranch
if (refName(1) == "heads" && branchName == defaultBranch && command.getType == ReceiveCommand.Type.UPDATE) { if (refName(1) == "heads" && branchName == defaultBranch && command.getType == ReceiveCommand.Type.UPDATE) {
git.log.addRange(command.getOldId, command.getNewId).call.asScala.foreach { commit => git.log.addRange(command.getOldId, command.getNewId).call.asScala.foreach {
commit =>
closeIssuesFromMessage(commit.getFullMessage, pusher, owner, repository) closeIssuesFromMessage(commit.getFullMessage, pusher, owner, repository)
} }
} }
}
// call web hook // call web hook
getWebHookURLs(owner, repository) match { getWebHookURLs(owner, repository) match {