Create
cancel
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

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
Posted in Bitbucket

How do you use the Bitbucket-Jira integration? How does it help your team?

Hey everyone, over the past year, we've added several new features on how you can use Bitbucket and Jira together. We'd love to know how you'll are using the integration and how it's helping your t...

86 views 0 2
Join discussion

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