mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-10 15:49:57 +00:00
Added API to handle emails.
This commit is contained in:
34
src/main/java/org/kohsuke/github/GHMyself.java
Normal file
34
src/main/java/org/kohsuke/github/GHMyself.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents the account that's logging into GitHub.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class GHMyself extends GHUser {
|
||||
/**
|
||||
* Returns the read-only list of e-mail addresses configured for you.
|
||||
*
|
||||
* This corresponds to the stuff you configure in https://github.com/settings/emails,
|
||||
* and not to be confused with {@link #getEmail()} that shows your public e-mail address
|
||||
* set in https://github.com/settings/profile
|
||||
*
|
||||
* @return
|
||||
* Always non-null.
|
||||
*/
|
||||
public List<String> getEmails() throws IOException {
|
||||
String[] addresses = root.retrieveWithAuth3("/user/emails",String[].class);
|
||||
return Collections.unmodifiableList(Arrays.asList(addresses));
|
||||
}
|
||||
|
||||
// public void addEmails(Collection<String> emails) throws IOException {
|
||||
//// new Poster(root,ApiVersion.V3).withCredential().to("/user/emails");
|
||||
// root.retrieveWithAuth3()
|
||||
// }
|
||||
}
|
||||
@@ -49,6 +49,7 @@ import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.codehaus.jackson.map.DeserializationConfig.Feature;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
@@ -240,19 +241,16 @@ public class GitHub {
|
||||
/**
|
||||
* Gets the {@link GHUser} that represents yourself.
|
||||
*/
|
||||
public GHUser getMyself() throws IOException {
|
||||
@WithBridgeMethods(GHUser.class)
|
||||
public GHMyself getMyself() throws IOException {
|
||||
requireCredential();
|
||||
|
||||
if (oauthAccessToken != null) {
|
||||
GHUser u = retrieveWithAuth("/user/show", JsonUser.class).user;
|
||||
|
||||
u.root = this;
|
||||
users.put(u.getLogin(), u);
|
||||
|
||||
return u;
|
||||
} else {
|
||||
return getUser(login);
|
||||
}
|
||||
GHMyself u = retrieveWithAuth("/user/show", JsonMyself.class).user;
|
||||
|
||||
u.root = this;
|
||||
users.put(u.getLogin(), u);
|
||||
|
||||
return u;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
8
src/main/java/org/kohsuke/github/JsonMyself.java
Normal file
8
src/main/java/org/kohsuke/github/JsonMyself.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
/**
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
class JsonMyself {
|
||||
GHMyself user;
|
||||
}
|
||||
@@ -64,8 +64,8 @@ public class AppTest extends TestCase {
|
||||
for (GHHook h : r.getHooks())
|
||||
h.delete();
|
||||
}
|
||||
|
||||
public void testApp() throws IOException {
|
||||
|
||||
public void testEventApi() throws Exception {
|
||||
GitHub gitHub = GitHub.connect();
|
||||
for (GHEventInfo ev : gitHub.getEvents()) {
|
||||
System.out.println(ev);
|
||||
@@ -75,6 +75,11 @@ public class AppTest extends TestCase {
|
||||
System.out.println(pr.getPullRequest());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testApp() throws IOException {
|
||||
GitHub gitHub = GitHub.connect();
|
||||
System.out.println(gitHub.getMyself().getEmails());
|
||||
|
||||
// GHRepository r = gitHub.connect().getOrganization("jenkinsci").createRepository("kktest4", "Kohsuke's test", "http://kohsuke.org/", "Everyone", true);
|
||||
// r.fork();
|
||||
|
||||
Reference in New Issue
Block a user