Skip to content
Permalink
Browse files
JENKINS-7824: Add a record of who assigned the build failure and display
it
  • Loading branch information
ninian committed Aug 24, 2014
1 parent dcefc3d commit 69dd1a8827220bdd2d3456e8744f8ce1e3003d92
Showing 10 changed files with 105 additions and 27 deletions.
@@ -31,6 +31,7 @@

private boolean claimed;
private String claimedBy;
private String assignedBy;
private Date claimDate;
private boolean transientClaim;

@@ -53,7 +54,8 @@ public String getUrlName() {
public void doClaim(StaplerRequest req, StaplerResponse resp)
throws ServletException, IOException {
Authentication authentication = Hudson.getAuthentication();
String name = authentication.getName(); // Default to self-assignment
String currentUser = authentication.getName();
String name = currentUser; // Default to self-assignment
String assignee = req.getSubmittedForm().getString("assignee");
if (!StringUtils.isEmpty(assignee) && !name.equals(assignee)) {
// Validate the specified assignee.
@@ -68,7 +70,7 @@ public void doClaim(StaplerRequest req, StaplerResponse resp)
String reason = req.getSubmittedForm().getString("reason");
boolean sticky = req.getSubmittedForm().getBoolean("sticky");
if (StringUtils.isEmpty(reason)) reason = null;
claim(name, reason, sticky);
claim(name, reason, currentUser, sticky);
owner.save();
resp.forwardToPreviousPage(req);
}
@@ -84,6 +86,11 @@ public void doUnclaim(StaplerRequest req, StaplerResponse resp)
public String getClaimedBy() {
return claimedBy;
}

@Exported
public String getAssignedBy() {
return assignedBy;
}

public String getClaimedByName() {
User user = User.get(claimedBy, false,Collections.EMPTY_MAP);
@@ -93,36 +100,51 @@ public String getClaimedByName() {
return claimedBy;
}
}

public String getAssignedByName() {
User user = User.get(assignedBy, false,Collections.EMPTY_MAP);
if (user != null) {
return user.getDisplayName();
} else {
return assignedBy;
}
}

public void setClaimedBy(String claimedBy) {
this.claimedBy = claimedBy;
}

public void setAssignedBy (String assignedBy) {
this.assignedBy = assignedBy;
}

@Exported
public boolean isClaimed() {
return claimed;
}

public void claim(String claimedBy, String reason, boolean sticky) {
public void claim(String claimedBy, String reason, String assignedBy, boolean sticky) {
this.claimed = true;
this.claimedBy = claimedBy;
this.reason = reason;
this.transientClaim = !sticky;
this.claimDate = new Date();
this.assignedBy = assignedBy;
}

/**
* Claim a new Run with the same settings as this one.
*/
public void copyTo(AbstractClaimBuildAction<T> other) {
other.claim(getClaimedBy(), getReason(), isSticky());
other.claim(getClaimedBy(), getReason(), getAssignedBy(), isSticky());
}

public void unclaim() {
this.claimed = false;
this.claimedBy = null;
this.transientClaim = false;
this.claimDate = null;
this.assignedBy = null;
// we remember the reason to show it if someone reclaims this build.
}

@@ -180,6 +202,22 @@ public Date getClaimDate() {
public boolean hasClaimDate() {
return this.claimDate != null;
}

/**
* was the action claimed by someone to themselves?
* @return true if the item was claimed by the user to themselves, false otherwise
*/
public boolean isSelfAssigned() {
boolean ret = true;
if (! isClaimed()) {
ret = false;
} else if (getClaimedBy() == null) {
ret = false;
} else if (! getClaimedBy().equals(getAssignedBy())) {
ret = false;
}
return ret;
}

public abstract String getNoun();

@@ -16,8 +16,8 @@ public String getDisplayName() {
}

@Override
public void claim(String claimedBy, String reason, boolean sticky) {
super.claim(claimedBy, reason, sticky);
public void claim(String claimedBy, String reason, String assignedBy, boolean sticky) {
super.claim(claimedBy, reason, assignedBy, sticky);
owner.addClaim(testObjectId, this);
}

@@ -46,10 +46,10 @@ public String getClaimantText(Run r) {
String reason = claim.getReason();
if (reason != null) {
return Messages.ClaimedBuildsReport_ClaimantText_claimedWithReason(
claim.getClaimedBy(), claim.getReason());
claim.getClaimedBy(), claim.getReason(), claim.getAssignedBy());
} else {
return Messages.ClaimedBuildsReport_ClaimantText_claimed(claim
.getClaimedBy());
.getClaimedBy(), claim.getAssignedBy());
}
}

@@ -21,8 +21,16 @@
<p>
<j:choose>
<j:when test="${it.hasClaimDate()}">
${%you.claimed.on(it.noun)}
<i:formatDate value="${it.claimDate}" type="both" dateStyle="medium" timeStyle="medium"/>${%.}
<j:choose>
<j:when test="${it.isSelfAssigned()}">
${%you.claimed.on(it.noun)}
<i:formatDate value="${it.claimDate}" type="both" dateStyle="medium" timeStyle="medium"/>${%.}
</j:when>
<j:otherwise>
${%you.assigned.on(it.noun, it.assignedByName)}
<i:formatDate value="${it.claimDate}" type="both" dateStyle="medium" timeStyle="medium"/>${%.}
</j:otherwise>
</j:choose>
</j:when>
<j:otherwise>
${%you.claimed(it.noun)}
@@ -41,8 +49,16 @@
<p>
<j:choose>
<j:when test="${it.hasClaimDate()}">
${%one.claimed.on(it.noun,it.claimedByName)}
<i:formatDate value="${it.claimDate}" type="both" dateStyle="medium" timeStyle="medium"/>${%.}
<j:choose>
<j:when test="${it.isSelfAssigned()}">
${%one.claimed.on(it.noun,it.claimedByName)}
<i:formatDate value="${it.claimDate}" type="both" dateStyle="medium" timeStyle="medium"/>${%.}
</j:when>
<j:otherwise>
${%one.assigned.on(it.noun, it.claimedByName,it.assignedByName)}
<i:formatDate value="${it.claimDate}" type="both" dateStyle="medium" timeStyle="medium"/>${%.}
</j:otherwise>
</j:choose>
</j:when>
<j:otherwise>
${%one.claimed(it.noun,it.claimedByName)}
@@ -69,7 +85,6 @@
<f:entry title="${%Assignee}" field="assignee" help="/plugin/claim/help-assignee.html">
<f:select />
</f:entry>

<f:entry title="${%Reason}" help="/plugin/claim/help-reason.html">
<f:textarea name="reason" value="${it.reason}"/>
</f:entry>
@@ -1,6 +1,7 @@
you.claimed.on=You claimed this {0} on
you.claimed=You claimed this {0}.
you.assigned.on=You were assigned this {0} by {1} on
one.claimed.on=This {0} was claimed by {1} on
one.claimed=This {0} was claimed by {1}.
not.claimed=This {0} was not claimed.

one.assigned.on=This {0} was assigned to {1} by {2} on
@@ -26,15 +26,33 @@ THE SOFTWARE.
<td>
<j:forEach var="action" items="${it.getAction(job)}">
<j:choose>
<j:when test="${action.claim.reason != null}">
<img width="16" height="16"
title="${%climed.reason(action.combinationName,action.claim.claimedBy,action.claim.reason)}"
src="${imagesURL}/16x16/lock.gif"/>
<j:when test="${action.claim.reason != null}">
<j:choose>
<j:when test="${action.claim.claimedBy.equals(action.claim.assignedBy)}">
<img width="16" height="16"
title="${%climed.reason(action.combinationName,action.claim.claimedBy,action.claim.reason)}"
src="${imagesURL}/16x16/lock.gif"/>
</j:when>
<j:otherwise>
<img width="16" height="16"
title="${%assigned.reason(action.claim.claimedBy,action.claim.assignedBy,action.claim.reason)}"
src="${imagesURL}/16x16/lock.gif"/>
</j:otherwise>
</j:choose>
</j:when>
<j:otherwise>
<img width="16" height="16"
title="${%climed(action.combinationName,action.claim.claimedBy)}"
src="${imagesURL}/16x16/lock.gif"/>
<j:choose>
<j:when test="${action.claim.claimedBy.equals(action.claim.assignedBy)}">
<img width="16" height="16"
title="${%climed(action.combinationName,action.claim.claimedBy)}"
src="${imagesURL}/16x16/lock.gif"/>
</j:when>
<j:otherwise>
<img width="16" height="16"
title="${%climed(action.claim.claimedBy,action.claim.assignedBy)}"
src="${imagesURL}/16x16/lock.gif"/>
</j:otherwise>
</j:choose>
</j:otherwise>
</j:choose>
</j:forEach>
@@ -1,2 +1,4 @@
climed.reason={0} Claimed by {1}. Reason: {2}
assigned.reason=Assigned to {0} by {1}. Reason: {2}
climed={0} Claimed by {1}.
assigned=Assigned to {0} by {1}
@@ -6,8 +6,8 @@ ClaimColumn.DisplayName=Claim

ClaimedBuildsReport.DisplayName=Claim Report
ClaimedBuildsReport.ClaimantText.unclimed=unclaimed
ClaimedBuildsReport.ClaimantText.claimedWithReason=claimed by {0} because: {1}
ClaimedBuildsReport.ClaimantText.claimed=claimed by {0}
ClaimedBuildsReport.ClaimantText.claimedWithReason=assigned to {0} by {2} because: {1}
ClaimedBuildsReport.ClaimantText.claimed=assigned to {0} by {1}

ClaimPublisher.DisplayName=Allow broken build claiming

@@ -1,3 +1,3 @@
<div>
The user you are assigning the claim to. Blank means yourself.
The user you are assigning the claim to.
</div>
@@ -37,7 +37,6 @@
import org.jvnet.hudson.test.FailureBuilder;

import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlOption;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
@@ -83,6 +82,7 @@ public void failed_build_can_be_claimed_by_you() throws Exception {
assertThat(action.getClaimedBy(), is("user1"));
assertThat(action.getReason(), is(claimText));
assertThat(action.isClaimed(), is(true));
assertThat (action.getAssignedBy(), is("user1"));
}

@Test
@@ -93,6 +93,7 @@ public void failed_build_can_be_assigned() throws Exception {
assertThat(action.getClaimedBy(), is("user2"));
assertThat(action.getReason(), is(claimText));
assertThat(action.isClaimed(), is(true));
assertThat(action.getAssignedBy(), is("user1"));
}

@Test
@@ -105,6 +106,7 @@ public void claimed_build_can_be_reclaimed_by_you() throws Exception {
assertThat(action.getClaimedBy(), is("user1"));
assertThat(action.getReason(), is(claimText));
assertThat(action.isClaimed(), is(true));
assertThat(action.getAssignedBy(), is("user1"));
}

@Test
@@ -128,6 +130,7 @@ public void claim_can_be_reassigned() throws Exception {
assertThat(action.getClaimedBy(), is("user2"));
assertThat(action.getReason(), is(claimText));
assertThat(action.isClaimed(), is(true));
assertThat(action.getAssignedBy(), is("user1"));
}

@Test
@@ -142,6 +145,7 @@ public void sticky_claim_propagates_to_next_build() throws Exception {
assertThat(action2.getClaimedBy(), is("user1"));
assertThat(action2.getReason(), is("reason"));
assertThat(action2.isSticky(), is(true));
assertThat(action2.getAssignedBy(),is("user1"));
}

@Test
@@ -158,13 +162,13 @@ public void non_sticky_claim_does_not_propagate_to_next_build() throws Exception

private ClaimBuildAction givenBuildClaimedByOtherUser() {
ClaimBuildAction action = build.getAction(ClaimBuildAction.class);
action.claim("user2", "reason", true);
action.claim("user2", "reason", "user1", true);
return action;
}

private ClaimBuildAction givenBuildClaimedByCurrentUser() {
ClaimBuildAction action = build.getAction(ClaimBuildAction.class);
action.claim("user1", "reason", true);
action.claim("user1", "reason", "user1", true);
return action;
}

0 comments on commit 69dd1a8

Please sign in to comment.