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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

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

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

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

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
Community showcase
Published in Bitbucket

Powering DevOps with Bitbucket Server & Data Center

Hi everyone, The Cloud team recently announced 12 new DevOps features that help developers ship better code, faster   ! While we’re all excited about the new improvements to Bitbucket ...

1,922 views 0 7
Read article

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