From d91388aba4f6966938d15ad61076dd5afc8af4a3 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 10 Dec 2015 07:00:06 -0800 Subject: [PATCH 01/12] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 805080b06e..a81a8e0fe7 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ github-api - 1.72 + 1.73-SNAPSHOT GitHub API for Java http://github-api.kohsuke.org/ GitHub API for Java @@ -16,7 +16,7 @@ scm:git:git@github.com/kohsuke/${project.artifactId}.git scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git http://${project.artifactId}.kohsuke.org/ - github-api-1.72 + HEAD From ac39b564a83f3788501c0e3caac5566eab914efd Mon Sep 17 00:00:00 2001 From: Daniel Lovera Date: Sun, 13 Dec 2015 20:59:49 +0100 Subject: [PATCH 02/12] Support for auto_init parameter The GitHub api auto_init parameter allows to initialize created repository with a readme file. Add a createRepository method using auto_init parameter. Already existing createRepository method uses auto_init parameter as false for retro-compatibility. --- src/main/java/org/kohsuke/github/GitHub.java | 18 ++++++++++++++++-- src/test/java/org/kohsuke/github/AppTest.java | 12 ++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index b6ddd6e965..55d1bcac5f 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -417,9 +417,23 @@ public T parseEventPayload(Reader r, Class type) t * Newly created repository. */ public GHRepository createRepository(String name, String description, String homepage, boolean isPublic) throws IOException { + return createRepository(name, description, homepage, isPublic, false); + } + + /** + * Creates a new repository. + * + * To create a repository in an organization, see + * {@link GHOrganization#createRepository(String, String, String, GHTeam, boolean, boolean)} + * + * @return + * Newly created repository. + */ + public GHRepository createRepository(String name, String description, String homepage, boolean isPublic, boolean autoInit) throws IOException { Requester requester = new Requester(this) - .with("name", name).with("description", description).with("homepage", homepage) - .with("public", isPublic ? 1 : 0); + .with("name", name).with("description", description).with("homepage", homepage) + .with("public", isPublic ? 1 : 0) + .with("auto_init", autoInit); return requester.method("POST").to("/user/repos", GHRepository.class).wrap(this); } diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index 5d5e0a5fef..0ccd0d11c3 100755 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -38,6 +38,18 @@ public void testRepoCRUD() throws Exception { getUser().getRepository(targetName).delete(); } + @Test + public void testRepositoryWithAutoInitializationCRUD() throws IOException { + String name = "github-api-test-autoinit"; + deleteRepository(name); + GHRepository r = gitHub.createRepository(name, "a test repository for auto init", "http://github-api.kohsuke.org/", true, true); + r.enableIssueTracker(false); + r.enableDownloads(false); + r.enableWiki(false); + assertNotNull(r.getReadme()); + getUser().getRepository(name).delete(); + } + private void deleteRepository(final String name) throws IOException { GHRepository repository = getUser().getRepository(name); if(repository != null) { From c879e9e34d00c3d8f91ea04b028e028b86afff67 Mon Sep 17 00:00:00 2001 From: Daniel Lovera Date: Sun, 13 Dec 2015 21:00:40 +0100 Subject: [PATCH 03/12] Support for auto_init parameter in organization The GitHub api auto_init parameter allows to initialize created repository with a readme file. Add createRepository methods in GHOrganization using auto_init parameter. Already existing createRepository methods use auto_init parameter as false for retro-compatibility. --- .../org/kohsuke/github/GHOrganization.java | 16 ++++++--- .../kohsuke/github/GHOrganizationTest.java | 36 +++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 src/test/java/org/kohsuke/github/GHOrganizationTest.java diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index 83c8a0474a..9c4a42042f 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -26,19 +26,27 @@ public class GHOrganization extends GHPerson { * Newly created repository. */ public GHRepository createRepository(String name, String description, String homepage, String team, boolean isPublic) throws IOException { + return createRepository(name, description, homepage, team, isPublic, false); + } + + public GHRepository createRepository(String name, String description, String homepage, String team, boolean isPublic, boolean autoInit) throws IOException { GHTeam t = getTeams().get(team); if (t==null) throw new IllegalArgumentException("No such team: "+team); - return createRepository(name, description, homepage, t, isPublic); + return createRepository(name, description, homepage, t, isPublic, autoInit); } public GHRepository createRepository(String name, String description, String homepage, GHTeam team, boolean isPublic) throws IOException { + return createRepository(name, description, homepage, team, isPublic, false); + } + + public GHRepository createRepository(String name, String description, String homepage, GHTeam team, boolean isPublic, boolean autoInit) throws IOException { if (team==null) throw new IllegalArgumentException("Invalid team"); // such API doesn't exist, so fall back to HTML scraping return new Requester(root) - .with("name", name).with("description", description).with("homepage", homepage) - .with("public", isPublic).with("team_id",team.getId()).to("/orgs/"+login+"/repos", GHRepository.class).wrap(root); + .with("name", name).with("description", description).with("homepage", homepage) + .with("public", isPublic).with("auto_init", autoInit).with("team_id",team.getId()).to("/orgs/"+login+"/repos", GHRepository.class).wrap(root); } /** @@ -185,7 +193,7 @@ public GHTeam createTeam(String name, Permission p, Collection rep } public GHTeam createTeam(String name, Permission p, GHRepository... repositories) throws IOException { - return createTeam(name,p, Arrays.asList(repositories)); + return createTeam(name, p, Arrays.asList(repositories)); } /** diff --git a/src/test/java/org/kohsuke/github/GHOrganizationTest.java b/src/test/java/org/kohsuke/github/GHOrganizationTest.java new file mode 100644 index 0000000000..3f425f3fef --- /dev/null +++ b/src/test/java/org/kohsuke/github/GHOrganizationTest.java @@ -0,0 +1,36 @@ +package org.kohsuke.github; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; + +public class GHOrganizationTest extends AbstractGitHubApiTestBase { + + public static final String GITHUB_API_TEST_ORG = "github-api-test-org"; + public static final String GITHUB_API_TEST = "github-api-test"; + + @Test + public void testCreateRepository() throws IOException { + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + GHRepository repository = org.createRepository(GITHUB_API_TEST, + "a test repository used to test kohsuke's github-api", "http://github-api.kohsuke.org/", "Core Developers", true); + Assert.assertNotNull(repository); + } + + @Test + public void testCreateRepositoryWithAutoInitialization() throws IOException { + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + GHRepository repository = org.createRepository(GITHUB_API_TEST, + "a test repository used to test kohsuke's github-api", "http://github-api.kohsuke.org/", "Core Developers", true, true); + Assert.assertNotNull(repository); + Assert.assertNotNull(repository.getReadme()); + } + + @After + public void cleanUp() throws Exception { + GHRepository repository = gitHub.getOrganization(GITHUB_API_TEST_ORG).getRepository(GITHUB_API_TEST); + repository.delete(); + } +} From e94c36b7e6f4cb18d3403a05994a03b528584e2e Mon Sep 17 00:00:00 2001 From: Daniel Lovera Date: Sun, 13 Dec 2015 21:05:36 +0100 Subject: [PATCH 04/12] clean: remove unused import --- src/main/java/org/kohsuke/github/GHOrganization.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index 9c4a42042f..33daecd591 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -7,7 +7,6 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.TreeMap; From f573f83fb9232a8a8bbbdf185824529e9741c063 Mon Sep 17 00:00:00 2001 From: benbek Date: Tue, 19 Jan 2016 00:05:01 +0200 Subject: [PATCH 05/12] Amendment to the documentation The status reported by GitHub for deleting a file is actually "removed", not "deleted". --- src/main/java/org/kohsuke/github/GHCommit.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/GHCommit.java b/src/main/java/org/kohsuke/github/GHCommit.java index a350eeb535..031e15c315 100644 --- a/src/main/java/org/kohsuke/github/GHCommit.java +++ b/src/main/java/org/kohsuke/github/GHCommit.java @@ -102,7 +102,7 @@ public int getLinesDeleted() { } /** - * "modified", "added", or "deleted" + * "modified", "added", or "removed" */ public String getStatus() { return status; From 33d95d3e3a2ace95682a34f60f1e25e831541089 Mon Sep 17 00:00:00 2001 From: Daniel Beck Date: Wed, 20 Jan 2016 23:30:10 +0100 Subject: [PATCH 06/12] Fix error when creating email service hook --- src/main/java/org/kohsuke/github/GHRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index b024814625..fbd64709a6 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -475,7 +475,7 @@ private void modifyCollaborators(Collection users, String method) throws public void setEmailServiceHook(String address) throws IOException { Map config = new HashMap(); config.put("address", address); - new Requester(root).method("POST").with("name", "email").with("config", config).with("active", "true") + new Requester(root).method("POST").with("name", "email").with("config", config).with("active", true) .to(getApiTailUrl("hooks")); } From c0a05e06501bc162ec15afeaf364964646323cf5 Mon Sep 17 00:00:00 2001 From: Daniel Beck Date: Sun, 21 Feb 2016 01:26:43 +0100 Subject: [PATCH 07/12] Populate commit with data for getCommitShortInfo --- src/main/java/org/kohsuke/github/GHCommit.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/GHCommit.java b/src/main/java/org/kohsuke/github/GHCommit.java index a350eeb535..ee6131709e 100644 --- a/src/main/java/org/kohsuke/github/GHCommit.java +++ b/src/main/java/org/kohsuke/github/GHCommit.java @@ -178,7 +178,8 @@ static class User { User author,committer; - public ShortInfo getCommitShortInfo() { + public ShortInfo getCommitShortInfo() throws IOException { + populate(); return commit; } From f4b129b9f10928f05bd9cdb589fbcfe2d642206c Mon Sep 17 00:00:00 2001 From: Artem Gubanov Date: Thu, 25 Feb 2016 10:46:17 +0200 Subject: [PATCH 08/12] Added getHtmlUrl() to GHCommit --- src/main/java/org/kohsuke/github/GHCommit.java | 9 ++++++++- src/test/java/org/kohsuke/github/AppTest.java | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/GHCommit.java b/src/main/java/org/kohsuke/github/GHCommit.java index a350eeb535..c7825b88bc 100644 --- a/src/main/java/org/kohsuke/github/GHCommit.java +++ b/src/main/java/org/kohsuke/github/GHCommit.java @@ -171,7 +171,7 @@ static class User { String login; } - String url,sha; + String url,html_url,sha; List files; Stats stats; List parents; @@ -213,6 +213,13 @@ public int getLinesDeleted() throws IOException { return stats.deletions; } + /** + * URL of this commit like "https://github.com/kohsuke/sandbox-ant/commit/8ae38db0ea5837313ab5f39d43a6f73de3bd9000" + */ + public URL getHtmlUrl() { + return GitHub.parseURL(html_url); + } + /** * [0-9a-f]{40} SHA1 checksum. */ diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index 5d5e0a5fef..82952a7960 100755 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -326,6 +326,8 @@ public void testCommit() throws Exception { System.out.println(commit); assertEquals(1, commit.getParents().size()); assertEquals(1,commit.getFiles().size()); + assertEquals("https://github.com/jenkinsci/jenkins/commit/08c1c9970af4d609ae754fbe803e06186e3206f7", + commit.getHtmlUrl().toString()); File f = commit.getFiles().get(0); assertEquals(48,f.getLinesChanged()); From d80ad778710f17f60ecf86c11de4d3d46a551ff1 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Mon, 29 Feb 2016 19:57:16 -0800 Subject: [PATCH 09/12] Use builder pattern to support all the other options --- .../github/GHCreateRepositoryBuilder.java | 114 ++++++++++++++++++ .../org/kohsuke/github/GHOrganization.java | 32 +++-- src/main/java/org/kohsuke/github/GitHub.java | 27 ++--- src/test/java/org/kohsuke/github/AppTest.java | 5 +- .../kohsuke/github/GHOrganizationTest.java | 19 ++- 5 files changed, 162 insertions(+), 35 deletions(-) create mode 100644 src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java diff --git a/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java b/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java new file mode 100644 index 0000000000..492aaf5c81 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java @@ -0,0 +1,114 @@ +package org.kohsuke.github; + +import java.io.IOException; +import java.net.URL; + +/** + * Creates a repository + * + * @author Kohsuke Kawaguchi + */ +public class GHCreateRepositoryBuilder { + private final GitHub root; + protected final Requester builder; + private final String apiUrlTail; + + /*package*/ GHCreateRepositoryBuilder(GitHub root, String apiUrlTail, String name) { + this.root = root; + this.apiUrlTail = apiUrlTail; + this.builder = new Requester(root); + this.builder.with("name",name); + } + + public GHCreateRepositoryBuilder description(String description) { + this.builder.with("description",description); + return this; + } + + public GHCreateRepositoryBuilder homepage(URL homepage) { + return homepage(homepage.toExternalForm()); + } + + public GHCreateRepositoryBuilder homepage(String homepage) { + this.builder.with("homepage",homepage); + return this; + } + + /** + * Creates a private repository + */ + public GHCreateRepositoryBuilder private_(boolean b) { + this.builder.with("private",b); + return this; + } + + /** + * Enables issue tracker + */ + public GHCreateRepositoryBuilder issues(boolean b) { + this.builder.with("has_issues",b); + return this; + } + + /** + * Enables wiki + */ + public GHCreateRepositoryBuilder wiki(boolean b) { + this.builder.with("has_wiki",b); + return this; + } + + /** + * Enables downloads + */ + public GHCreateRepositoryBuilder downloads(boolean b) { + this.builder.with("has_downloads",b); + return this; + } + + /** + * If true, create an initial commit with empty README. + */ + public GHCreateRepositoryBuilder autoInit(boolean b) { + this.builder.with("auto_init",b); + return this; + } + + /** + * Creates a default .gitignore + * + * See https://developer.github.com/v3/repos/#create + */ + public GHCreateRepositoryBuilder gitignoreTemplate(String language) { + this.builder.with("gitignore_template",language); + return this; + } + + /** + * Desired license template to apply + * + * See https://developer.github.com/v3/repos/#create + */ + public GHCreateRepositoryBuilder licenseTemplate(String license) { + this.builder.with("license_template",license); + return this; + } + + /** + * The team that gets granted access to this repository. Only valid for creating a repository in + * an organization. + */ + public GHCreateRepositoryBuilder team(GHTeam team) { + if (team!=null) + this.builder.with("team_id",team.getId()); + return this; + } + + /** + * Creates a repository with all the parameters. + */ + public GHRepository create() throws IOException { + return builder.method("POST").to(apiUrlTail, GHRepository.class).wrap(root); + } + +} diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index 33daecd591..c4ae92e6db 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -23,29 +23,35 @@ public class GHOrganization extends GHPerson { * * @return * Newly created repository. + * @deprecated + * Use {@link #createRepository(String)} that uses a builder pattern to let you control every aspect. */ public GHRepository createRepository(String name, String description, String homepage, String team, boolean isPublic) throws IOException { - return createRepository(name, description, homepage, team, isPublic, false); - } - - public GHRepository createRepository(String name, String description, String homepage, String team, boolean isPublic, boolean autoInit) throws IOException { GHTeam t = getTeams().get(team); if (t==null) throw new IllegalArgumentException("No such team: "+team); - return createRepository(name, description, homepage, t, isPublic, autoInit); + return createRepository(name, description, homepage, t, isPublic); } + /** + * @deprecated + * Use {@link #createRepository(String)} that uses a builder pattern to let you control every aspect. + */ public GHRepository createRepository(String name, String description, String homepage, GHTeam team, boolean isPublic) throws IOException { - return createRepository(name, description, homepage, team, isPublic, false); - } - - public GHRepository createRepository(String name, String description, String homepage, GHTeam team, boolean isPublic, boolean autoInit) throws IOException { if (team==null) throw new IllegalArgumentException("Invalid team"); - // such API doesn't exist, so fall back to HTML scraping - return new Requester(root) - .with("name", name).with("description", description).with("homepage", homepage) - .with("public", isPublic).with("auto_init", autoInit).with("team_id",team.getId()).to("/orgs/"+login+"/repos", GHRepository.class).wrap(root); + return createRepository(name).description(description).homepage(homepage).private_(!isPublic).team(team).create(); + } + + /** + * Starts a builder that creates a new repository. + * + *

