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

Adding additional data to Stash Asynchronous Post-Receive hook

Robert L. March 20, 2013

I'm trying to expand the example Post-Receive hook plugin (https://developer.atlassian.com/stash/docs/latest/how-tos/repo-hook-examples/async-post-receive-config.html) to so the call to remote URL can also post the Repository and Branch information. I'm new to Pluging development and would appreciate any suggestions and examples on how this could be acheived.

Thank you

3 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Robert L. March 26, 2013

Charles,

I'll not be able to test the updated plugin until next week, but looking at the code it should be very close. I really apprecaite all support and will get back to you if any more questions.

Regards,

Robert

0 votes
cofarrell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 25, 2013

Hi Robert,

Well that makes it a little easier. Try this.

https://bitbucket.org/cofarrell/stash-webhook-plugin/commits/branch/question-150195

Note that there are a few TODOs, some of which there is nothing we can do in Stash at the moment, some of them I've left out for performance and some because it's late...

I hope this helps.

Charles

0 votes
cofarrell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 20, 2013

Hi Robert,

This is an example I put together for Stash before repository hooks for posting changeset information to Jenkins:

https://bitbucket.org/atlassian/stash-webhook-plugin/src/4d05d91913225c050fe0acd07b0a842d22e28713/src/main/java/com/atlassian/stash/plugin/webook/WebHook.java?at=master

Instead of listening to the PushEvent you could implement postReceive() and use the Repository/RefChanges in the same way. The URL could/would be loaded from settings as well.

I hope this helps a little.

Charles

Robert L. March 20, 2013

Attached is the code (code.txt)

cofarrell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 20, 2013

Ahh. I can see it now. I'm not sure how that would compile. You're passing RepositoryHookContent into Iterables.filter. You want to pass refChanges, which is a list of the pushed branches (and their changeset ranges).

Robert L. March 20, 2013

Charles,

Thank you for the suggestion. Using your example I was able to post the Repo URL, but I still can not figure out how to get the current branch the request is for (getUpdateBranches function).

Attached is the code

Robert

cofarrell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 20, 2013

Hi Robert,

I'm afraid I couldn't see the attached code. That said the branch you want is on the RefChange object under getRefId()?

Cheers,

Charles

Robert L. March 21, 2013

Charles,

Thank you for all great help. I was able to get code working, and post the the Repo URL and branch name.

I was wondering if you could provide some guidance on following few questions.

1. My objective is to generate a post-recieive call based on update to specic branch and the post URL should include only name of that one updated branch. I believe the getUpdateBranches function will pottentialy return mutliple branch names.

2. Is there a way to get only the Repo name rather than full repo URL. Would you have a code example or suggest the appropriage API call.

3. Is there a way to get Project Name only?

4. How could I convert output so instead the URL variables the json object is passed.

5. The example plugin you recommended before includes LoggerFactory. I'm trying to undestand where the logs are storred.

Again thank you for all support. I attached the current version of the plugin for the reference.

cofarrell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 22, 2013

Hi Robert,

I've put some quick changes to your attached file to hopefully answer some of your questions:

https://bitbucket.org/cofarrell/stash-webhook-plugin/commits/branch/question-150195

1. Would looping over all the branches do? Or do you know specifically which branch you're interested in? Or you don't care about branches you just want to notify the URL regardless? In my example I'm just looping over each branch.

2 & 3. See example

4. How do you mean? Do you want to POST a JSON request to some endpoint? Or do you want to include a JSON parameter as a GET parameter? I'm assuming it's the former? Either way see how I'm creating JSON in my example.

5. The logs go to $STASH_HOME/log/atlassian-stash.log. By default we only log INFO and up, although you can modify the logging levels at runtime (we just use logback).

https://confluence.atlassian.com/display/STASH/Stash+home+directory

https://confluence.atlassian.com/display/STASH012/Enabling+Stash+debug+logging

Cheers,

Charles

Robert L. March 24, 2013

Hi Charles,

Thank you for the updated code. However, based on my testing, the repoName returns the branch name and projectKey returns the Repo name.

Let me explain my end goal. I'm trying to achaive similar functionality as the WebHook in Github. Github posts to the remote URL the json object that includes all the info about the push, including the project name, repo name, repo URL, branch name, user who pushed the code, comments text, commit ID and few other. The plugin as it is works, but is missing few details (project name, user who pushed the code, commit ID and comments filed). Would you be able to point out the correct API calls to retrieve missing values?

Attached is an example payload. I'm trying to get the STASH post-receive plugin to create the similar object that will include the all relevant info. (payload.log)

Thank you,

Robert

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events