Hi, I am writing a script runner pre commit hook and need to validate that the file being committed contains certain string. and reject the push if it does not.
I know how to stream a file using ContentService if the file has already been committed into the repository but it doesn’t seem to work with newly added files.
When I add new file to but bucket I don’t see how to read the content of newly added file.
// When iterating through changes as below, I get to the change where new file that needs to be validated got added
def collector = { Iterable<Change> changes -> changes.each { change -> validate(change.path.toString()) } }
pathsMatchExcludingDeletes(“glob:**.txt”, collector)
// and them validate in that file
def validate(path) {
…
contentService.streamFile(repo, contentId, path, supplier) // this will throw “The path xxx does not exist at revision yyy
…
}
If I attempt to read the file using path provided by the change.path it will throw the exception “The path xxx does not exist at revision yyy”
I assume this is because file is only getting added and does not yet exist in the repository at the time pre hook runs.
How can I read content of the change for the newly added files?