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

Support iterating through downstream builds (if present) to compose the message that will be posted to Github #48

Merged
merged 48 commits into from
Sep 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
e7c3540
Add build-flow plugin as dependency
mdelapenya Jun 25, 2014
f629383
Extract buildURL calculation to a method
mdelapenya Jun 25, 2014
0ef710d
If build is from FlowRun type, then iterate through its jobs graph ad…
mdelapenya Jun 25, 2014
983d35f
Make build-flow dependency optional, as suggested
mdelapenya Jul 1, 2014
137b72f
Define an interface to calculate build URL, implementing a default be…
mdelapenya Jul 1, 2014
814c1b7
Implement BuildFlow build url calculation
mdelapenya Jul 1, 2014
b52fd3f
Use a factory to decide which downstream manager to use
mdelapenya Jul 1, 2014
a3f550e
Apply factory to the place where URL is calculated to be sent to github
mdelapenya Jul 1, 2014
7dc1790
Prevent that the plugin is not installed, returning default behaviour…
mdelapenya Jul 1, 2014
287165c
Forgot author
mdelapenya Jul 1, 2014
ae61ba2
Add javadocs
mdelapenya Jul 1, 2014
7e53539
Rename classes with better names
mdelapenya Jul 1, 2014
e37d094
Create a flag on plugin configuration to display -or not- build error…
mdelapenya Jul 30, 2014
57d076f
Rename method to be more generic
mdelapenya Jul 30, 2014
c839f2e
Only append message if the build result is success OR display build e…
mdelapenya Jul 30, 2014
78389c0
Generate the customized message only for two conditions: the build re…
mdelapenya Jul 30, 2014
f55314a
Rename interface and base class, as they will be managing downstream …
mdelapenya Aug 1, 2014
5671407
Support retrieving the downstream builds as an iterator, so it could …
mdelapenya Aug 1, 2014
d36dfc0
Support retrieving testName&since attributes from downstream tests re…
mdelapenya Aug 1, 2014
72c7b1d
Add stacktrace to the output message
mdelapenya Aug 20, 2014
5034180
Print stacktrace inside code block
mdelapenya Aug 20, 2014
1ec50a9
Return a set with uniques nodes, as JobEdge iterator retrieves all no…
mdelapenya Aug 20, 2014
6b6f5cf
Update tests
mdelapenya Aug 20, 2014
f3047c5
Forgot to add message if conditions are not satisfied
mdelapenya Aug 20, 2014
1c67640
This logic is better to determine which message to append
mdelapenya Aug 20, 2014
02053c6
Print stack traces only when configured
mdelapenya Aug 20, 2014
8578bb6
Print the total number of failures
alee8888 Aug 21, 2014
e95be40
Display failed test count in the H2, using github's css class for fai…
mdelapenya Aug 22, 2014
e09658c
Prepend build url to failed test url
mdelapenya Aug 22, 2014
4a26cd5
Always append downstream build, and only tests results when build res…
mdelapenya Aug 27, 2014
e15ba2e
More readable condition
Aug 28, 2014
66bfed9
Rename the method to retrieve the downstream projects
Aug 28, 2014
9c8aa48
Use a logger instead of printing the stacktrace
Aug 28, 2014
2cc9ba3
Simpler way to retrieve the vertex of the graph flow
Aug 28, 2014
39aa6f7
Proper package naming
Aug 28, 2014
ac0c063
Do not use deprecated code (http://javadoc.jenkins-ci.org/hudson/mode…
mdelapenya Sep 4, 2014
d946efa
Use the same URL for failed tests as jUnit plugin
mdelapenya Sep 4, 2014
3615f61
Add fail fast conditions
mdelapenya Sep 4, 2014
39dc2e8
Use an anchor to display downstream build url
mdelapenya Sep 5, 2014
45e3674
Tests: Support creating BuildFlow projects using a TestRule
mdelapenya Sep 8, 2014
7b2aa1b
Tests: add tests to verify that GhprbBuildManager returns the proper …
mdelapenya Sep 8, 2014
e862423
Fix potential NPE discovered by test
mdelapenya Sep 8, 2014
8373368
Move utility methods to a utility class, to reuse methods across tests
mdelapenya Sep 8, 2014
f0fbaac
Define a base test class so that we could reuse methods on different …
mdelapenya Sep 8, 2014
37768b0
Add tests for url calculation using default implementation
mdelapenya Sep 8, 2014
ef22983
Add tests for BuildFlow job configuration
mdelapenya Sep 9, 2014
3ba378d
Add test for BuildFlow manager
mdelapenya Sep 9, 2014
244b60b
Improve fail fast conditions, appending last 25 build log lines
mdelapenya Sep 12, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.cloudbees.plugins</groupId>
<artifactId>build-flow-plugin</artifactId>
<version>0.12</version>
<optional>true</optional>
</dependency>
</dependencies>

<build>
Expand Down
29 changes: 28 additions & 1 deletion src/main/java/org/jenkinsci/plugins/ghprb/GhprbBuilds.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
import hudson.plugins.git.util.BuildData;

import org.apache.commons.io.FileUtils;

import org.jenkinsci.plugins.ghprb.manager.GhprbBuildManager;
import org.jenkinsci.plugins.ghprb.manager.configuration.JobConfiguration;
import org.jenkinsci.plugins.ghprb.manager.factory.GhprbBuildManagerFactoryUtil;

import org.kohsuke.github.GHCommitState;
import org.kohsuke.github.GHIssueState;
import org.kohsuke.github.GHPullRequest;
Expand Down Expand Up @@ -138,8 +143,9 @@ public void onCompleted(AbstractBuild<?,?> build, PrintStream logger) {
} else {
msg.append(GhprbTrigger.getDscp().getMsgFailure(build));
}

msg.append("\nRefer to this link for build results (access rights to CI server needed): \n");
msg.append(publishedURL).append(build.getUrl());
msg.append(generateCustomizedMessage(build));

int numLines = GhprbTrigger.getDscp().getlogExcerptLines();
if (state != GHCommitState.SUCCESS && numLines > 0) {
Expand Down Expand Up @@ -177,4 +183,25 @@ public void onCompleted(AbstractBuild<?,?> build, PrintStream logger) {
}
}
}

