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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.