diff --git a/pom.xml b/pom.xml index 452fbaba7f..1ada8628b5 100644 --- a/pom.xml +++ b/pom.xml @@ -3,11 +3,11 @@ org.kohsuke pom - 1 + 3 github-api - 1.19 + 1.20 GitHub API for Java http://github-api.kohsuke.org/ GitHub API for Java diff --git a/src/main/java/org/kohsuke/github/GHPerson.java b/src/main/java/org/kohsuke/github/GHPerson.java index f58ff4e57a..fa155ca454 100644 --- a/src/main/java/org/kohsuke/github/GHPerson.java +++ b/src/main/java/org/kohsuke/github/GHPerson.java @@ -58,11 +58,26 @@ public GHRepository getRepository(String name) throws IOException { /** * Gravatar ID of this user, like 0cb9832a01c22c083390f3c5dcb64105 + * + * @deprecated + * No longer available in the v3 API. */ public String getGravatarId() { return gravatar_id; } + /** + * Returns a string like 'https://secure.gravatar.com/avatar/0cb9832a01c22c083390f3c5dcb64105' + * that indicates the avatar image URL. + */ + public String getAvatarUrl() { + if (avatar_url!=null) + return avatar_url; + if (gravatar_id!=null) + return "https://secure.gravatar.com/avatar/"+gravatar_id; + return null; + } + /** * Gets the login ID of this user, like 'kohsuke' */ diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 7684bfed14..86e805d53f 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -68,9 +68,11 @@ public class GHRepository { private String html_url; // this is the UI private GHUser owner; // not fully populated. beware. private boolean has_issues, has_wiki, fork, _private, has_downloads; - private int watchers,forks,open_issues; + private int watchers,forks,open_issues,size; private String created_at, pushed_at; private Map milestones = new HashMap(); + + private String master_branch; public String getDescription() { return description; @@ -162,6 +164,19 @@ public Date getCreatedAt() { return GitHub.parseDate(created_at); } + /** + * Returns the primary branch you'll configure in the "Admin > Options" config page. + * + * @return + * This field is null until the user explicitly configures the master branch. + */ + public String getMasterBranch() { + return master_branch; + } + + public int getSize() { + return size; + } /** * Gets the collaborators on this repository. diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index d95287f243..76b2684f15 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -245,7 +245,7 @@ private T _retrieve(String tailApiUrl, Class type, String method, boolean public GHMyself getMyself() throws IOException { requireCredential(); - GHMyself u = retrieveWithAuth("/user/show", JsonMyself.class).user; + GHMyself u = retrieveWithAuth3("/user", GHMyself.class); u.root = this; users.put(u.getLogin(), u); @@ -259,17 +259,9 @@ public GHMyself getMyself() throws IOException { public GHUser getUser(String login) throws IOException { GHUser u = users.get(login); if (u == null) { - - if (oauthAccessToken != null) { - u = retrieve("/user/show/" + login, JsonUser.class).user; - u.root = this; - users.put(u.getLogin(), u); - } else { - u = retrieve("/user/show/" + login, JsonUser.class).user; - u.root = this; - users.put(login, u); - } - + u = retrieve3("/users/" + login, GHUser.class); + u.root = this; + users.put(u.getLogin(), u); } return u; } @@ -352,7 +344,7 @@ public GHRepository createRepository(String name, String description, String hom */ public boolean isCredentialValid() throws IOException { try { - retrieveWithAuth("/user/show",JsonUser.class); + retrieveWithAuth3("/user",GHUser.class); return true; } catch (IOException e) { return false; diff --git a/src/main/java/org/kohsuke/github/JsonUser.java b/src/main/java/org/kohsuke/github/JsonUser.java deleted file mode 100644 index 1fae836dca..0000000000 --- a/src/main/java/org/kohsuke/github/JsonUser.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2010, Kohsuke Kawaguchi - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.kohsuke.github; - -/** - * @author Kohsuke Kawaguchi - */ -class JsonUser { - public GHUser user; -} diff --git a/src/test/java/org/kohsuke/AppTest.java b/src/test/java/org/kohsuke/AppTest.java index 06fcedb22a..8260a1dce0 100644 --- a/src/test/java/org/kohsuke/AppTest.java +++ b/src/test/java/org/kohsuke/AppTest.java @@ -7,10 +7,12 @@ import org.kohsuke.github.GHHook; import org.kohsuke.github.GHBranch; import org.kohsuke.github.GHIssueState; +import org.kohsuke.github.GHMyself; import org.kohsuke.github.GHOrganization; import org.kohsuke.github.GHOrganization.Permission; import org.kohsuke.github.GHRepository; import org.kohsuke.github.GHTeam; +import org.kohsuke.github.GHUser; import org.kohsuke.github.GitHub; import java.io.IOException; @@ -31,9 +33,18 @@ public void testCredentialValid() throws IOException { public void testFetchPullRequest() throws Exception { GitHub gh = GitHub.connect(); GHRepository r = gh.getOrganization("jenkinsci").getRepository("jenkins"); + assertEquals("master",r.getMasterBranch()); r.getPullRequest(1); r.getPullRequests(GHIssueState.OPEN); } + + public void tryGetMyself() throws Exception { + GitHub hub = GitHub.connect(); + GHMyself me = hub.getMyself(); + System.out.println(me); + GHUser u = hub.getUser("kohsuke2"); + System.out.println(u); + } public void tryOrgFork() throws Exception { GitHub gh = GitHub.connect();