mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-10 08:21:21 +00:00
added a method to test credential.
This commit is contained in:
@@ -188,6 +188,18 @@ public class GitHub {
|
||||
.with("public", isPublic ? 1 : 0).to(getApiURL("/repos/create"), JsonRepository.class).wrap(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that the credential is valid.
|
||||
*/
|
||||
public boolean isCredentialValid() throws IOException {
|
||||
try {
|
||||
retrieveWithAuth(getApiURL("/user/show"),JsonUser.class);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
WebClient createWebClient() throws IOException {
|
||||
WebClient wc = new WebClient();
|
||||
wc.setJavaScriptEnabled(false);
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package org.kohsuke;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import org.kohsuke.github.GHOrganization;
|
||||
import org.kohsuke.github.GHRepository;
|
||||
import org.kohsuke.github.GHTeam;
|
||||
@@ -16,6 +14,11 @@ import java.util.Set;
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest extends TestCase {
|
||||
public void testCredentialValid() throws IOException {
|
||||
assertTrue(GitHub.connect().isCredentialValid());
|
||||
assertFalse(GitHub.connect("totally","bogus").isCredentialValid());
|
||||
}
|
||||
|
||||
public void testApp() throws IOException {
|
||||
GitHub gitHub = GitHub.connect();
|
||||
// testOrganization(gitHub);
|
||||
|
||||
Reference in New Issue
Block a user