Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to perform static code analysis of the lines that have been either been added or modified?

Lukasz Ladynski February 15, 2020

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:

  • CommitService.streamFile to get the contents of a single file
  • CommitService.streamDiff to get the diff between two commits
  • CommitService.streamChanges to a the changes (paths + type of change) between two commits

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?

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events