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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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
Community showcase
Published in Bitbucket

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

3,710 views 10 16
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you