private String generateCustomizedMessage(AbstractBuild build) {
JobConfiguration jobConfiguration =
JobConfiguration.builder()
.printStackTrace(trigger.isDisplayBuildErrorsOnDownstreamBuilds())
.build();

GhprbBuildManager buildManager =
GhprbBuildManagerFactoryUtil.getBuildManager(build, jobConfiguration);

StringBuilder sb = new StringBuilder();

sb.append(buildManager.calculateBuildUrl());

if (build.getResult() != Result.SUCCESS) {
sb.append(
buildManager.getTestResults());
}

return sb.toString();
}
}
20 changes: 18 additions & 2 deletions src/main/java/org/jenkinsci/plugins/ghprb/GhprbTrigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class GhprbTrigger extends Trigger<AbstractProject<?, ?>> {
private final String commentFilePath;
private String whitelist;
private Boolean autoCloseFailedPullRequests;
private Boolean displayBuildErrorsOnDownstreamBuilds;
private List<GhprbBranch> whiteListTargetBranches;
private transient Ghprb helper;
private String project;
Expand All @@ -68,6 +69,7 @@ public GhprbTrigger(String adminlist,
Boolean useGitHubHooks,
Boolean permitAll,
Boolean autoCloseFailedPullRequests,
Boolean displayBuildErrorsOnDownstreamBuilds,
String commentFilePath,
List<GhprbBranch> whiteListTargetBranches,
Boolean allowMembersOfWhitelistedOrgsAsAdmin) throws ANTLRException {
Expand All @@ -81,6 +83,7 @@ public GhprbTrigger(String adminlist,
this.useGitHubHooks = useGitHubHooks;
this.permitAll = permitAll;
this.autoCloseFailedPullRequests = autoCloseFailedPullRequests;
this.displayBuildErrorsOnDownstreamBuilds = displayBuildErrorsOnDownstreamBuilds;
this.whiteListTargetBranches = whiteListTargetBranches;
this.commentFilePath = commentFilePath;
this.allowMembersOfWhitelistedOrgsAsAdmin = allowMembersOfWhitelistedOrgsAsAdmin;
Expand Down Expand Up @@ -287,9 +290,16 @@ public Boolean isAutoCloseFailedPullRequests() {
if (autoCloseFailedPullRequests == null) {
Boolean autoClose = getDescriptor().getAutoCloseFailedPullRequests();
return (autoClose != null && autoClose);
} else {
return autoCloseFailedPullRequests;
}
return autoCloseFailedPullRequests;
}

public Boolean isDisplayBuildErrorsOnDownstreamBuilds() {
if (displayBuildErrorsOnDownstreamBuilds == null) {
Boolean displayErrors = getDescriptor().getDisplayBuildErrorsOnDownstreamBuilds();
return (displayErrors != null && displayErrors);
}
return displayBuildErrorsOnDownstreamBuilds;
}

public List<GhprbBranch> getWhiteListTargetBranches() {
Expand Down Expand Up @@ -351,6 +361,7 @@ public static final class DescriptorImpl extends TriggerDescriptor {
private String msgFailure = "Test FAILed.";
private List<GhprbBranch> whiteListTargetBranches;
private Boolean autoCloseFailedPullRequests = false;
private Boolean displayBuildErrorsOnDownstreamBuilds = false;



Expand Down Expand Up @@ -399,6 +410,7 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc
logExcerptLines = formData.getInt("logExcerptLines");
unstableAs = formData.getString("unstableAs");
autoCloseFailedPullRequests = formData.getBoolean("autoCloseFailedPullRequests");
displayBuildErrorsOnDownstreamBuilds = formData.getBoolean("displayBuildErrorsOnDownstreamBuilds");
msgSuccess = formData.getString("msgSuccess");
msgFailure = formData.getString("msgFailure");

Expand Down Expand Up @@ -481,6 +493,10 @@ public Boolean getAutoCloseFailedPullRequests() {
return autoCloseFailedPullRequests;
}

public Boolean getDisplayBuildErrorsOnDownstreamBuilds() {
return displayBuildErrorsOnDownstreamBuilds;
}

public String getServerAPIUrl() {
return serverAPIUrl;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.jenkinsci.plugins.ghprb.manager;

import java.util.Iterator;

/**
* @author mdelapenya (Manuel de la Peña)
*/
public interface GhprbBuildManager {

/**
* Calculate the build URL of a build
*
* @return the build URL
*/
String calculateBuildUrl();

/**
* Returns downstream builds as an iterator
*
* @return the iterator
*/
Iterator downstreamProjects();

/**
* Print tests result of a build
*
* @return the tests result
*/
String getTestResults();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.jenkinsci.plugins.ghprb.manager.configuration;

/**
* @author Miguel Pastor
*/
public class JobConfiguration {

public static PrintStackTrace builder() {
return new JobConfigurationBuilder();
}

private boolean printStacktrace;

private JobConfiguration() {
}

public boolean printStackTrace() {
return this.printStacktrace;
}

public static interface PrintStackTrace {
Build printStackTrace(boolean print);
}

public static interface Build {
JobConfiguration build();
}


public static final class JobConfigurationBuilder implements Build, PrintStackTrace {

private JobConfiguration jobConfiguration = new JobConfiguration();

public JobConfiguration build() {
return jobConfiguration;
}

public Build printStackTrace(boolean print) {
jobConfiguration.printStacktrace = print;
return this;
}
}

}


Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.jenkinsci.plugins.ghprb.manager.factory;


import com.cloudbees.plugins.flow.FlowRun;

import hudson.model.AbstractBuild;
import org.jenkinsci.plugins.ghprb.manager.configuration.JobConfiguration;
import org.jenkinsci.plugins.ghprb.manager.GhprbBuildManager;
import org.jenkinsci.plugins.ghprb.manager.impl.GhprbDefaultBuildManager;
import org.jenkinsci.plugins.ghprb.manager.impl.downstreambuilds.BuildFlowBuildManager;

/**
* @author mdelapenya (Manuel de la Peña)
*/
public class GhprbBuildManagerFactoryUtil {

/**
* Gets an instance of a library that is able to calculate build urls
* depending of build type.
*
* If the class representing the build type is not present on the classloader
* then default implementation is returned.
*
* @param build
* @return
*/
public static GhprbBuildManager getBuildManager(AbstractBuild build) {
JobConfiguration jobConfiguration =
JobConfiguration.builder()
.printStackTrace(false)
.build();

return getBuildManager(build, jobConfiguration);
}

public static GhprbBuildManager getBuildManager(AbstractBuild build, JobConfiguration jobConfiguration) {
try {
if (build instanceof FlowRun) {
return new BuildFlowBuildManager(build, jobConfiguration);
}
}
catch (NoClassDefFoundError ncdfe) {
}

return new GhprbDefaultBuildManager(build);
}

}
Loading