Skip to content

Commit

Permalink
[FIXED JENKINS-46082] API will include culprits again.
Browse files Browse the repository at this point in the history
  • Loading branch information
abayer committed Aug 11, 2017
1 parent b8f6246 commit a975f72
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
6 changes: 6 additions & 0 deletions core/src/main/java/hudson/model/AbstractBuild.java
Expand Up @@ -324,6 +324,12 @@ public FilePath[] getModuleRoots() {
return culprits;
}

@Override
@Exported
@Nonnull public Set<User> getCulprits() {
return RunWithSCM.super.getCulprits();
}

@Override
public boolean shouldCalculateCulprits() {
return getCulpritIds() == null;
Expand Down
25 changes: 24 additions & 1 deletion test/src/test/java/hudson/model/AbstractBuildTest.java
Expand Up @@ -24,6 +24,7 @@
package hudson.model;

import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebResponse;
import hudson.EnvVars;
import hudson.Launcher;
import hudson.model.queue.QueueTaskFuture;
Expand All @@ -43,6 +44,8 @@
import hudson.tasks.LogRotatorTest;
import hudson.tasks.Recorder;
import hudson.util.OneShotEvent;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.CaptureEnvironmentBuilder;
Expand All @@ -53,6 +56,7 @@
import org.jvnet.hudson.test.TestBuilder;
import org.jvnet.hudson.test.TestExtension;
import org.jvnet.hudson.test.UnstableBuilder;
import org.xml.sax.SAXException;

/**
* Unit tests of {@link AbstractBuild}.
Expand Down Expand Up @@ -125,12 +129,31 @@ public void rawConsoleOutput() throws Exception {
assertThat(rsp.getWebResponse().getContentAsString(), containsString(out));
}

private void assertCulprits(AbstractBuild<?,?> b, String... expectedIds) {
private void assertCulprits(AbstractBuild<?,?> b, String... expectedIds) throws IOException, SAXException {
Set<String> actual = new TreeSet<>();
for (User u : b.getCulprits()) {
actual.add(u.getId());
}
assertEquals(actual, new TreeSet<>(Arrays.asList(expectedIds)));

if (expectedIds.length > 0) {
JenkinsRule.WebClient wc = j.createWebClient();
WebResponse response = wc.goTo(b.getUrl() + "api/json?tree=culprits[id]", "application/json").getWebResponse();
JSONObject json = JSONObject.fromObject(response.getContentAsString());

Object culpritsArray = json.get("culprits");
assertNotNull(culpritsArray);
assertTrue(culpritsArray instanceof JSONArray);
Set<String> fromApi = new TreeSet<>();
for (Object o : ((JSONArray)culpritsArray).toArray()) {
assertTrue(o instanceof JSONObject);
Object id = ((JSONObject)o).get("id");
if (id instanceof String) {
fromApi.add((String)id);
}
}
assertEquals(fromApi, new TreeSet<>(Arrays.asList(expectedIds)));
}
}

@Test
Expand Down

0 comments on commit a975f72

Please sign in to comment.