+ * You use the returned builder to set various properties, then call {@link GHCreateRepositoryBuilder#create()} + * to finally createa repository. + */ + public GHCreateRepositoryBuilder createRepository(String name) throws IOException { + return new GHCreateRepositoryBuilder(root,"/orgs/"+login+"/repos",name); } /** diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 55d1bcac5f..77d178800c 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -410,31 +410,28 @@ public T parseEventPayload(Reader r, Class type) t /** * Creates a new repository. * - * To create a repository in an organization, see - * {@link GHOrganization#createRepository(String, String, String, GHTeam, boolean)} - * * @return * Newly created repository. + * @deprecated + * Use {@link #createRepository(String)} that uses a builder pattern to let you control every aspect. */ public GHRepository createRepository(String name, String description, String homepage, boolean isPublic) throws IOException { - return createRepository(name, description, homepage, isPublic, false); + return createRepository(name).description(description).homepage(homepage).private_(!isPublic).create(); } /** - * Creates a new repository. + * Starts a builder that creates a new repository. * - * To create a repository in an organization, see - * {@link GHOrganization#createRepository(String, String, String, GHTeam, boolean, boolean)} + *

+ * You use the returned builder to set various properties, then call {@link GHCreateRepositoryBuilder#create()} + * to finally createa repository. * - * @return - * Newly created repository. + *

+ * To create a repository in an organization, see + * {@link GHOrganization#createRepository(String, String, String, GHTeam, boolean)} */ - public GHRepository createRepository(String name, String description, String homepage, boolean isPublic, boolean autoInit) throws IOException { - Requester requester = new Requester(this) - .with("name", name).with("description", description).with("homepage", homepage) - .with("public", isPublic ? 1 : 0) - .with("auto_init", autoInit); - return requester.method("POST").to("/user/repos", GHRepository.class).wrap(this); + public GHCreateRepositoryBuilder createRepository(String name) { + return new GHCreateRepositoryBuilder(this,"/user/repos",name); } /** diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index 0ccd0d11c3..c3a7d6a437 100755 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -42,7 +42,10 @@ public void testRepoCRUD() throws Exception { public void testRepositoryWithAutoInitializationCRUD() throws IOException { String name = "github-api-test-autoinit"; deleteRepository(name); - GHRepository r = gitHub.createRepository(name, "a test repository for auto init", "http://github-api.kohsuke.org/", true, true); + GHRepository r = gitHub.createRepository(name) + .description("a test repository for auto init") + .homepage("http://github-api.kohsuke.org/") + .autoInit(true).create(); r.enableIssueTracker(false); r.enableDownloads(false); r.enableWiki(false); diff --git a/src/test/java/org/kohsuke/github/GHOrganizationTest.java b/src/test/java/org/kohsuke/github/GHOrganizationTest.java index 3f425f3fef..a1c5d3b921 100644 --- a/src/test/java/org/kohsuke/github/GHOrganizationTest.java +++ b/src/test/java/org/kohsuke/github/GHOrganizationTest.java @@ -8,12 +8,17 @@ public class GHOrganizationTest extends AbstractGitHubApiTestBase { - public static final String GITHUB_API_TEST_ORG = "github-api-test-org"; public static final String GITHUB_API_TEST = "github-api-test"; + private GHOrganization org; + + @Override + public void setUp() throws Exception { + super.setUp(); + org = gitHub.getOrganization("github-api-test-org"); + } @Test public void testCreateRepository() throws IOException { - GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); GHRepository repository = org.createRepository(GITHUB_API_TEST, "a test repository used to test kohsuke's github-api", "http://github-api.kohsuke.org/", "Core Developers", true); Assert.assertNotNull(repository); @@ -21,16 +26,18 @@ public void testCreateRepository() throws IOException { @Test public void testCreateRepositoryWithAutoInitialization() throws IOException { - GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); - GHRepository repository = org.createRepository(GITHUB_API_TEST, - "a test repository used to test kohsuke's github-api", "http://github-api.kohsuke.org/", "Core Developers", true, true); + GHRepository repository = org.createRepository(GITHUB_API_TEST) + .description("a test repository used to test kohsuke's github-api") + .homepage("http://github-api.kohsuke.org/") + .team(org.getTeamByName("Core Developers")) + .autoInit(true).create(); Assert.assertNotNull(repository); Assert.assertNotNull(repository.getReadme()); } @After public void cleanUp() throws Exception { - GHRepository repository = gitHub.getOrganization(GITHUB_API_TEST_ORG).getRepository(GITHUB_API_TEST); + GHRepository repository = org.getRepository(GITHUB_API_TEST); repository.delete(); } } From 14f7198a07fc5365eafbd708388bf0e6f6a8d971 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Mon, 29 Feb 2016 20:56:28 -0800 Subject: [PATCH 10/12] Handle "all" webhook correctly This fixes #250 --- src/main/java/org/kohsuke/github/GHEvent.java | 17 ++++++++++++++++- src/main/java/org/kohsuke/github/GHHook.java | 6 ++++-- src/main/java/org/kohsuke/github/GHHooks.java | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHEvent.java b/src/main/java/org/kohsuke/github/GHEvent.java index 9e172146ae..e8e79bb456 100644 --- a/src/main/java/org/kohsuke/github/GHEvent.java +++ b/src/main/java/org/kohsuke/github/GHEvent.java @@ -1,5 +1,7 @@ package org.kohsuke.github; +import java.util.Locale; + /** * Hook event type. * @@ -33,5 +35,18 @@ public enum GHEvent { STATUS, TEAM_ADD, WATCH, - PING + PING, + /** + * Special event type that means "every possible event" + */ + ALL; + + + /** + * Returns GitHub's internal representation of this event. + */ + String symbol() { + if (this==ALL) return "*"; + return name().toLowerCase(Locale.ENGLISH); + } } diff --git a/src/main/java/org/kohsuke/github/GHHook.java b/src/main/java/org/kohsuke/github/GHHook.java index 7d63f9d950..73b2eb4364 100644 --- a/src/main/java/org/kohsuke/github/GHHook.java +++ b/src/main/java/org/kohsuke/github/GHHook.java @@ -26,8 +26,10 @@ public String getName() { public EnumSet getEvents() { EnumSet s = EnumSet.noneOf(GHEvent.class); - for (String e : events) - s.add(Enum.valueOf(GHEvent.class,e.toUpperCase(Locale.ENGLISH))); + for (String e : events) { + if (e.equals("*")) s.add(GHEvent.ALL); + else s.add(Enum.valueOf(GHEvent.class, e.toUpperCase(Locale.ENGLISH))); + } return s; } diff --git a/src/main/java/org/kohsuke/github/GHHooks.java b/src/main/java/org/kohsuke/github/GHHooks.java index 4ee939c5a8..6f64587b17 100644 --- a/src/main/java/org/kohsuke/github/GHHooks.java +++ b/src/main/java/org/kohsuke/github/GHHooks.java @@ -39,7 +39,7 @@ public GHHook createHook(String name, Map config, Collection(); for (GHEvent e : events) - ea.add(e.name().toLowerCase(Locale.ENGLISH)); + ea.add(e.symbol()); } GHHook hook = new Requester(root) From 751043bf81a5e3afe3ac15300ca198c5d6a220a4 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Mon, 29 Feb 2016 21:01:18 -0800 Subject: [PATCH 11/12] change in the markup generated --- src/test/java/org/kohsuke/github/AppTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index f9fb4c95b3..c8d523cd81 100755 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -791,7 +791,7 @@ public void markDown() throws Exception { assertTrue(actual.contains("href=\"https://github.com/kohsuke\"")); assertTrue(actual.contains("href=\"https://github.com/kohsuke/github-api/pull/1\"")); assertTrue(actual.contains("class=\"user-mention\"")); - assertTrue(actual.contains("class=\"issue-link\"")); + assertTrue(actual.contains("class=\"issue-link ")); assertTrue(actual.contains("to fix issue")); } From 013eaa30b64a33c70231844e1c52fdbfcd630d27 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Mon, 29 Feb 2016 21:03:31 -0800 Subject: [PATCH 12/12] [maven-release-plugin] prepare release github-api-1.73 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index a81a8e0fe7..05d286b718 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ github-api - 1.73-SNAPSHOT + 1.73 GitHub API for Java http://github-api.kohsuke.org/ GitHub API for Java @@ -16,7 +16,7 @@ scm:git:git@github.com/kohsuke/${project.artifactId}.git scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git http://${project.artifactId}.kohsuke.org/ - HEAD + github-api-1.73