Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented JENKINS-37331 - Add branches to build list view column
- Loading branch information
1 parent
44da1a4
commit 8ccee77
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/main/java/hudson/plugins/git/GitBranchSpecifierColumn.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/resources/hudson/plugins/git/GitBranchSpecifierColumn/column.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |