mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-11 08:21:23 +00:00
Compare commits
7 Commits
github-api
...
github-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3080313aef | ||
|
|
0ddac59c9c | ||
|
|
131caf04e5 | ||
|
|
6c3884b94d | ||
|
|
540d473e42 | ||
|
|
db717c86bb | ||
|
|
4f9cace3fe |
2
pom.xml
2
pom.xml
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
43
src/main/java/org/kohsuke/github/JsonUsers.java
Normal file
43
src/main/java/org/kohsuke/github/JsonUsers.java
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,7 @@ class Poster {
|
||||
}
|
||||
|
||||
public Poster withCredential() {
|
||||
root.requireCredential();
|
||||
return with("login",root.login).with("token",root.token);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user