Skip to content

Commit

Permalink
Merge pull request #60 from dnozay/JENKINS-3549
Browse files Browse the repository at this point in the history
JENKINS-3549: display promotion stars on the view.
  • Loading branch information
oleg-nenashev committed Aug 20, 2015
2 parents c346052 + b9e830c commit 33470ae
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 1 deletion.
28 changes: 27 additions & 1 deletion pom.xml
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down Expand Up @@ -44,12 +45,37 @@
</licenses>

<repositories>
<!-- needed unless you have a profile for those -->
<repository>
<id>jenkins-releases</id>
<url>http://repo.jenkins-ci.org/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

<pluginRepositories>
<!-- needed unless you have a profile for those -->
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
Expand Down
Expand Up @@ -17,6 +17,8 @@
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.stapler.interceptor.RequirePOST;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

/**
* For customizing project top-level GUI.
Expand Down Expand Up @@ -58,6 +60,27 @@ public AbstractBuild<?,?> getLatest(PromotionProcess p) {
return list.size() > 0 ? list.get(0) : null;
}

@Restricted(NoExternalUse.class)
public List<PromotionProcess> getPromotionProcesses() {
List<PromotionProcess> processes = null;
processes = getProcesses();
if (processes == null) {
// assert ?
// this case should not happen, the action should get deleted
// when there is no process; but we're now safe for the UI.
processes = new ArrayList<PromotionProcess>();
}
return processes;
}

@Restricted(NoExternalUse.class)
public Status getStatus(PromotionProcess process) {
List<Promotion> list = getPromotions( process );
Promotion latest = list.size() > 0 ? list.get(0) : null;
Status status = latest != null ? latest.getStatus() : null;
return status;
}

/**
* Finds the last promoted build under the given criteria.
*/
Expand Down
@@ -0,0 +1,42 @@
package hudson.plugins.promoted_builds;

import org.kohsuke.stapler.DataBoundConstructor;

import hudson.Extension;
import hudson.model.Job;
import hudson.model.Run;
import hudson.views.ListViewColumn;
import hudson.views.ListViewColumnDescriptor;

import java.util.ArrayList;
import java.util.List;

public class PromotionStatusColumn extends ListViewColumn {

@DataBoundConstructor
public PromotionStatusColumn() {
super();
}

public PromotedProjectAction getAction(Job job) {
PromotedProjectAction action = job.getAction(PromotedProjectAction.class);
return action;
}

@Extension
public static class DescriptorImpl extends ListViewColumnDescriptor {

public DescriptorImpl() {
}

@Override
public String getDisplayName() {
return Messages.PromotionStatusColumn_DisplayName();
}

public boolean shownByDefault() {
return false;
}
}

}
9 changes: 9 additions & 0 deletions src/main/java/hudson/plugins/promoted_builds/Status.java
Expand Up @@ -29,6 +29,8 @@
import jenkins.model.Jenkins;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

/**
* Promotion status of a build wrt a specific {@link PromotionProcess}.
Expand Down Expand Up @@ -266,6 +268,13 @@ public Promotion getLast() {
return null;
}

@Restricted(NoExternalUse.class)
public Boolean isLastAnError() {
Promotion l = getLast();
return (l != null && l.getResult() != Result.SUCCESS);
}


/**
* Gets all the promotion builds.
*/
Expand Down
Expand Up @@ -36,3 +36,4 @@ Promotion.PromotePermission.Description=This permission allows user to use force
Promotion.RunnerImpl.Promoting = Promoting {0}
Promotion.RunnerImpl.SchedulingBuild = scheduling build for {0}
PromotionCause.ShortDescription = Started by promotion {0} for project "{1}", build number {2}
PromotionStatusColumn.DisplayName = Promotions
@@ -0,0 +1,40 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout">
<td>
<j:set var="ppa" value="${it.getAction(job)}"/>
<j:choose>
<j:when test="${ppa!=null}">
<j:set var="pp" value="${ppa.getPromotionProcesses()}"/>
<j:forEach var="process" items="${pp}">
<j:set var="status" value="${ppa.getStatus(process)}"/>
<j:set var="icon" value="${process.getIcon()}"/>
<j:set var="iconUrl" value="${resURL}/plugin/promoted-builds/icons/${iconSize}/${icon}.png"/>
<img width="${iconSize}" height="${iconSize}"
title="${%PromotionProcess} ${process.name}"
src="${iconUrl}"/>
<j:choose>
<j:when test="${status!=null}">
<j:if test="${status.isLastAnError()}">
<j:set var="iconUrl" value="${resURL}/images/${iconSize}/error.png"/>
<img width="${iconSize}" height="${iconSize}"
title="${%PromotionProcess} ${process.name} ${%PromotionProcess.failed}"
src="${iconUrl}"/>
</j:if>
<j:set var="target" value="${status.getTarget()}"/>
<a href="${jobBaseUrl}${job.shortUrl}${target.number}/" class="model-link inside">
${target.displayName}
</a>
</j:when>
<j:otherwise><!-- promotion has never happened / no builds -->
${%Otherwise.noBuild}
</j:otherwise>
</j:choose>
</j:forEach>
</j:when>
<j:otherwise><!-- job has no promotion process (no project action) -->
${%Otherwise.noPromotedProjectAction}
</j:otherwise>
</j:choose>
</td>
</j:jelly>

@@ -0,0 +1,4 @@
PromotionProcess = Promotion process
PromotionProcess.failed = failed
Otherwise.noBuild = N/A
Otherwise.noPromotedProjectAction = N/A
@@ -0,0 +1,6 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core">
<th>
${%PromotionStatusColumn.Header}
</th>
</j:jelly>
@@ -0,0 +1 @@
PromotionStatusColumn.Header = Promotions
@@ -0,0 +1,8 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<f:block>
<p>${%PromotionStatusColumn.Blurb}</p>
</f:block>
</j:jelly>
@@ -0,0 +1 @@
PromotionStatusColumn.Blurb = This column shows the promotion status of the last build.

0 comments on commit 33470ae

Please sign in to comment.