Hook/Add-On to execute custom actions on a merge on a pull-request

We have a use case where we would like to execute some custom actions when the "Merge" button is pushed in the Stash user interface. The end-goal is to update a version number that we can use in our gradle build scripts to be stamped in any builds done in our code.

Outside of Stash, we currently achieve this with pre-commit hooks, that modify our version number in a properties file. We have also tested and are considering using git tags instead. However, now that we've moved to stash. The "Merge" is handled outside of our local repos and thus our git hooks do not run. So I'm looking for some guidance. In Stash,

  1. Is there a way (either via a hook) to tag a specific commit at merge time? I didn't find anything conclusive that suggested this was possible.
  2. It seems it should be possible to write a hook that will modify a properties file, and ammend the commit. The thing about this solution that I'm not clear on is how/where the merge itself gets executed... The SDK exposes actions like git add and git commit, but are they run on the origin server itself? or elsewhere?

I hope my questions are clear! Thanks!

6 answers

0 vote
Jason Hinch Atlassian Team Aug 27, 2013

I'm not sure if your requirements for a version number has to be incremental but you may be interested in using git describe --tags --always HEAD instead of updating a file every commit or creating many tags.

We do want our version number to change/increment with every merge to our main branch, but not necessarily every actual commit. We are in fact using the git describe, but it isn't helpful in this case.

We have Major.Minor.Patch-commit

- Major is manually updated

- Minor should be updated once per pull request/merge

- Patch is manually updated

- the commit number is taken from the git describe, so developers who are making multiple commits can track builds they make manually.

The minor number is the one we are interested in. I will look at doing some git describe or log magic to see if I can't extrapolate the same information.

We do want our version number to change/increment with every merge to our main branch, but not necessarily every actual commit. We are in fact using the git describe, but it isn't helpful in this case.

We have Major.Minor.Patch-commit

- Major is manually updated

- Minor should be updated once per pull request/merge

- Patch is manually updated

- the commit number is taken from the git describe, so developers who are making multiple commits can track builds they make manually.

The minor number is the one we are interested in. I will look at doing some git describe or log magic to see if I can't extrapolate the same information.

Hi Jeremy,

How did you go with git describe?

I have to second Jason's suggestion. And perhaps to elaborate checking in the version into Git, while convenient for builds, is something that is going to be difficult to implement and is largely redundant given the information Git has. It should be possible to write a very simple plugin or build script that attaches a tag on each pull request merge, which will then assist your git describe (or whatever) to work out the minor version.

Here are some examples of people using git tags in Gradle.

https://github.com/palantir/gradle-gitsemver

http://ryanharter.com/blog/2013/07/30/automatic-versioning-with-git-and-gradle/

Good luck,

Charles

Hello, sorry for the delayed response. We did in the end go with a more automated version calculation using tags and git describe. The suggestion was good, put us on the right path. Our version number is tagged on releases and otherwise fully calculated via git describe.

Hi Jeremy. Glad to hear it. :)

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

1,986 views 1 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you