mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-10 15:49:57 +00:00
added code to list up public keys
This commit is contained in:
48
src/main/java/org/kohsuke/github/GHKey.java
Normal file
48
src/main/java/org/kohsuke/github/GHKey.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* SSH public key.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class GHKey {
|
||||
/*package almost final*/ GitHub root;
|
||||
|
||||
private String url, key, title;
|
||||
private boolean verified;
|
||||
private int id;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Something like "https://api.github.com/user/keys/73593"
|
||||
*/
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public boolean isVerified() {
|
||||
return verified;
|
||||
}
|
||||
|
||||
/*package*/ GHKey wrap(GitHub root) {
|
||||
this.root = root;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this).append("title",title).append("id",id).append("key",key).toString();
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,16 @@ public class GHMyself extends GHUser {
|
||||
String[] addresses = root.retrieveWithAuth3("/user/emails",String[].class);
|
||||
return Collections.unmodifiableList(Arrays.asList(addresses));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the read-only list of all the pulic keys of the current user.
|
||||
*
|
||||
* @return
|
||||
* Always non-null.
|
||||
*/
|
||||
public List<GHKey> getPublicKeys() throws IOException {
|
||||
return Collections.unmodifiableList(Arrays.asList(root.retrieveWithAuth3("/user/keys",GHKey[].class)));
|
||||
}
|
||||
|
||||
// public void addEmails(Collection<String> emails) throws IOException {
|
||||
//// new Poster(root,ApiVersion.V3).withCredential().to("/user/emails");
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.kohsuke.github.GHEventPayload;
|
||||
import org.kohsuke.github.GHHook;
|
||||
import org.kohsuke.github.GHBranch;
|
||||
import org.kohsuke.github.GHIssueState;
|
||||
import org.kohsuke.github.GHKey;
|
||||
import org.kohsuke.github.GHMyself;
|
||||
import org.kohsuke.github.GHOrganization;
|
||||
import org.kohsuke.github.GHOrganization.Permission;
|
||||
@@ -56,6 +57,12 @@ public class AppTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testPublicKeys() throws Exception {
|
||||
GitHub gh = GitHub.connect();
|
||||
List<GHKey> keys = gh.getMyself().getPublicKeys();
|
||||
System.out.println(keys);
|
||||
}
|
||||
|
||||
public void tryOrgFork() throws Exception {
|
||||
GitHub gh = GitHub.connect();
|
||||
gh.getUser("kohsuke").getRepository("rubywm").forkTo(gh.getOrganization("jenkinsci"));
|
||||
|
||||
Reference in New Issue
Block a user