Skip to content

Commit ecbfdd7

Browse files
committed
initial version
0 parents  commit ecbfdd7

12 files changed

Lines changed: 810 additions & 0 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
target
2+
*.iml
3+
*.ipr
4+
*.iws

pom.xml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.kohsuke</groupId>
5+
<artifactId>github-api</artifactId>
6+
<packaging>jar</packaging>
7+
<version>1.0-SNAPSHOT</version>
8+
<name>GitHub API for Java</name>
9+
<url>http://kohsuke.org/github-api/</url>
10+
<description>GitHub API for Java</description>
11+
12+
<distributionManagement>
13+
<repository>
14+
<id>java.net-m2-repository</id>
15+
<url>java-net:/maven2-repository/trunk/repository/</url>
16+
</repository>
17+
<site>
18+
<id>kohsuke.org</id>
19+
<url>scp://kohsuke.org/home/kohsuke/kohsuke.org/github-api/</url>
20+
</site>
21+
</distributionManagement>
22+
23+
<build>
24+
<plugins>
25+
<plugin>
26+
<artifactId>maven-compiler-plugin</artifactId>
27+
<configuration>
28+
<source>1.5</source>
29+
<target>1.5</target>
30+
</configuration>
31+
</plugin>
32+
<plugin>
33+
<groupId>org.apache.maven.plugins</groupId>
34+
<artifactId>maven-release-plugin</artifactId>
35+
<version>2.0</version>
36+
<dependencies>
37+
<dependency>
38+
<groupId>org.apache.maven.scm</groupId>
39+
<artifactId>maven-scm-provider-gitexe</artifactId>
40+
<version>1.2</version>
41+
</dependency>
42+
</dependencies>
43+
</plugin>
44+
<plugin>
45+
<groupId>org.apache.maven.plugins</groupId>
46+
<artifactId>maven-scm-plugin</artifactId>
47+
<version>1.3</version>
48+
</plugin>
49+
</plugins>
50+
<extensions>
51+
<extension>
52+
<groupId>org.jvnet.wagon-svn</groupId>
53+
<artifactId>wagon-svn</artifactId>
54+
<version>1.9</version>
55+
</extension>
56+
</extensions>
57+
</build>
58+
59+
<scm>
60+
<connection>scm:git:[email protected]:kohsuke/github-api.git</connection>
61+
</scm>
62+
63+
<developers>
64+
<developer>
65+
<id>kohsuke</id>
66+
<name>Kohsuke Kawaguchi</name>
67+
</developer>
68+
</developers>
69+
70+
<licenses>
71+
<license>
72+
<name>MIT License</name>
73+
<distribution>repository</distribution>
74+
<url>http://www.opensource.org/licenses/mit-license.php</url>
75+
</license>
76+
</licenses>
77+
78+
<dependencies>
79+
<dependency>
80+
<groupId>junit</groupId>
81+
<artifactId>junit</artifactId>
82+
<version>3.8.1</version>
83+
<scope>test</scope>
84+
</dependency>
85+
<dependency>
86+
<groupId>org.codehaus.jackson</groupId>
87+
<artifactId>jackson-mapper-asl</artifactId>
88+
<version>1.5.0</version>
89+
</dependency>
90+
<dependency>
91+
<groupId>commons-io</groupId>
92+
<artifactId>commons-io</artifactId>
93+
<version>1.4</version>
94+
</dependency>
95+
</dependencies>
96+
</project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2010, Kohsuke Kawaguchi
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
package org.kohsuke.github;
25+
26+
/**
27+
* @author Kohsuke Kawaguchi
28+
*/
29+
class DeleteToken {
30+
public String delete_token;
31+
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2010, Kohsuke Kawaguchi
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
package org.kohsuke.github;
25+
26+
import java.io.IOException;
27+
import java.net.URL;
28+
import java.util.Collection;
29+
import java.util.Collections;
30+
import java.util.HashSet;
31+
import java.util.Set;
32+
33+
import static java.util.Arrays.asList;
34+
35+
/**
36+
* @author Kohsuke Kawaguchi
37+
*/
38+
public class GHRepository {
39+
/*package almost final*/ GitHub root;
40+
41+
private String description, homepage, url, name, owner;
42+
private boolean has_issues, has_wiki, fork, _private, has_downloads;
43+
private int watchers,forks;
44+
45+
public String getDescription() {
46+
return description;
47+
}
48+
49+
public String getHomepage() {
50+
return homepage;
51+
}
52+
53+
public String getUrl() {
54+
return url;
55+
}
56+
57+
public String getName() {
58+
return name;
59+
}
60+
61+
public GHUser getOwner() throws IOException {
62+
return root.getUser(owner);
63+
}
64+
65+
public boolean hasIssues() {
66+
return has_issues;
67+
}
68+
69+
public boolean hasWiki() {
70+
return has_wiki;
71+
}
72+
73+
public boolean isFork() {
74+
return fork;
75+
}
76+
77+
public int getForks() {
78+
return forks;
79+
}
80+
81+
public boolean isPrivate() {
82+
return _private;
83+
}
84+
85+
public boolean hasDownloads() {
86+
return has_downloads;
87+
}
88+
89+
public int getWatchers() {
90+
return watchers;
91+
}
92+
93+
/**
94+
* Gets the collaborators on this repository.
95+
* This set always appear to include the owner.
96+
*/
97+
public Set<GHUser> getCollaborators() throws IOException {
98+
Set<GHUser> r = new HashSet<GHUser>();
99+
for (String u : root.retrieve("/repos/show/"+owner+"/"+name+"/collaborators",JsonCollaborators.class).collaborators)
100+
r.add(root.getUser(u));
101+
return Collections.unmodifiableSet(r);
102+
}
103+
104+
public void addCollaborators(GHUser... users) throws IOException {
105+
addCollaborators(asList(users));
106+
}
107+
108+
public void addCollaborators(Collection<GHUser> users) throws IOException {
109+
modifyCollaborators(users, "/add/");
110+
}
111+
112+
public void removeCollaborators(GHUser... users) throws IOException {
113+
removeCollaborators(asList(users));
114+
}
115+
116+
public void removeCollaborators(Collection<GHUser> users) throws IOException {
117+
modifyCollaborators(users, "/remove/");
118+
}
119+
120+
private void modifyCollaborators(Collection<GHUser> users, String op) throws IOException {
121+
root.requireCredential();
122+
verifyMine();
123+
for (GHUser user : users) {
124+
new Poster(root).withCredential().to(root.getApiURL("/repos/collaborators/"+name+ op +user.getLogin()));
125+
}
126+
}
127+
128+
/**
129+
* Deletes this repository.
130+
*/
131+
public void delete() throws IOException {
132+
root.requireCredential();
133+
verifyMine();
134+
Poster poster = new Poster(root).withCredential();
135+
URL url = root.getApiURL("/repos/delete/" + name);
136+
137+
DeleteToken token = poster.to(url, DeleteToken.class);
138+
poster.with("delete_token",token.delete_token).to(url);
139+
}
140+
141+
private void verifyMine() throws IOException {
142+
if (!root.login.equals(owner))
143+
throw new IOException("Operation not applicable to a repository owned by someone else: "+owner);
144+
}
145+
146+
@Override
147+
public String toString() {
148+
return "Repository:"+owner+":"+name;
149+
}
150+
}

0 commit comments

Comments
 (0)