Skip to content

Commit

Permalink
Implemented JENKINS-37331 - Add branches to build list view column
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsNielsen committed Apr 19, 2017
1 parent 44da1a4 commit 8ccee77
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/main/java/hudson/plugins/git/GitBranchSpecifierColumn.java
@@ -0,0 +1,56 @@
package hudson.plugins.git;

import hudson.views.ListViewColumn;
import hudson.Extension;
import hudson.model.Item;
import hudson.scm.SCM;
import hudson.views.ListViewColumnDescriptor;
import java.util.ArrayList;
import jenkins.triggers.SCMTriggerItem;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* Class that adds an optional 'Git branches to build' column to a list view.
*
* @author Mads
*/
public class GitBranchSpecifierColumn extends ListViewColumn {

@DataBoundConstructor
public GitBranchSpecifierColumn() { }

public String getBranchSpecifier( final Item item ) {
String branchSpec = "";
SCMTriggerItem s = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(item);
if(s != null) {
for(SCM scm : s.getSCMs()) {
if (scm instanceof GitSCM) {
GitSCM gitScm = (GitSCM)scm;
ArrayList<String> branches = new ArrayList<String>();
for(BranchSpec spec : gitScm.getBranches()) {
branches.add(spec.getName());
}
branchSpec = StringUtils.join(branches, " ");
}
}
}
return branchSpec;
}

@Extension
public static class DescriptorImpl extends ListViewColumnDescriptor {

@Override
public String getDisplayName() {
return "Git branches to build";
}

@Override
public boolean shownByDefault() {
return false;
}

}

}
@@ -0,0 +1,9 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core">
<j:set var="branchSpec" value="${it.getBranchSpecifier(job)}"/>
<td data="${branchSpec}">
<j:forEach items="${branchSpec.split(' ')}" var="i">
<p>${i}</p>
</j:forEach>
</td>
</j:jelly>

0 comments on commit 8ccee77

Please sign in to comment.