diff --git a/pom.xml b/pom.xml index b9125ef22..6aa7f12fc 100644 --- a/pom.xml +++ b/pom.xml @@ -3,11 +3,11 @@ org.kohsuke pom - 3 + 4 github-api - 1.35-SNAPSHOT + 1.36-SNAPSHOT GitHub API for Java http://github-api.kohsuke.org/ GitHub API for Java diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 51b9665d9..177f19781 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -55,6 +55,8 @@ import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.*; */ public class GitHub { /*package*/ final String login; + + /*package*/ final String encodedAuthorization; /*package*/ final String apiToken; @@ -65,7 +67,7 @@ public class GitHub { private final String apiUrl; private GitHub(String login, String apiToken, String password) { - this ("https://api.github.com", login, apiToken, password); + this (GITHUB_URL, login, apiToken, password); } /** @@ -112,7 +114,11 @@ public class GitHub { } finally { IOUtils.closeQuietly(in); } - return new GitHub(props.getProperty("login"),props.getProperty("token"),props.getProperty("password")); + String oauth = props.getProperty("oauth"); + if (oauth!=null) + return new GitHub(GITHUB_URL,oauth); + else + return new GitHub(props.getProperty("login"),props.getProperty("token"),props.getProperty("password")); } /** @@ -164,7 +170,7 @@ public class GitHub { if (tailApiUrl.startsWith("/")) { if ("github.com".equals(apiUrl)) {// backward compatibility - return new URL("https://api.github.com" + tailApiUrl); + return new URL(GITHUB_URL + tailApiUrl); } else { return new URL(apiUrl + tailApiUrl); } @@ -339,4 +345,6 @@ public class GitHub { MAPPER.setVisibilityChecker(new Std(NONE, NONE, NONE, NONE, ANY)); MAPPER.getDeserializationConfig().set(Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); } + + private static final String GITHUB_URL = "https://api.github.com"; } diff --git a/src/site/apt/index.apt b/src/site/apt/index.apt deleted file mode 100644 index 28254de23..000000000 --- a/src/site/apt/index.apt +++ /dev/null @@ -1,25 +0,0 @@ -What is this? - - This library defines an object oriented representation of the GitHub API. The library doesn't yet cover the entirety of the GitHub API, but it's implemented with the right abstractions and libraries to make it very easy to improve the coverage. - -Sample Usage - ------------------- -GitHub github = GitHub.connect(); -GHRepository repo = github.createRepository( - "new-repository","this is my new repository", - "http://www.kohsuke.org/",true/*public*/); -repo.addCollaborators(github.getUser("abayer"),github.getUser("rtyler")); -repo.delete(); ------------------- - -Credential - - This library allows the caller to supply the credential as parameters, but it also defines a common convention - so that applications using this library will look at the consistent location. In this convention, the library - looks at "~/.github" property file, which should have the following two values: - ------------------- -login=kohsuke -token=012345678 ------------------- diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md new file mode 100644 index 000000000..ba9fbb528 --- /dev/null +++ b/src/site/markdown/index.md @@ -0,0 +1,36 @@ +What is this? +===== + +This library defines an object oriented representation of the GitHub API. By "object oriented" we mean +there are classes that correspond to the domain model of GitHub (such as `GHUser` and `GHRepository`), +operations that act on them as defined as methods (such as `GHUser.follow()`), and those object references +are used in favor of using string handle (such as `GHUser.isMemberOf(GHOrganization)` instead of +`GHUser.isMemberOf(String)`) + +There are some corners of the GitHub API that's not yet implemented, but +the library is implemented with the right abstractions and libraries to make it very easy to improve the coverage. + +Sample Usage +----- + + GitHub github = GitHub.connect(); + GHRepository repo = github.createRepository( + "new-repository","this is my new repository", + "http://www.kohsuke.org/",true/*public*/); + repo.addCollaborators(github.getUser("abayer"),github.getUser("rtyler")); + repo.delete(); + +Credential +---- + +This library allows the caller to supply the credential as parameters, but it also defines a common convention +so that applications using this library will look at the consistent location. In this convention, the library +looks at `~/.github` property file, which should have the following two values: + + login=kohsuke + password=012345678 + +Alternatively, you can have just the OAuth token in this file: + + oauth=4d98173f7c075527cb64878561d1fe70 +