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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Powering DevOps with Bitbucket Server & Data Center

Hi everyone, The Cloud team recently announced 12 new DevOps features that help developers ship better code, faster   ! While we’re all excited about the new improvements to Bitbucket ...

2,124 views 0 7
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