Skip to content

Commit

Permalink
Added GHBranch creator
Browse files Browse the repository at this point in the history
Added GHBranch creator and added a test to make sure it works
  • Loading branch information
Alex Taylor committed Nov 15, 2019
1 parent 834c84c commit 8d50b33
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/main/java/org/kohsuke/github/GHBranch.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.kohsuke.github;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.io.IOException;
import java.net.URL;
import java.util.Collection;
Expand All @@ -26,7 +26,15 @@ public class GHBranch {
private boolean protection;
private String protection_url;


@JsonCreator
GHBranch(@JsonProperty("name") String name) throws Exception{
if (name != null) {
this.name = name;
}
else{
throw new GHFileNotFoundException("Branch Not Found");
}
}
public static class Commit {
String sha;

Expand Down
5 changes: 3 additions & 2 deletions src/test/java/org/kohsuke/github/GHRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ public void getBranchNonExistentBut200Status() throws Exception {
GHBranch branch = repo.getBranch("test/NonExistent");
fail();
}
catch(GHFileNotFoundException e){
assertEquals("{\"message\":\"Branch not found\",\"documentation_url\":\"https://developer.github.com/v3/repos/branches/#get-branch\"}", e.getMessage());
catch(Exception e){
//I dont really love this but I wanted to get to the root wrapped cause
assertEquals("Branch Not Found", e.getCause().getCause().getCause().getMessage());
}
}

Expand Down

0 comments on commit 8d50b33

Please sign in to comment.