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

How to get a list of all commits from a push on a pre-receive hook using Bitbucket SPI API?

Tomasz_Kmiecik January 23, 2020

Hello,

We have an idea of creating a pre-receive hook handler using ScritpRunner, which would only allow a push (containing some specific entries in any commit), if there is a special entry in one of the commit messages within this push request.

With PreRepositoryHookCommitCallback I can read the changes content and a commit message, but only from within the current commit. Is there a way to access other commits from a specific push?

 

Here is a pseudocode of what we try to accomplish:

commitCallback =
new PreRepositoryHookCommitCallback() {

@Override
boolean onCommitAdded(@Nonnull CommitAddedDetails commitDetails) {

if (commit.refChanges.any( contains a string matching a pattern) && !allPushCommits.any( has a message containing a special entry) ){
resultBuilder.veto("not allowed")
return false
}
}

1 answer

1 accepted

0 votes
Answer accepted
Robert Giddings [Adaptavist]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 24, 2020

Hi @Tomasz_Kmiecik ,

As a first suggestion I would try storing the commits (or just the commit messages, if that is what you are interested in) inside a global list.

Then call the onEnd() method to process the list.

For details see the JavaDoc for PreRepositoryHookCommitCallback here: https://docs.atlassian.com/bitbucket-server/javadoc/6.6.1/spi/reference/com/atlassian/bitbucket/hook/repository/PreRepositoryHookCommitCallback.html

And it's parent class here: https://docs.atlassian.com/bitbucket-server/javadoc/6.6.3/spi/reference/com/atlassian/bitbucket/hook/repository/RepositoryHookCommitCallback.html

Please let me know if this helps?

Regards,

Robert Giddings,

Product Manager, Adaptavist

Tomasz_Kmiecik February 4, 2020

Hi @Robert Giddings [Adaptavist] 
Thanks a lot for this suggestion. onEnd() method did the trick.

Kind regards,
Tomasz Kmiecik

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events