From 15612e6bfd8b4aa17bc66b112b02d6a00d546cba Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 14 Dec 2010 09:54:23 -0800 Subject: [PATCH 1/9] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6298239952..ec7988f708 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.kohsuke github-api jar - 1.4 + 1.5-SNAPSHOT GitHub API for Java http://kohsuke.org/github-api/ GitHub API for Java From fa40b625cc26ee5b1479f5d5d3b308b4dd194def Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 14 Dec 2010 10:05:28 -0800 Subject: [PATCH 2/9] explicitly declare Wagon --- pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pom.xml b/pom.xml index ec7988f708..3e84d83e99 100644 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,11 @@ wagon-svn 1.9 + + org.apache.maven.wagon + wagon-ssh + 1.0-beta-7 + From 637950c8be5450744d7273347627157c9c50b5fc Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 16 Dec 2010 13:36:05 -0800 Subject: [PATCH 3/9] added a method to fork a repository into an organization. --- .../java/org/kohsuke/github/GHRepository.java | 33 ++++++++++++++++++- src/test/java/org/kohsuke/AppTest.java | 8 +++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index d07ab6029b..aba2feb183 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -23,7 +23,9 @@ */ package org.kohsuke.github; +import com.gargoylesoftware.htmlunit.ElementNotFoundException; import com.gargoylesoftware.htmlunit.WebClient; +import com.gargoylesoftware.htmlunit.html.HtmlButton; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlInput; import com.gargoylesoftware.htmlunit.html.HtmlPage; @@ -154,12 +156,41 @@ public void delete() throws IOException { } /** - * Forks this repository. + * Forks this repository as your repository. + * + * @return + * Newly forked repository that belong to you. */ public GHRepository fork() throws IOException { 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"); + } + + private void verifyMine() throws IOException { if (!root.login.equals(owner)) throw new IOException("Operation not applicable to a repository owned by someone else: "+owner); diff --git a/src/test/java/org/kohsuke/AppTest.java b/src/test/java/org/kohsuke/AppTest.java index a327c59b85..1fc20e1b62 100644 --- a/src/test/java/org/kohsuke/AppTest.java +++ b/src/test/java/org/kohsuke/AppTest.java @@ -22,6 +22,9 @@ public void testCredentialValid() throws IOException { public void testApp() throws IOException { GitHub gitHub = GitHub.connect(); + +// tryOrgFork(gitHub); + // testOrganization(gitHub); // testPostCommitHook(gitHub); @@ -42,6 +45,11 @@ public void testApp() throws IOException { // System.out.println(hub.getUser("kohsuke").getRepository("hudson").getCollaborators()); } + 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 { GHOrganization o = gitHub.getOrganization("HudsonLabs"); GHTeam t = o.createTeam("auto team", Permission.PUSH); From a827e51fa76cded6e96ecd1b772efd8d99c8ebb6 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 16 Dec 2010 15:21:54 -0800 Subject: [PATCH 4/9] added the rename support. --- .../java/org/kohsuke/github/GHRepository.java | 20 +++++++++++++++++++ src/test/java/org/kohsuke/AppTest.java | 5 +++++ 2 files changed, 25 insertions(+) diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index aba2feb183..421a7de1d3 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -190,6 +190,26 @@ public GHRepository forkTo(GHOrganization org) throws IOException { 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; + } 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 { if (!root.login.equals(owner)) diff --git a/src/test/java/org/kohsuke/AppTest.java b/src/test/java/org/kohsuke/AppTest.java index 1fc20e1b62..fb0fe81f1d 100644 --- a/src/test/java/org/kohsuke/AppTest.java +++ b/src/test/java/org/kohsuke/AppTest.java @@ -23,6 +23,7 @@ public void testCredentialValid() throws IOException { public void testApp() throws IOException { GitHub gitHub = GitHub.connect(); +// tryRenaming(gitHub); // tryOrgFork(gitHub); // testOrganization(gitHub); @@ -45,6 +46,10 @@ public void testApp() throws IOException { // 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()); From 13c9da9e91fb751942935dcd5fe07375fe8212c2 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 16 Dec 2010 15:31:29 -0800 Subject: [PATCH 5/9] missing the return statement --- src/main/java/org/kohsuke/github/GHRepository.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 421a7de1d3..603481a7ef 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -202,6 +202,7 @@ public void renameTo(String newName) throws IOException { f.getInputByName("name").setValueAttribute(newName); f.submit((HtmlButton)f.getElementsByTagName("button").get(0)); name = newName; + return; } catch (ElementNotFoundException e) { // continue } From d1cd06aec423216e4dbe63c4338e9b2446e83fc4 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Wed, 23 Feb 2011 06:47:22 +0900 Subject: [PATCH 6/9] incorporated the pagenation --- src/main/java/org/kohsuke/github/GHPerson.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHPerson.java b/src/main/java/org/kohsuke/github/GHPerson.java index 719fb978f2..027c4529c3 100644 --- a/src/main/java/org/kohsuke/github/GHPerson.java +++ b/src/main/java/org/kohsuke/github/GHPerson.java @@ -1,13 +1,10 @@ package org.kohsuke.github; import java.io.IOException; -import java.net.URL; import java.util.Collections; import java.util.Map; import java.util.TreeMap; -import static org.kohsuke.github.GitHub.*; - /** * Common part of {@link GHUser} and {@link GHOrganization}. * @@ -31,7 +28,11 @@ public abstract class GHPerson { public synchronized Map getRepositories() throws IOException { if (repositories==null) { repositories = Collections.synchronizedMap(new TreeMap()); - repositories.putAll(root.retrieve("/repos/show/" + login, JsonRepositories.class).wrap(root)); + for (int i=1; ; i++) { + Map map = root.retrieve("/repos/show/" + login + "?page=" + i, JsonRepositories.class).wrap(root); + repositories.putAll(map); + if (map.isEmpty()) break; + } } return Collections.unmodifiableMap(repositories); From 7c599393bf9e2c197fd2d527e431cffd25de617e Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Wed, 23 Feb 2011 06:58:14 +0900 Subject: [PATCH 7/9] added methods to parse timestamp --- .../java/org/kohsuke/github/GHRepository.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 603481a7ef..140c30c254 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -32,10 +32,13 @@ import java.io.IOException; import java.net.URL; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.AbstractSet; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Date; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -54,6 +57,7 @@ public class GHRepository { private String description, homepage, url, name, owner; private boolean has_issues, has_wiki, fork, _private, has_downloads; private int watchers,forks; + private String created_at, pushed_at; public String getDescription() { return description; @@ -110,6 +114,23 @@ public int getWatchers() { 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. * This set always appear to include the owner. @@ -321,4 +342,6 @@ private HtmlForm getForm() throws IOException { public String toString() { return "Repository:"+owner+":"+name; } + + private static final String TIME_FORMAT = "yyyy/MM/dd HH:mm:ss ZZZZ"; } From 7f82306908bfd0fc9a980ce6d4224289ba0f1520 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Wed, 23 Feb 2011 09:26:18 +0900 Subject: [PATCH 8/9] [maven-release-plugin] prepare release github-api-1.5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3e84d83e99..bcbe2cd2de 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.kohsuke github-api jar - 1.5-SNAPSHOT + 1.5 GitHub API for Java http://kohsuke.org/github-api/ GitHub API for Java From c0dff74536f20c6a536fd09875ccf2b5e7b6fbb9 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Wed, 23 Feb 2011 09:31:02 +0900 Subject: [PATCH 9/9] switched the Maven repository --- pom.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index bcbe2cd2de..3f8f786b1f 100644 --- a/pom.xml +++ b/pom.xml @@ -8,11 +8,11 @@ http://kohsuke.org/github-api/ GitHub API for Java - - - java.net-m2-repository - java-net:/maven2-repository/trunk/repository/ - + + + maven.jenkins-ci.org + http://maven.jenkins-ci.org:8081/content/repositories/releases/ + kohsuke.org scp://kohsuke.org/home/kohsuke/kohsuke.org/github-api/