mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-13 00:11:22 +00:00
Compare commits
15 Commits
github-api
...
github-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
275b55f674 | ||
|
|
d3a18d234f | ||
|
|
878468820b | ||
|
|
6c9ebd1b5f | ||
|
|
985a11d896 | ||
|
|
c0dff74536 | ||
|
|
c6712ed6d5 | ||
|
|
7f82306908 | ||
|
|
7c599393bf | ||
|
|
d1cd06aec4 | ||
|
|
13c9da9e91 | ||
|
|
a827e51fa7 | ||
|
|
637950c8be | ||
|
|
fa40b625cc | ||
|
|
15612e6bfd |
43
pom.xml
43
pom.xml
@@ -3,22 +3,48 @@
|
|||||||
<groupId>org.kohsuke</groupId>
|
<groupId>org.kohsuke</groupId>
|
||||||
<artifactId>github-api</artifactId>
|
<artifactId>github-api</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>1.4</version>
|
<version>1.6</version>
|
||||||
<name>GitHub API for Java</name>
|
<name>GitHub API for Java</name>
|
||||||
<url>http://kohsuke.org/github-api/</url>
|
<url>http://kohsuke.org/github-api/</url>
|
||||||
<description>GitHub API for Java</description>
|
<description>GitHub API for Java</description>
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<repository>
|
<repository>
|
||||||
<id>java.net-m2-repository</id>
|
<id>maven.jenkins-ci.org</id>
|
||||||
<url>java-net:/maven2-repository/trunk/repository/</url>
|
<url>http://maven.jenkins-ci.org:8081/content/repositories/releases/</url>
|
||||||
</repository>
|
</repository>
|
||||||
<site>
|
<site>
|
||||||
<id>kohsuke.org</id>
|
<id>kohsuke.org</id>
|
||||||
<url>scp://kohsuke.org/home/kohsuke/kohsuke.org/github-api/</url>
|
<url>scp://kohsuke.org/home/kohsuke/kohsuke.org/github-api/</url>
|
||||||
</site>
|
</site>
|
||||||
</distributionManagement>
|
</distributionManagement>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>m.g.o-public</id>
|
||||||
|
<url>http://maven.glassfish.org/content/groups/public/</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<pluginRepositories>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>m.g.o-public</id>
|
||||||
|
<url>http://maven.glassfish.org/content/groups/public/</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</pluginRepository>
|
||||||
|
</pluginRepositories>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
@@ -52,6 +78,11 @@
|
|||||||
<artifactId>wagon-svn</artifactId>
|
<artifactId>wagon-svn</artifactId>
|
||||||
<version>1.9</version>
|
<version>1.9</version>
|
||||||
</extension>
|
</extension>
|
||||||
|
<extension>
|
||||||
|
<groupId>org.apache.maven.wagon</groupId>
|
||||||
|
<artifactId>wagon-ssh</artifactId>
|
||||||
|
<version>1.0-beta-7</version>
|
||||||
|
</extension>
|
||||||
</extensions>
|
</extensions>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import static org.kohsuke.github.GitHub.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common part of {@link GHUser} and {@link GHOrganization}.
|
* Common part of {@link GHUser} and {@link GHOrganization}.
|
||||||
*
|
*
|
||||||
@@ -31,7 +28,11 @@ public abstract class GHPerson {
|
|||||||
public synchronized Map<String,GHRepository> getRepositories() throws IOException {
|
public synchronized Map<String,GHRepository> getRepositories() throws IOException {
|
||||||
if (repositories==null) {
|
if (repositories==null) {
|
||||||
repositories = Collections.synchronizedMap(new TreeMap<String, GHRepository>());
|
repositories = Collections.synchronizedMap(new TreeMap<String, GHRepository>());
|
||||||
repositories.putAll(root.retrieve("/repos/show/" + login, JsonRepositories.class).wrap(root));
|
for (int i=1; ; i++) {
|
||||||
|
Map<String, GHRepository> map = root.retrieve("/repos/show/" + login + "?page=" + i, JsonRepositories.class).wrap(root);
|
||||||
|
repositories.putAll(map);
|
||||||
|
if (map.isEmpty()) break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Collections.unmodifiableMap(repositories);
|
return Collections.unmodifiableMap(repositories);
|
||||||
|
|||||||
@@ -23,17 +23,24 @@
|
|||||||
*/
|
*/
|
||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import com.gargoylesoftware.htmlunit.ElementNotFoundException;
|
||||||
import com.gargoylesoftware.htmlunit.WebClient;
|
import com.gargoylesoftware.htmlunit.WebClient;
|
||||||
|
import com.gargoylesoftware.htmlunit.html.HtmlButton;
|
||||||
|
import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
|
||||||
|
import com.gargoylesoftware.htmlunit.html.HtmlElement;
|
||||||
import com.gargoylesoftware.htmlunit.html.HtmlForm;
|
import com.gargoylesoftware.htmlunit.html.HtmlForm;
|
||||||
import com.gargoylesoftware.htmlunit.html.HtmlInput;
|
import com.gargoylesoftware.htmlunit.html.HtmlInput;
|
||||||
import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.AbstractSet;
|
import java.util.AbstractSet;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -52,6 +59,7 @@ public class GHRepository {
|
|||||||
private String description, homepage, url, name, owner;
|
private String description, homepage, url, name, owner;
|
||||||
private boolean has_issues, has_wiki, fork, _private, has_downloads;
|
private boolean has_issues, has_wiki, fork, _private, has_downloads;
|
||||||
private int watchers,forks;
|
private int watchers,forks;
|
||||||
|
private String created_at, pushed_at;
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
@@ -108,6 +116,23 @@ public class GHRepository {
|
|||||||
return watchers;
|
return watchers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Date getPushedAt() {
|
||||||
|
return parseDate(pushed_at);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreatedAt() {
|
||||||
|
return parseDate(created_at);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Date parseDate(String timestamp) {
|
||||||
|
try {
|
||||||
|
return new SimpleDateFormat(TIME_FORMAT).parse(timestamp);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
throw new IllegalStateException("Unable to parse the timestamp: "+pushed_at);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the collaborators on this repository.
|
* Gets the collaborators on this repository.
|
||||||
* This set always appear to include the owner.
|
* This set always appear to include the owner.
|
||||||
@@ -142,6 +167,18 @@ public class GHRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setEmailServiceHook(String address) throws IOException {
|
||||||
|
WebClient wc = root.createWebClient();
|
||||||
|
HtmlPage pg = (HtmlPage)wc.getPage(getUrl()+"/admin");
|
||||||
|
HtmlInput email = (HtmlInput)pg.getElementById("Email_address");
|
||||||
|
email.setValueAttribute(address);
|
||||||
|
HtmlCheckBoxInput active = (HtmlCheckBoxInput)pg.getElementById("Email[active]");
|
||||||
|
active.setChecked(true);
|
||||||
|
|
||||||
|
final HtmlForm f = email.getEnclosingFormOrDie();
|
||||||
|
f.submit((HtmlButton)f.getElementsByTagName("button").get(0));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes this repository.
|
* Deletes this repository.
|
||||||
*/
|
*/
|
||||||
@@ -154,12 +191,62 @@ public class GHRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forks this repository.
|
* Forks this repository as your repository.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* Newly forked repository that belong to you.
|
||||||
*/
|
*/
|
||||||
public GHRepository fork() throws IOException {
|
public GHRepository fork() throws IOException {
|
||||||
return new Poster(root).withCredential().to("/repos/fork/" + owner + "/" + name, JsonRepository.class).wrap(root);
|
return new Poster(root).withCredential().to("/repos/fork/" + owner + "/" + name, JsonRepository.class).wrap(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forks this repository into an organization.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* Newly forked repository that belong to you.
|
||||||
|
*/
|
||||||
|
public GHRepository forkTo(GHOrganization org) throws IOException {
|
||||||
|
WebClient wc = root.createWebClient();
|
||||||
|
HtmlPage pg = (HtmlPage)wc.getPage(getUrl());
|
||||||
|
for (HtmlForm f : pg.getForms()) {
|
||||||
|
if (!f.getActionAttribute().endsWith("/fork")) continue;
|
||||||
|
try {
|
||||||
|
if (org.getLogin().equals(f.getInputByName("organization").getValueAttribute())) {
|
||||||
|
// found it
|
||||||
|
f.submit((HtmlButton)f.getElementsByTagName("button").get(0));
|
||||||
|
return org.refreshRepository(name);
|
||||||
|
}
|
||||||
|
} catch (ElementNotFoundException e) {
|
||||||
|
// continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new IllegalArgumentException("Either you don't have the privilege to fork into "+org.getLogin()+" or there's a bug in HTML scraping");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rename this repository.
|
||||||
|
*/
|
||||||
|
public void renameTo(String newName) throws IOException {
|
||||||
|
WebClient wc = root.createWebClient();
|
||||||
|
HtmlPage pg = (HtmlPage)wc.getPage(getUrl()+"/admin");
|
||||||
|
for (HtmlForm f : pg.getForms()) {
|
||||||
|
if (!f.getActionAttribute().endsWith("/rename")) continue;
|
||||||
|
try {
|
||||||
|
f.getInputByName("name").setValueAttribute(newName);
|
||||||
|
f.submit((HtmlButton)f.getElementsByTagName("button").get(0));
|
||||||
|
name = newName;
|
||||||
|
return;
|
||||||
|
} catch (ElementNotFoundException e) {
|
||||||
|
// continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new IllegalArgumentException("Either you don't have the privilege to rename "+owner+'/'+name+" or there's a bug in HTML scraping");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void verifyMine() throws IOException {
|
private void verifyMine() throws IOException {
|
||||||
if (!root.login.equals(owner))
|
if (!root.login.equals(owner))
|
||||||
throw new IOException("Operation not applicable to a repository owned by someone else: "+owner);
|
throw new IOException("Operation not applicable to a repository owned by someone else: "+owner);
|
||||||
@@ -269,4 +356,6 @@ public class GHRepository {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return "Repository:"+owner+":"+name;
|
return "Repository:"+owner+":"+name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final String TIME_FORMAT = "yyyy/MM/dd HH:mm:ss ZZZZ";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,12 @@ public class AppTest extends TestCase {
|
|||||||
|
|
||||||
public void testApp() throws IOException {
|
public void testApp() throws IOException {
|
||||||
GitHub gitHub = GitHub.connect();
|
GitHub gitHub = GitHub.connect();
|
||||||
|
|
||||||
|
// gitHub.getMyself().getRepository("perforce-plugin").setEmailServiceHook("kk@kohsuke.org");
|
||||||
|
|
||||||
|
// tryRenaming(gitHub);
|
||||||
|
// tryOrgFork(gitHub);
|
||||||
|
|
||||||
// testOrganization(gitHub);
|
// testOrganization(gitHub);
|
||||||
// testPostCommitHook(gitHub);
|
// testPostCommitHook(gitHub);
|
||||||
|
|
||||||
@@ -42,6 +48,15 @@ public class AppTest extends TestCase {
|
|||||||
// System.out.println(hub.getUser("kohsuke").getRepository("hudson").getCollaborators());
|
// System.out.println(hub.getUser("kohsuke").getRepository("hudson").getCollaborators());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void tryRenaming(GitHub gitHub) throws IOException {
|
||||||
|
gitHub.getUser("kohsuke").getRepository("test").renameTo("test2");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tryOrgFork(GitHub gitHub) throws IOException {
|
||||||
|
GHOrganization o = gitHub.getOrganization("HudsonLabs");
|
||||||
|
System.out.println(gitHub.getUser("rtyler").getRepository("memcache-ada").forkTo(o).getUrl());
|
||||||
|
}
|
||||||
|
|
||||||
private void tryTeamCreation(GitHub gitHub) throws IOException {
|
private void tryTeamCreation(GitHub gitHub) throws IOException {
|
||||||
GHOrganization o = gitHub.getOrganization("HudsonLabs");
|
GHOrganization o = gitHub.getOrganization("HudsonLabs");
|
||||||
GHTeam t = o.createTeam("auto team", Permission.PUSH);
|
GHTeam t = o.createTeam("auto team", Permission.PUSH);
|
||||||
|
|||||||
Reference in New Issue
Block a user