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

Next challenges

Recent achievements

Recognition

  • Give kudos
  • My kudos

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

Bitbucket - pre-receive hook - How to get changes in the file between the commits (delta changes)

Hi, I am writing bitbucket server side pre-receive hook. I need to verify certain @Annotation element is present in the java file.I am successful in getting the file contents.But, it is always returning the complete file content.I am interested in the delta changes, meaning the changes between the previous commit to current commit (similar to git diff).Not sure, how to get that using the SDK api's.

@Override
public boolean onReceive(RepositoryHookContext context, Collection<RefChange> refChanges, HookResponse hookResponse)
{
Repository repository = context.getRepository();

final Map<String, ByteArrayOutputStream> filesStreamsToHash = new HashMap();

final Map<String, String> fileContents = new HashMap();

boolean isValidCheckIn = true;

refChanges.stream().forEach(refChange -> {

final ChangesRequest changesreq = new ChangesRequest.Builder(repository, refChange.getToHash()).sinceId(refChange.getFromHash()).build();

commitService.streamChanges(changesreq, change -> {

String fileName = change.getPath().toString();

//get the changes for model classes only
if (fileName.startsWith(ModelPath)) {
//want to have changes between changesreq.getUntilId() and changesreq.getSinceId() ONLY
contentService.streamFile(repository, changesreq.getUntilId(), fileName, arg0 -> {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
filesStreamsToHash.put(fileName, baos);
return baos;
});


}

return true;
});
});

 

Any idea would be appreciated.

 

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 ...

1,914 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