Skip to content

Commit

Permalink
[JENKINS-20892] Introduced method so that /user/*/rssLatest can check…
Browse files Browse the repository at this point in the history
… UserIdCause just like /user/*/builds already was.

(cherry picked from commit 76af02e)
  • Loading branch information
jglick authored and olivergondza committed Feb 28, 2014
1 parent 46d4a63 commit 915000b
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions core/src/main/java/hudson/model/User.java
Expand Up @@ -429,6 +429,22 @@ public String getDisplayName() {
return getFullName();
}

/** true if {@link AbstractBuild#hasParticipant} or {@link hudson.model.Cause.UserIdCause} */
private boolean relatedTo(AbstractBuild<?,?> b) {
if (b.hasParticipant(this)) {
return true;
}
for (Cause cause : b.getCauses()) {
if (cause instanceof Cause.UserIdCause) {
String userId = ((Cause.UserIdCause) cause).getUserId();
if (userId != null && userId.equals(getId())) {
return true;
}
}
}
return false;
}

/**
* Gets the list of {@link Build}s that include changes by this user,
* by the timestamp order.
Expand All @@ -440,16 +456,8 @@ public RunList getBuilds() {
List<AbstractBuild> r = new ArrayList<AbstractBuild>();
for (AbstractProject<?,?> p : Jenkins.getInstance().getAllItems(AbstractProject.class))
for (AbstractBuild<?,?> b : p.getBuilds().newBuilds()){
if(b.hasParticipant(this))
if (relatedTo(b)) {
r.add(b);
else {
//append builds that were run by this user
Cause.UserIdCause cause = b.getCause(Cause.UserIdCause.class);
if (cause != null) {
String userId = cause.getUserId();
if (userId != null && this.getId() != null && userId.equals(this.getId()))
r.add(b);
}
}
}
return RunList.fromRuns(r);
Expand Down Expand Up @@ -581,7 +589,7 @@ public void doRssLatest(StaplerRequest req, StaplerResponse rsp) throws IOExcept
final List<Run> lastBuilds = new ArrayList<Run>();
for (AbstractProject<?,?> p : Jenkins.getInstance().getAllItems(AbstractProject.class)) {
for (AbstractBuild<?,?> b = p.getLastBuild(); b != null; b = b.getPreviousBuild()) {
if (b.hasParticipant(this)) { // TODO or check UserIdCause
if (relatedTo(b)) {
lastBuilds.add(b);
break;
}
Expand Down

0 comments on commit 915000b

Please sign in to comment.