Skip to content
Permalink
Browse files

[FIXED JENKINS-41814] Expose event origin to listeners

  • Loading branch information...
stephenc committed Feb 7, 2017
1 parent 581546b commit 17175e82977a1bd8eae6191b1715c9f395ddf07f
@@ -16,7 +16,7 @@
<properties>
<jenkins.version>1.642.3</jenkins.version>
<no-test-jar>false</no-test-jar>
<scm-api.version>2.0.1</scm-api.version>
<scm-api.version>2.0.3-SNAPSHOT</scm-api.version>
</properties>

<developers>
@@ -44,11 +44,17 @@
public class MercurialSCMHeadEvent extends SCMHeadEvent<MercurialCommitPayload> {
private final MercurialCommitPayload payload;

@Deprecated
public MercurialSCMHeadEvent(Type type, MercurialCommitPayload payload) {
super(type, payload);
this.payload = payload;
}

public MercurialSCMHeadEvent(Type type, MercurialCommitPayload payload, String origin) {
super(type, payload, origin);
this.payload = payload;
}

@Override
public boolean isMatch(@NonNull SCMNavigator navigator) {
return false; // because we do not have a Mercurial SCM Navigator
@@ -17,6 +17,7 @@
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.HttpResponses;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

@@ -132,24 +133,26 @@ static boolean looselyMatches(URI notifyUri, String repository) {
public HttpResponse doNotifyCommit(@QueryParameter(required=true) final String url,
@QueryParameter String branch,
@QueryParameter String changesetId) throws ServletException, IOException {
String origin = SCMEvent.originOf(Stapler.getCurrentRequest());
// run in high privilege to see all the projects anonymous users don't see.
// this is safe because we only initiate polling.
SecurityContext securityContext = ACL.impersonate(ACL.SYSTEM);
try {
if (StringUtils.isNotBlank(branch) && StringUtils.isNotBlank(changesetId)) {
SCMHeadEvent.fireNow(new MercurialSCMHeadEvent(
SCMEvent.Type.UPDATED, new MercurialCommitPayload(new URI(url), branch, changesetId)));
SCMEvent.Type.UPDATED, new MercurialCommitPayload(new URI(url), branch, changesetId),
origin));
return HttpResponses.ok();
}
return handleNotifyCommit(new URI(url));
return handleNotifyCommit(origin, new URI(url));
} catch ( URISyntaxException ex ) {
throw HttpResponses.error(SC_BAD_REQUEST, ex);
} finally {
SecurityContextHolder.setContext(securityContext);
}
}

private HttpResponse handleNotifyCommit(URI url) throws ServletException, IOException {
private HttpResponse handleNotifyCommit(String origin, URI url) throws ServletException, IOException {
final List<Item> projects = Lists.newArrayList();
boolean scmFound = false,
urlFound = false;
@@ -187,7 +190,9 @@ private HttpResponse handleNotifyCommit(URI url) throws ServletException, IOExce
continue;
}

LOGGER.log(Level.INFO, "Triggering polling of {0}", project.getFullName());
LOGGER.log(Level.INFO, "Triggering polling of {0} after event from {1}", new Object[]{
project.getFullName(), origin
});
trigger.run();
projects.add(project);
break SCMS;
@@ -210,7 +215,9 @@ private HttpResponse handleNotifyCommit(URI url) throws ServletException, IOExce
continue;
}
urlFound = true;
LOGGER.log(Level.INFO, "Scheduling {0} for refresh", project.getFullName());
LOGGER.log(Level.INFO, "Scheduling {0} for refresh after event from {1}", new Object[]{
project.getFullName(), origin
});
project.onSCMSourceUpdated(source);
projects.add(project);
}

0 comments on commit 17175e8

Please sign in to comment.
You can’t perform that action at this time.