diff --git a/pom.xml b/pom.xml
index 93819aa2c5..4551c03abf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -97,6 +97,12 @@
1.5.3
true
+
+ org.kohsuke
+ wordnet-random-name
+ 1.2
+ test
+
diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java
index cb3346e4cf..f8c3598e72 100644
--- a/src/main/java/org/kohsuke/github/GHRepository.java
+++ b/src/main/java/org/kohsuke/github/GHRepository.java
@@ -153,7 +153,7 @@ public List getIssues(GHIssueState state) throws IOException {
public List getIssues(GHIssueState state, GHMilestone milestone) throws IOException {
return Arrays.asList(GHIssue.wrap(root.retrieve()
.to(String.format("/repos/%s/%s/issues?state=%s&milestone=%s", owner.login, name,
- state.toString().toLowerCase(), milestone == null ? "none" : "" + milestone.getNumber()),
+ state.toString().toLowerCase(), milestone == null ? "none" : "" + milestone.getNumber()),
GHIssue[].class
), this));
}
@@ -469,6 +469,29 @@ protected void wrapUp(GHPullRequest[] page) {
};
}
+ /**
+ * Creates a new pull request.
+ *
+ * @param title
+ * Required. The title of the pull request.
+ * @param head
+ * Required. The name of the branch where your changes are implemented.
+ * For cross-repository pull requests in the same network,
+ * namespace head with a user like this: username:branch.
+ * @param base
+ * Required. The name of the branch you want your changes pulled into.
+ * This should be an existing branch on the current repository.
+ * @param body
+ * The contents of the pull request. This is the markdown description
+ * of a pull request.
+ */
+ public GHPullRequest createPullRequest(String title, String head, String base, String body) throws IOException {
+ return new Requester(root).with("title",title)
+ .with("head",head)
+ .with("base",base)
+ .with("body",body).to(getApiTailUrl("pulls"),GHPullRequest.class).wrapUp(this);
+ }
+
/**
* Retrieves the currently configured hooks.
*/
@@ -498,7 +521,7 @@ public GHCompare getCompare(String id1, String id2) throws IOException {
}
public GHCompare getCompare(GHCommit id1, GHCommit id2) throws IOException {
- return getCompare(id1.getSHA1(),id2.getSHA1());
+ return getCompare(id1.getSHA1(), id2.getSHA1());
}
public GHCompare getCompare(GHBranch id1, GHBranch id2) throws IOException {
diff --git a/src/test/java/org/kohsuke/github/AbstractGitHubApiTestBase.java b/src/test/java/org/kohsuke/github/AbstractGitHubApiTestBase.java
index c52dcda461..e45895d66e 100644
--- a/src/test/java/org/kohsuke/github/AbstractGitHubApiTestBase.java
+++ b/src/test/java/org/kohsuke/github/AbstractGitHubApiTestBase.java
@@ -3,7 +3,7 @@
import org.apache.commons.io.IOUtils;
import org.junit.Assert;
import org.junit.Before;
-import org.kohsuke.github.GitHub;
+import org.kohsuke.randname.RandomNameGenerator;
import java.io.FileInputStream;
import java.util.Properties;
@@ -31,4 +31,6 @@ public void setUp() throws Exception {
gitHub = GitHub.connect();
}
}
+
+ protected static final RandomNameGenerator rnd = new RandomNameGenerator();
}
diff --git a/src/test/java/org/kohsuke/github/PullRequestTest.java b/src/test/java/org/kohsuke/github/PullRequestTest.java
new file mode 100644
index 0000000000..18f4a160f7
--- /dev/null
+++ b/src/test/java/org/kohsuke/github/PullRequestTest.java
@@ -0,0 +1,18 @@
+package org.kohsuke.github;
+
+import org.junit.Test;
+
+/**
+ * @author Kohsuke Kawaguchi
+ */
+public class PullRequestTest extends AbstractGitHubApiTestBase {
+ @Test
+ public void createPullRequest() throws Exception {
+ GHRepository j = gitHub.getOrganization("github-api-test-org").getRepository("jenkins");
+ String name = rnd.next();
+ GHPullRequest p = j.createPullRequest(name, "stable", "master", "## test");
+ System.out.println(p.getUrl());
+ assertEquals(name, p.getTitle());
+ p.close();
+ }
+}