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-20797] - Rework handling of Users in RecentReleasesPortlet #18

Merged
merged 1 commit into from
Sep 28, 2016
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import hudson.model.Run;
import hudson.model.User;
import hudson.model.Cause.UserCause;
import hudson.model.Cause.UserIdCause;
import hudson.plugins.release.ReleaseWrapper.ReleaseBuildBadgeAction;
import hudson.plugins.view.dashboard.DashboardPortlet;
import hudson.tasks.Mailer;
Expand All @@ -18,11 +19,13 @@
import java.io.IOException;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

import javax.servlet.ServletException;
import jenkins.model.JenkinsLocationConfiguration;

import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
Expand Down Expand Up @@ -161,18 +164,33 @@ public Calendar getEntryTimestamp(Run entry) {
return entry.getTimestamp();
}

@Override
public String getEntryAuthor(Run entry) {
// release builds are manual so get the UserCause
// and report rss entry as user who kicked off build
List<Cause> causes = entry.getCauses();
for (Cause cause : causes) {
if (cause instanceof UserCause) {
return User.get(((UserCause) cause).getUserName()).getFullName();
}
}

// in the unexpected case where there is no user cause, return admin
return Mailer.descriptor().getAdminAddress();
// release builds are manual so get the UserCause
// and report rss entry as user who kicked off build
List<Cause> causes = entry.getCauses();
for (Cause cause : causes) {
final String userName;
if (cause instanceof UserIdCause) {
userName = ((UserIdCause)cause).getUserName();
} else if (cause instanceof UserCause) {
userName = ((UserCause)cause).getUserName();
} else {
userName = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't work unless the first cause is any of the two user causes, if the first cause is something else you won't be able to set it in the next loop around. Effectively you are only looking at the first cause in the list.

Copy link
Member Author

@oleg-nenashev oleg-nenashev Sep 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYM? It's a local final variable within the loop.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes. Sorry I saw it as outside of the loop. Sorry for the confusion.

}

if (userName != null) {
final User usr = User.get(userName, false, Collections.emptyMap());
return usr != null ? usr.getFullName() : userName;
}
}

// in the unexpected case where there is no user cause, return admin
final JenkinsLocationConfiguration jlc = JenkinsLocationConfiguration.get();
if (jlc == null) {
throw new IllegalStateException("JenkinsLocationConfiguration is not available");
}
return jlc.getAdminAddress();
}
}
}