Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pull request triggers from forks #172

Merged
merged 2 commits into from
Sep 1, 2017
Merged

Conversation

ch3lo
Copy link
Contributor

@ch3lo ch3lo commented Jun 23, 2016

This PR fix the problem when the PR hook is triggered from forks. #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 #83 (comment) 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

ch3lo added 2 commits June 23, 2016 02:50
Signed-off-by: Marcelo Salazar <chelosalazar@gmail.com>
…omes from forks

and should be merged in a not default branch.
@go2sh
Copy link

go2sh commented Jun 29, 2016

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

@ch3lo
Copy link
Contributor Author

ch3lo commented Jun 29, 2016

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
Copy link

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

#96

@elee
Copy link

elee commented Apr 16, 2017

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

Copy link
Contributor

@alexBraidwood alexBraidwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, I just have a concern where we're changing the refspec and branch specifier schemes.

* @return The notification result.
*/
public @Nullable NotificationResult notify(@Nonnull Repository repo, //CHECKSTYLE:annot
String jenkinsBase, boolean ignoreCerts, String cloneType, String cloneUrl,
String strRef, String strSha1, boolean omitHashCode, boolean omitBranchName) {
String strRef, String strSha1, String targetBranch, boolean omitHashCode,
boolean omitBranchName, boolean omitTargetBranch) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel the omit bools aren't clear enough. I think we should prefer names like shouldOmitTargetBranch. To me, it makes statements like if (!shouldOmitTargetBranch) more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I wrote in that manner to maintain consistency with the others vars.

@@ -62,16 +62,16 @@ protected void handleEvent(PullRequestEvent event) {
return;
}

String strRef = event.getPullRequest().getFromRef().toString()
.replaceFirst(".*refs/heads/", "");
String strRef = "pr/" + Long.toString(event.getPullRequest().getId()) + "/from";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the implications of this change? It looks we're changing the whole PR scheme here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember well, i'ts necessary, because a PR can come from a fork.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I'm going to test this out and look into getting it in.

@alexBraidwood alexBraidwood merged commit f2d6e8f into mohamicorp:master Sep 1, 2017
@alexBraidwood
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants