/**
  * @param onlyIfLastCompleted When the statuses aren't sorted, we only show the last failed when
  *     it is also the latest completed build.
  */
 public static BuildInfo getLastFailedBuild(
     Job<?, ?> job,
     Locale locale,
     boolean onlyIfLastCompleted,
     boolean isShowColorblindUnderlineHint,
     boolean isFirst,
     TimeAgoType timeAgoType) {
   Run<?, ?> lastFailedBuild = job.getLastFailedBuild();
   Run<?, ?> lastCompletedBuild = job.getLastCompletedBuild();
   if (lastFailedBuild == null) {
     return null;
   } else if (!onlyIfLastCompleted || (lastCompletedBuild.number == lastFailedBuild.number)) {
     return createBuildInfo(
         job.getLastFailedBuild(),
         BuildInfo.FAILED_COLOR,
         FAILED_UNDERLINE_STYLE,
         getFailedMessage(),
         "lastFailedBuild",
         job,
         locale,
         isShowColorblindUnderlineHint,
         isFirst,
         timeAgoType);
   } else {
     return null;
   }
 }
  @SuppressWarnings("rawtypes")
  public List<ReportObject> getRedBuildList(String viewName) {
    View view = Jenkins.getInstance().getView(viewName);
    RunList builds = view.getBuilds();
    RunList failedBuilds = builds.failureOnly();
    Set<String> processedProjects = new HashSet<String>();
    List<ReportObject> objects = new LinkedList<ReportObject>();
    @SuppressWarnings("unchecked")
    Iterator<Run> failedBuildIterator = failedBuilds.iterator();
    while (failedBuildIterator.hasNext()) {
      Job parent = failedBuildIterator.next().getParent();
      if (!processedProjects.contains(parent.getFullName())) {
        Run lastBuildCompleted = parent.getLastBuild();
        if (lastBuildCompleted != null && lastBuildCompleted.isBuilding()) {
          lastBuildCompleted = lastBuildCompleted.getPreviousBuild();
        }
        if (parent.getLastFailedBuild() != null
            && lastBuildCompleted != null
            && lastBuildCompleted.getResult().isWorseThan(Result.SUCCESS)
            && (lastBuildCompleted.getAction(VolunteerAction.class) != null)) {
          objects.add(ReportObject.getInstance(parent, lastBuildCompleted));
          processedProjects.add(parent.getFullName());
        }
      } else {
        System.out.println("Already processed parent " + parent.getDisplayName());
      }
    }

    Collections.sort(
        objects,
        new Comparator<ReportObject>() {
          @Override
          public int compare(ReportObject o1, ReportObject o2) {
            return (o2.getFailedBuilds() - o1.getFailedBuilds()) * 10
                + o1.getLastFailedBuildname().compareTo(o2.getLastFailedBuildname());
          }
        });

    return objects;
  }
 @Override
 public Run<?, ?> getBuild(Job<?, ?> project) {
   return project.getLastFailedBuild();
 }