-
Notifications
You must be signed in to change notification settings - Fork 720
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
[JENKINS-24141] Switch to using RunWithSCM for getCulprits logic #155
Changes from 5 commits
6cce465
2e38d1d
57a94b4
cd6c1f6
da47c13
1ca8b49
facb011
cd7d569
b5c0d76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,10 @@ | |
|
||
package hudson.plugins.emailext.plugins.recipients; | ||
|
||
import com.google.common.base.Predicates; | ||
import com.google.common.collect.Iterables; | ||
import hudson.EnvVars; | ||
import hudson.Extension; | ||
import hudson.model.AbstractBuild; | ||
import hudson.model.Result; | ||
import hudson.model.Run; | ||
import hudson.model.User; | ||
|
@@ -21,6 +22,8 @@ | |
|
||
import javax.mail.internet.InternetAddress; | ||
import java.io.PrintStream; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
@@ -51,10 +54,18 @@ public void send(final String format, final Object... args) { | |
} | ||
final Debug debug = new Debug(); | ||
Run<?,?> run = context.getRun(); | ||
if (run instanceof AbstractBuild) { | ||
Set<User> users = ((AbstractBuild<?,?>)run).getCulprits(); | ||
RecipientProviderUtilities.addUsers(users, context, env, to, cc, bcc, debug); | ||
} else { | ||
// TODO: core 2.60+, workflow-job 2.12+: Switch to checking if run is RunWithSCM and make catch an else block | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. …or simply delete the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I guess we can probably just rule out any other weirdo job types out there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I like what I've got here. It's a nice better-safe-than-sorry fallback. |
||
try { | ||
Method getCulprits = run.getClass().getMethod("getCulprits"); | ||
if (Set.class.isAssignableFrom(getCulprits.getReturnType())) { | ||
@SuppressWarnings("unchecked") | ||
Set<User> users = (Set<User>) getCulprits.invoke(run); | ||
if (Iterables.all(users, Predicates.instanceOf(User.class))) { | ||
RecipientProviderUtilities.addUsers(users, context, env, to, cc, bcc, debug); | ||
} | ||
} | ||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { | ||
debug.send("Exception getting culprits for %s: %s", run, e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🐜 this is a valid behavior for 2.60-, no? Maybe it needs more graceful message, but up to you There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. |
||
List<Run<?, ?>> builds = new ArrayList<>(); | ||
Run<?, ?> build = run; | ||
builds.add(build); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ | |
import hudson.scm.ChangeLogSet; | ||
import hudson.tasks.MailSender; | ||
|
||
import javax.mail.MethodNotSupportedException; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoops.. |
||
import javax.mail.internet.InternetAddress; | ||
import java.lang.reflect.Field; | ||
import java.lang.reflect.InvocationTargetException; | ||
|
@@ -66,6 +67,7 @@ public static Set<User> getChangeSetAuthors(final Collection<Run<?, ?>> runs, fi | |
final Set<User> users = new HashSet<>(); | ||
for (final Run<?, ?> run : runs) { | ||
debug.send(" build: %d", run.getNumber()); | ||
// TODO: core 2.60+, workflow-job 2.12+: Switch to checking if run is an instance of RunWithSCM and call getChangeSets directly. | ||
if (run instanceof AbstractBuild<?,?>) { | ||
final ChangeLogSet<?> changeLogSet = ((AbstractBuild<?,?>)run).getChangeSet(); | ||
if (changeLogSet == null) { | ||
|
@@ -74,6 +76,7 @@ public static Set<User> getChangeSetAuthors(final Collection<Run<?, ?>> runs, fi | |
addChangeSetUsers(changeLogSet, users, debug); | ||
} | ||
} else { | ||
// TODO: core 2.60+, workflow-job 2.12+: Decide whether to remove this logic since it won't be needed for Pipelines any more. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, in 2.60+ we can just drop the |
||
try { | ||
Method getChangeSets = run.getClass().getMethod("getChangeSets"); | ||
if (List.class.isAssignableFrom(getChangeSets.getReturnType())) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sure that all deps are compatible with Jenkins 2.0after the dep downgrade
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are - none of the core Pipeline plugins have dependencies on core >=2.0 until
workflow-job
2.12.