Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from drekbour/assign-claim
JENKINS-7824 Allow assigning builds/tests to other users
- Loading branch information
Showing
11 changed files
with
286 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/main/java/hudson/plugins/claim/DescribableTestAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package hudson.plugins.claim; | ||
|
||
import hudson.Extension; | ||
import hudson.model.Describable; | ||
import hudson.model.Descriptor; | ||
import hudson.model.Hudson; | ||
import hudson.model.User; | ||
import hudson.tasks.junit.TestAction; | ||
import hudson.util.ListBoxModel; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
public abstract class DescribableTestAction extends TestAction implements Describable<DescribableTestAction> { | ||
|
||
//private static final Logger LOGGER = Logger.getLogger("claim-plugin"); | ||
|
||
public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl(); | ||
|
||
public Descriptor<DescribableTestAction> getDescriptor() { | ||
return DESCRIPTOR; | ||
} | ||
|
||
private static Comparator<User> comparator = new Comparator<User>() { | ||
public int compare(User c1, User c2) { | ||
return c1.getId().compareTo(c2.getId()); | ||
} | ||
}; | ||
|
||
@Extension | ||
public static final class DescriptorImpl extends Descriptor<DescribableTestAction> { | ||
@Override | ||
public String getDisplayName() { return "Assignee"; } | ||
|
||
public ListBoxModel doFillAssigneeItems() { | ||
ListBoxModel items = new ListBoxModel(); | ||
|
||
// sort in case the users are not already in sort order | ||
// with the current user at the top of the list | ||
String currentUserId = Hudson.getAuthentication().getName(); | ||
User currentUser = null; | ||
if (currentUserId != null) { | ||
currentUser = User.get(currentUserId); | ||
} | ||
if (currentUser != null) { | ||
items.add(currentUser.getDisplayName(), currentUser.getId()); | ||
} | ||
|
||
Collection<User> c = User.getAll(); | ||
if (c != null && currentUser != null) { | ||
if (c.contains(currentUser)) { | ||
c.remove(currentUser); | ||
} | ||
} | ||
|
||
if (c!= null ) { | ||
List<User> l = new ArrayList<User>(c); | ||
Collections.sort(l, comparator); | ||
for (User u : l) { | ||
items.add(u.getDisplayName(), u.getId()); | ||
} | ||
} | ||
|
||
return items; | ||
|
||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<div> | ||
Allow users to claim failed builds. | ||
Allow users to claim or be assigned failed builds. | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div> | ||
The user you are assigning the claim to. Blank means yourself. | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div> | ||
指定誰要認這筆帳。都不填代表由您一肩扛起! | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,72 @@ | ||
package hudson.plugins.claim; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
import com.gargoylesoftware.htmlunit.html.HtmlElement; | ||
import com.gargoylesoftware.htmlunit.html.HtmlPage; | ||
import hudson.model.FreeStyleProject; | ||
import hudson.model.ListView; | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.FailureBuilder; | ||
import org.jvnet.hudson.test.HudsonTestCase; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
import com.gargoylesoftware.htmlunit.html.HtmlElement; | ||
import com.gargoylesoftware.htmlunit.html.HtmlPage; | ||
import java.io.IOException; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
public class ClaimReportTest extends HudsonTestCase { | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class ClaimReportTest { | ||
|
||
private static final String JOB_NAME = "job"; | ||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
|
||
private static final String JOB_NAME = "myjob"; | ||
private FreeStyleProject job; | ||
private ListView view; | ||
|
||
@Override | ||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
@Before | ||
public void setUp() throws Exception { | ||
|
||
java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(java.util.logging.Level.SEVERE); | ||
|
||
job = createFailingJobWithName(JOB_NAME); | ||
|
||
view = new ListView("DefaultView"); | ||
j.jenkins.addView(view); | ||
j.jenkins.setPrimaryView(view); | ||
|
||
} | ||
|
||
private FreeStyleProject createFailingJobWithName(String jobName) throws IOException, | ||
InterruptedException, ExecutionException { | ||
FreeStyleProject project = createFreeStyleProject(jobName); | ||
InterruptedException, ExecutionException { | ||
FreeStyleProject project = j.createFreeStyleProject(jobName); | ||
project.getBuildersList().add(new FailureBuilder()); | ||
project.getPublishersList().add(new ClaimPublisher()); | ||
project.scheduleBuild2(0).get(); | ||
return project; | ||
} | ||
|
||
public void testThatJobNotPresentInDefaultViewIsVisibleInClaimReport() throws Exception { | ||
ListView view = new ListView("DefaultView"); | ||
hudson.addView(view); | ||
hudson.setPrimaryView(view); | ||
|
||
WebClient wc = new WebClient(); | ||
|
||
HtmlPage page = wc.goTo("claims/"); | ||
@Test | ||
public void job_is_visible_in_claim_report() throws Exception { | ||
// Given: | ||
view.add(job); | ||
//j.interactiveBreak(); | ||
// When: | ||
HtmlPage page = j.createWebClient().goTo("claims/"); | ||
// Then: | ||
HtmlElement element = page.getElementById("claim.build." + JOB_NAME); | ||
assertTrue(element.isDisplayed()); | ||
assertThat(element.isDisplayed(), is(true)); | ||
} | ||
|
||
public void testJobPresentInDefaultViewIsVisibleInClaimReport() throws Exception { | ||
ListView view = new ListView("DefaultView"); | ||
view.add(job); | ||
hudson.addView(view); | ||
hudson.setPrimaryView(view); | ||
|
||
WebClient wc = new WebClient(); | ||
|
||
HtmlPage page = wc.goTo("claims/"); | ||
@Test | ||
public void job_not_present_in_default_view_is_visible_in_claim_report() throws Exception { | ||
// When: | ||
HtmlPage page = j.createWebClient().goTo("claims/"); | ||
// Then: | ||
HtmlElement element = page.getElementById("claim.build." + JOB_NAME); | ||
assertTrue(element.isDisplayed()); | ||
assertThat(element.isDisplayed(), is(true)); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.