-
Notifications
You must be signed in to change notification settings - Fork 84
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
[WIP] workflow support? #26
Changes from all commits
638a5c5
179e8c3
086539a
60d2207
d5788ee
a6ac409
6ec1014
0b6019e
f73276c
8a4869b
f828bf9
aac911c
b529611
bb0e426
27fa64a
7be3c88
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 |
---|---|---|
|
@@ -5,17 +5,22 @@ | |
import hudson.model.AbstractBuild; | ||
import hudson.model.AbstractDescribableImpl; | ||
import hudson.model.Descriptor; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import jenkins.model.Jenkins; | ||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.annotation.CheckForNull; | ||
import java.io.IOException; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Represents a comment for GitHub that can contain token macros. | ||
|
@@ -33,48 +38,61 @@ public GitHubPRMessage(String content) { | |
this.content = content; | ||
} | ||
|
||
public String expandAll(AbstractBuild<?, ?> build, TaskListener listener) { | ||
String content = getContent(); | ||
/** | ||
* Expand all what we can from given run | ||
*/ | ||
@Restricted(NoExternalUse.class) | ||
@CheckForNull | ||
public String expandAll(Run<?, ?> run, TaskListener listener) throws IOException, InterruptedException { | ||
return expandAll(getContent(), run, listener); | ||
} | ||
|
||
/** | ||
* Expand all what we can from given run | ||
*/ | ||
@Restricted(NoExternalUse.class) | ||
@CheckForNull | ||
public static String expandAll(String content, Run<?, ?> run, TaskListener listener) | ||
throws IOException, InterruptedException { | ||
if (content == null || content.length() == 0) { | ||
return content; // Do nothing for an empty String | ||
} | ||
// // Expand environment variables | ||
// String s = build.getEnvironment(listener).expand(content); | ||
// Expand build variables | ||
content = Util.replaceMacro(content, build.getBuildVariableResolver()); | ||
|
||
Jenkins jenkins = Jenkins.getInstance(); | ||
try { | ||
ClassLoader uberClassLoader = Jenkins.getInstance().pluginManager.uberClassLoader; | ||
// Expand environment variables | ||
String body = run.getEnvironment(listener).expand(content); | ||
|
||
if (jenkins.getPlugin("token-macro") != null) { | ||
List macros = null; | ||
// Expand build variables + token macro if they available | ||
if (run instanceof AbstractBuild<?, ?>) { | ||
final AbstractBuild<?, ?> build = (AbstractBuild<?, ?>) run; | ||
body = Util.replaceMacro(body, build.getBuildVariableResolver()); | ||
|
||
//get private macroses like groovy template ${SCRIPT} if available | ||
if (jenkins.getPlugin("email-ext") != null) { | ||
Class<?> contentBuilderClazz = uberClassLoader.loadClass("hudson.plugins.emailext.plugins.ContentBuilder"); | ||
Method getPrivateMacrosMethod = contentBuilderClazz.getDeclaredMethod("getPrivateMacros"); | ||
macros = new ArrayList((Collection) getPrivateMacrosMethod.invoke(null)); | ||
} | ||
try { | ||
Jenkins jenkins = Jenkins.getActiveInstance(); | ||
ClassLoader uberClassLoader = jenkins.pluginManager.uberClassLoader; | ||
List macros = null; | ||
if (jenkins.getPlugin("token-macro") != null) { | ||
// get private macroses like groovy template ${SCRIPT} if available | ||
if (jenkins.getPlugin("email-ext") != null) { | ||
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. 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. When private macros will be in token macro nested if will disappear, but now it right logic. 3 is too small |
||
Class<?> contentBuilderClazz = uberClassLoader.loadClass("hudson.plugins.emailext.plugins.ContentBuilder"); | ||
Method getPrivateMacrosMethod = contentBuilderClazz.getDeclaredMethod("getPrivateMacros"); | ||
macros = new ArrayList((Collection) getPrivateMacrosMethod.invoke(null)); | ||
} | ||
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. I understand the reason of such magic, but it causes much risks when the plugins get updated. 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. that existed code, just moved to if |
||
|
||
//calls TokenMacro.expand(build, listener, content, false, macros) | ||
Class<?> tokenMacroClazz = uberClassLoader.loadClass("org.jenkinsci.plugins.tokenmacro.TokenMacro"); | ||
Method tokenMacroExpand = tokenMacroClazz.getDeclaredMethod("expand", AbstractBuild.class, | ||
TaskListener.class, String.class, boolean.class, List.class); | ||
// call TokenMacro.expand(build, listener, content, false, macros) | ||
Class<?> tokenMacroClazz = uberClassLoader.loadClass("org.jenkinsci.plugins.tokenmacro.TokenMacro"); | ||
Method tokenMacroExpand = tokenMacroClazz.getDeclaredMethod("expand", AbstractBuild.class, | ||
TaskListener.class, String.class, boolean.class, List.class); | ||
|
||
content = (String) tokenMacroExpand.invoke(null, build, listener, content, false, macros); | ||
body = (String) tokenMacroExpand.invoke(null, build, listener, body, false, macros); | ||
} | ||
} catch (ClassNotFoundException e) { | ||
LOGGER.error("Can't find class", e); | ||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { | ||
LOGGER.error("Can't evaluate macro", e); | ||
} | ||
} catch (ClassNotFoundException e) { | ||
LOGGER.error("Can't find class", e); | ||
} catch (NoSuchMethodException e) { | ||
LOGGER.error("Can't evaluate macro", e); | ||
} catch (InvocationTargetException e) { | ||
LOGGER.error("Can't evaluate macro", e); | ||
} catch (IllegalAccessException e) { | ||
LOGGER.error("Can't evaluate macro", e); | ||
} | ||
|
||
return content; | ||
return body; | ||
} | ||
|
||
public String getContent() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,8 @@ | |
|
||
import hudson.Util; | ||
import hudson.console.AnnotatedLargeText; | ||
import hudson.model.AbstractProject; | ||
import hudson.model.Action; | ||
import hudson.model.Job; | ||
import org.apache.commons.jelly.XMLOutput; | ||
|
||
import java.io.File; | ||
|
@@ -16,13 +16,13 @@ | |
* @author Alina Karpovich | ||
*/ | ||
public class GitHubPRPollingLogAction implements Action { | ||
private transient AbstractProject<?, ?> project; | ||
private transient Job<?, ?> project; | ||
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 even item... I can imagine a use-case for Folders integration 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 idea, not sure only how test it on real example 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. Augh - the number of weird things that could fall under |
||
|
||
public GitHubPRPollingLogAction(AbstractProject<?, ?> project) { | ||
public GitHubPRPollingLogAction(Job<?, ?> project) { | ||
this.project = project; | ||
} | ||
|
||
public AbstractProject<?,?> getOwner() { | ||
public Job<?,?> getOwner() { | ||
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. breaks binary compatibility. You need to bump the major version or to introduce bridge methods 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. That's alpha plugin!!! 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, break away, I say. |
||
return project; | ||
} | ||
|
||
|
@@ -50,8 +50,7 @@ public String getLog() throws IOException { | |
* @since 1.350 | ||
*/ | ||
public void writeLogTo(XMLOutput out) throws IOException { | ||
new AnnotatedLargeText<>(getLogFile(), | ||
Charset.defaultCharset(),true,this).writeHtmlTo(0,out.asWriter()); | ||
new AnnotatedLargeText<>(getLogFile(), Charset.defaultCharset(),true,this).writeHtmlTo(0,out.asWriter()); | ||
} | ||
|
||
public File getLogFile() { | ||
|
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.
😠 @lanwen tune to 4 nested at least?