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

[FIXED JENKINS-46082] API will include culprits again. #2978

Merged
merged 1 commit into from
Aug 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 core/src/main/java/hudson/model/AbstractBuild.java
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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