Compare commits

..

7 Commits

Author SHA1 Message Date
Kohsuke Kawaguchi
3080313aef [maven-release-plugin] prepare release github-api-1.2 2010-04-19 09:38:20 -07:00
Kohsuke Kawaguchi
0ddac59c9c added the fork support 2010-04-19 09:27:44 -07:00
Kohsuke Kawaguchi
131caf04e5 [maven-release-plugin] prepare for next development iteration 2010-04-18 22:24:12 -07:00
Kohsuke Kawaguchi
6c3884b94d [maven-release-plugin] prepare release github-api-1.1 2010-04-18 22:24:07 -07:00
Kohsuke Kawaguchi
540d473e42 bug fix 2010-04-18 22:21:30 -07:00
Kohsuke Kawaguchi
db717c86bb added following/follows support 2010-04-18 22:12:10 -07:00
Kohsuke Kawaguchi
4f9cace3fe [maven-release-plugin] prepare for next development iteration 2010-04-18 22:04:28 -07:00
6 changed files with 83 additions and 4 deletions

View File

@@ -3,7 +3,7 @@
<groupId>org.kohsuke</groupId>
<artifactId>github-api</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<version>1.2</version>
<name>GitHub API for Java</name>
<url>http://kohsuke.org/github-api/</url>
<description>GitHub API for Java</description>

View File

@@ -120,7 +120,6 @@ public class GHRepository {
}
private void modifyCollaborators(Collection<GHUser> users, String op) throws IOException {
root.requireCredential();
verifyMine();
for (GHUser user : users) {
new Poster(root).withCredential().to(root.getApiURL("/repos/collaborators/"+name+ op +user.getLogin()));
@@ -131,7 +130,6 @@ public class GHRepository {
* Deletes this repository.
*/
public void delete() throws IOException {
root.requireCredential();
verifyMine();
Poster poster = new Poster(root).withCredential();
URL url = root.getApiURL("/repos/delete/" + name);
@@ -140,6 +138,15 @@ public class GHRepository {
poster.with("delete_token",token.delete_token).to(url);
}
/**
* Forks this repository.
*/
public GHRepository fork() throws IOException {
GHRepository r = new Poster(root).withCredential().to(root.getApiURL("/repos/fork/" + owner + "/" + name), JsonRepository.class).repository;
r.root = root;
return r;
}
private void verifyMine() throws IOException {
if (!root.login.equals(owner))
throw new IOException("Operation not applicable to a repository owned by someone else: "+owner);

View File

@@ -27,6 +27,7 @@ import java.io.IOException;
import java.net.URL;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import static org.kohsuke.github.GitHub.MAPPER;
@@ -143,6 +144,34 @@ public class GHUser {
return getRepositories().get(name);
}
/**
* Follow this user.
*/
public void follow() throws IOException {
new Poster(root).withCredential().to(root.getApiURL("/user/follow/"+login));
}
/**
* Unfollow this user.
*/
public void unfollow() throws IOException {
new Poster(root).withCredential().to(root.getApiURL("/user/unfollow/"+login));
}
/**
* Lists the users that this user is following
*/
public Set<GHUser> getFollows() throws IOException {
return root.retrieve("/user/show/"+login+"/following",JsonUsers.class).toSet(root);
}
/**
* Lists the users who are following this user.
*/
public Set<GHUser> getFollowers() throws IOException {
return root.retrieve("/user/show/"+login+"/followers",JsonUsers.class).toSet(root);
}
@Override
public String toString() {
return "User:"+login;

View File

@@ -125,7 +125,6 @@ public class GitHub {
* Newly created repository.
*/
public GHRepository createRepository(String name, String description, String homepage, boolean isPublic) throws IOException {
requireCredential();
GHRepository r = new Poster(this).withCredential()
.with("name", name).with("description", description).with("homepage", homepage)
.with("public", isPublic ? 1 : 0).to(getApiURL("/repos/create"), JsonRepository.class).repository;

View File

@@ -0,0 +1,43 @@
/*
* 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;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @author Kohsuke Kawaguchi
*/
class JsonUsers {
public List<String> users;
public Set<GHUser> toSet(GitHub root) throws IOException {
Set<GHUser> r = new HashSet<GHUser>();
for (String u : users)
r.add(root.getUser(u));
return r;
}
}

View File

@@ -51,6 +51,7 @@ class Poster {
}
public Poster withCredential() {
root.requireCredential();
return with("login",root.login).with("token",root.token);
}