Skip to content

Commit

Permalink
Merge pull request #430 from Praqma/JENKINS-37331
Browse files Browse the repository at this point in the history
Implemented [JENKINS-37331] - Add branches to build list view column
  • Loading branch information
MarkEWaite committed Apr 19, 2017
2 parents 44da1a4 + 69cf99c commit 383f5ab
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/main/java/hudson/plugins/git/GitBranchSpecifierColumn.java
@@ -0,0 +1,59 @@
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 java.util.List;
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 List<String> getBranchSpecifier( final Item item ) {
List<String> branchSpec = new ArrayList<String>();
SCMTriggerItem s = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(item);
if(s != null) {
for(SCM scm : s.getSCMs()) {
if (scm instanceof GitSCM) {
GitSCM gitScm = (GitSCM)scm;
for(BranchSpec spec : gitScm.getBranches()) {
branchSpec.add(spec.getName());
}
}
}
}
return branchSpec;
}

public String breakOutString(List<String> branches) {
return StringUtils.join(branches, ", ");
}

@Extension
public static class DescriptorImpl extends ListViewColumnDescriptor {

@Override
public String getDisplayName() {
return "Git Branches";
}

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

}

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

0 comments on commit 383f5ab

Please sign in to comment.