Skip to content

Commit

Permalink
Added branch support, in theory it works but does not in practise (bu…
Browse files Browse the repository at this point in the history
…t neither do the others tag/revision)
  • Loading branch information
David Rubin committed Feb 7, 2012
1 parent a2aa205 commit bc7422e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import hudson.plugins.git.IGitAPI;
import hudson.plugins.git.GitAPI;
import hudson.plugins.git.Revision;
import hudson.plugins.git.Branch;



public class GitParameterDefinition extends ParameterDefinition {
Expand All @@ -44,6 +46,8 @@ public class GitParameterDefinition extends ParameterDefinition {
public static final String PARAMETER_TYPE_TAG = "PT_TAG";

public static final String PARAMETER_TYPE_REVISION = "PT_REVISION";

public static final String PARAMETER_TYPE_BRANCH = "PT_BRANCH";

@Extension
public static class DescriptorImpl extends ParameterDescriptor {
Expand All @@ -61,6 +65,8 @@ public String getDisplayName() {

private Map<String, String> revisionMap;
private Map<String, String> tagMap;
private Map<String, String> branchMap;


@DataBoundConstructor
public GitParameterDefinition(String name,
Expand Down Expand Up @@ -200,7 +206,14 @@ public void generateContents(String contenttype) {
for(String tagName: newgit.getTagNames("*")) {
tagMap.put(tagName, tagName);
}
}
} else if(type.equalsIgnoreCase(PARAMETER_TYPE_BRANCH)) {
branchMap = new HashMap<String, String>();

//Set<String> tagNameList = newgit.getTagNames("*");
for(Branch branch: newgit.getBranches()) {
branchMap.put(branch.getSHA1String(), branch.toString());
}
}

}
}
Expand All @@ -226,5 +239,12 @@ public Map<String, String> getTagMap() {
return tagMap;
}

public Map<String, String> getBranchMap() {
if( branchMap == null || branchMap.isEmpty()){
generateContents(PARAMETER_TYPE_BRANCH);
}
return branchMap;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@
<j:otherwise>
<option value="PT_REVISION">Revision</option>
</j:otherwise>
</j:choose>
</j:choose>
<j:choose>
<j:when test="${instance.type eq 'PT_BRANCH'}">
<option value="PT_BRANCH" selected="selected">Branch</option>
</j:when>
<j:otherwise>
<option value="PT_BRANCH">Branch</option>
</j:otherwise>
</j:choose>
</select>
</f:entry>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
The type of the list of parameters:
<ul>
<li>Tag - list of all commit tags in repository - returns Tag Name</li>
<li>Branch - list of all commit branches in repository - returns Branch Name</li>
<li>Revision - list of all revision sha1 in repository followed
by its author and date - returns Tag SHA1</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
</j:choose>
</j:forEach>
</select>
</j:when>
<j:when test="${it.type eq 'PT_BRANCH'}">
<input type="hidden" name="name" value="${it.name}" />
<select name="value" size="5" width="200px">
<j:forEach var="val" items="${it.branchMap}" >
<j:choose>
<option value="${val.key}">${val.value}</option>
</j:choose>
</j:forEach>
</select>
</j:when>
</j:choose>
</div>
Expand Down

0 comments on commit bc7422e

Please sign in to comment.