Bitbucket Plugin to detect the file changes

We are developing a Atlassian Bitbucket Plugin to detect the list of files changed when user tries to PUSH the changes to server. When user push changes for specific files, we need to reject. We tried a couple of solutions and couldn’t resolve it.

Solution-1:

PreRepositoryHook<RepositoryPushHookRequest>

We implemented the Interface. The plugin gets called upon PUSH, However there are no reference to the files changed.
Solution-2:

PreRepositoryHook<FileEditHookRequest>

This specific plugin did not get called when we committed and pushed changes.

Any idea how to find the list of files changed upon PUSH from a plugin ?

Err, nevermind. This plugin is no longer open source. It used to be Apache 2.0 licensed, but it no longer is. Maybe see if you can find an older version of it!

(Previously I wrote:

Maybe study https://bitbucket.org/atlassian/stash-auto-unapprove-plugin (the most popular free and open source plugin for Bitbucket).

It runs a “git diff” as part of its operation. If you change that diff to include the “–name-only” flag it should list all touched files. Or even better “-w --name-only” (e.g., list all changed files but ignore whitespace changes).
)

1 Like

The hooks preUpdate is called as preUpdate(@Nonnull PreRepositoryHookContext context, @Nonnull RepositoryHookRequest request) and you can register a commitCallback with the context like so:

context.registerCommitCallback(new PreRepositoryHookCommitCallback {
  @Override
  public boolean onCommitAdded(@Nonnull CommitAddedDetails commitDetails) {
    Commit commit = commitDetails.getCommit();
            ...
  }
})

To get the outcome of your commit scan add public RepositoryHookResult getResult() to the PreRepositoryHookCommitCallback implementation.

Let me know how you go.