Commit dc982127 authored by Greg Messner's avatar Greg Messner
Browse files

Added getBranch() to simplify pulling the branch out of the refs.

parent a913a19b
......@@ -7,6 +7,8 @@ import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import org.codehaus.jackson.annotate.JsonIgnore;
import com.messners.gitlab.api.Commit;
import com.messners.gitlab.api.Repository;
......@@ -95,4 +97,28 @@ public class PushEvent {
public void setUserName (String userName) {
this.userName = userName;
}
/**
* Gets the branch name from the ref. Will return null if the ref does not start with "refs/heads/".
*
* @return the branch name from the ref
*/
@JsonIgnore
public String getBranch () {
String ref = getRef();
if (ref == null || ref.trim().length() == 0) {
return (null);
}
ref = ref.trim();
int refsHeadsIndex = ref.indexOf(REFS_HEADS);
if (refsHeadsIndex != 0) {
return (null);
}
return (ref.substring(REFS_HEADS.length()));
}
private static final String REFS_HEADS = "refs/heads/";
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment