Hi, I'm using ScriptRunner to write a Pre-receive hook. In this customized script, I used the matchingChangsCollector. But there is an error show -
[Static type checking] - Cannot call java.util.Collection #pathsMatch(com.atlassian.bitbucket.repository.Repository, java.lang.String, groovy.lang.Closure ) with arguments [com.atlassian.bitbucket.repository.Repository, java.lang.String, groovy.lang.Closure ] @ line 24, column 5.
Basically, I just used the sample code from - https://scriptrunner.adaptavist.com/5.6.3/bitbucket/
import com.atlassian.bitbucket.content.Change
import com.atlassian.bitbucket.repository.RefChange
import com.atlassian.bitbucket.repository.Repository
def repository = repository as Repository
def refChanges = refChanges as Collection<RefChange>
def hookMsg = ""
def matchingChangesCollector = { Iterable<Change> matchingChanges ->
hookMsg << "The following changes containing private ssh keys were blocked:\n"
matchingChanges.each { change ->
def message = "Id: ${shortId(change.contentId)}, Path: ${change.path.toString()}\n"
hookMsg << message
}
}
refChanges.pathsMatch(repository, "glob:id_rsa", matchingChangesCollector)
private String shortId(String contentId) {
contentId.substring(0, 11)
}
Thank you,
Jason