In some previous questions for performing a code analysis there has been a good answer from Atlassian Team posted:
Lots of different scenarios to consider! Also, when a file is changed in a commit, are you interested in the whole file or just the change? Depending on what you need to do there are different options:
I'm guessing that you're writing some kind of hook that performs a code style or static analysis check on the code that's being pushed. In that case you'll want to do something like this:
for each RefChange, use CommitService.streamChanges to determine the modified and added paths between RefChange.fromHash and RefChange.toHash (ignore the removed paths).
For each of these paths stream the file (using CommitService.streamFile) and perform the static analysis (or create a temporary directory and stream the file to a file on disk - then perform the static analysis).
From what I understand in the above mentioned solution we always analyse the whole files' content to which some changes have been done.
How can we retrieve just the part of the content (is it somehow by getContentId?) to which in fact a change has been introduced?
Shall this be somehow based on streamDiff method?