mohamicorp / stash-jenkins-postreceive-webhook

Webhook used to notify Jenkins when commits are made to Stash
Other
138 stars 98 forks source link

Fix pull request triggers from forks #172

Closed ch3lo closed 7 years ago

ch3lo commented 8 years ago

This PR fix the problem when the PR hook is triggered from forks. https://github.com/Nerdwin15/stash-jenkins-postreceive-webhook/issues/96

Today when the PR Trigger Button is clicked or a hook is dispatched in background (new PR, Reopen, change....), the plugin notifies Jenkins with the from sha1 and the from branch, but the last is useless if you are trying to reintegrate a PR or test your integration, because set a *, **, wherever.. in Branch Specifier field could be ambiguous and not clarify if it is a PR or not.

Additionally I added a new parameter in notification called TARGET_BRANCH, it is useful in merge when destination branch is not master or a default branch. It needs git plugin 2.4+.

This PR notifies always the branch parameter in this format: pr/<pull request id>/from. I used from because, merge ref is async https://github.com/Nerdwin15/stash-jenkins-postreceive-webhook/issues/83#issuecomment-60468105 and if you need to merge your code before test, it could be made easy in Jenkins with:

Additional Behaviours -> Merge Before Build with: Name of repository: origin Branch to merge to: $TARGET_BRANCH

With this PR, your Jenkins Git config should look like: Name: origin Refspec: +refs/pull-requests//from:refs/remotes/origin/pr/ Branch Specifier: origin/pr/*/from

sorry about my english

Signed-off-by: Marcelo Salazar chelosalazar@gmail.com

go2sh commented 8 years ago

I like your pull requests. Can't you add parameters to that url as it is not supported by the git plugin?

ch3lo commented 8 years ago

I don't know if you can add additional parameters previous git 2.4 version, this is the reason why I added a omit parameters.

mattadamson commented 8 years ago

Hi Marcelo, I'm very excited to see this PR. Does this mean you have this working in stash with a single Jenkins job for forked repositories? We typically merge from a fork for each developer and also in a separate feature / bug fix branch back to master or the central release branch.

I commented here

https://github.com/Nerdwin15/stash-jenkins-postreceive-webhook/issues/96

elee commented 7 years ago

This PR is relevant to my interests. Is there any barrier to merging this?

alexBraidwood commented 7 years ago

Pulled this in, I didn't run into any problems while testing on 4.0.1 branch.