Find files from push to BitBucket server

Hi,

I’m trying to create a plugin that will block a push being made to the BitBucket server if certain files are part of the commit being pushed. In the past I’ve created plugins that reject pushes if a certain criteria is not being met however I’m having trouble finding the correct method/package that allows the plugin to see which files are being pushed. Is there a method/package available for this? Is it even feasible?

I’ve tried using the PreRepositoryHookCommitCallback to see if it will return any info on the files but no luck so far.

Any information or help would be great!

Hi @ejobbers,

I think that using PreRepositoryHookCommitCallback is a good start. The onCommitAdded method will be called with each commit. From there you can call out to the ScmService or the CommitService depending on what details you need. It sounds like you only need the file names, in which case I would call out to the CommitService.getChanges method and page through the changes. Each Change object you will get back has a getPath method which you can use to get the file name.

Hope that helps. Good luck!
Kristy

2 Likes

Thank you @khughes! This was exactly what I was looking for!