diff --git a/Octokit.Tests.Integration/Clients/PullRequestsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestsClientTests.cs
index c3f0ac4d..0b01c085 100644
--- a/Octokit.Tests.Integration/Clients/PullRequestsClientTests.cs
+++ b/Octokit.Tests.Integration/Clients/PullRequestsClientTests.cs
@@ -49,6 +49,18 @@ public class PullRequestsClientTests : IDisposable
Assert.True(result.Draft);
}
+ [IntegrationTest]
+ public async Task CanCreateFromIssue()
+ {
+ await CreateTheWorld();
+
+ var newIssue = await _github.Issue.Create(Helper.UserName, _context.RepositoryName, new NewIssue("an issue"));
+ var newPullRequest = new NewPullRequest(newIssue.Number, branchName, "master");
+ var result = await _fixture.Create(Helper.UserName, _context.RepositoryName, newPullRequest);
+ Assert.Equal(newIssue.Number, result.Number);
+ Assert.Equal(newIssue.Title, result.Title);
+ }
+
[IntegrationTest]
public async Task CanCreateWithRepositoryId()
{
@@ -70,6 +82,18 @@ public class PullRequestsClientTests : IDisposable
Assert.True(result.Draft);
}
+ [IntegrationTest]
+ public async Task CanCreateFromIssueWithRepositoryId()
+ {
+ await CreateTheWorld();
+
+ var newIssue = await _github.Issue.Create(_context.RepositoryId, new NewIssue("an issue"));
+ var newPullRequest = new NewPullRequest(newIssue.Number, branchName, "master");
+ var result = await _fixture.Create(_context.Repository.Id, newPullRequest);
+ Assert.Equal(newIssue.Number, result.Number);
+ Assert.Equal(newIssue.Title, result.Title);
+ }
+
[IntegrationTest]
public async Task CanGetForRepository()
{
diff --git a/Octokit/Models/Request/NewPullRequest.cs b/Octokit/Models/Request/NewPullRequest.cs
index d2dd5821..cdd5f7ec 100644
--- a/Octokit/Models/Request/NewPullRequest.cs
+++ b/Octokit/Models/Request/NewPullRequest.cs
@@ -27,10 +27,31 @@ namespace Octokit
}
///
- /// Title of the pull request (required)
+ /// Initializes a new instance of the class.
+ ///
+ /// The number of an existing issue to convert into a pull request.
+ /// The branch (or git ref where your changes are implemented. In other words, the source branch/ref
+ /// The base (or git ref) reference you want your changes pulled into. In other words, the target branch/ref
+ public NewPullRequest(int issueId, string head, string baseRef)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(head, nameof(head));
+ Ensure.ArgumentNotNullOrEmptyString(baseRef, nameof(baseRef));
+
+ IssueId = issueId;
+ Head = head;
+ Base = baseRef;
+ }
+
+ ///
+ /// Title of the pull request (required if not provided).
///
public string Title { get; private set; }
+ ///
+ /// The number of an existing issue to convert into a pull request (required if not provided).
+ ///
+ public int? IssueId { get; private set; }
+
///
/// The branch (or git ref) you want your changes pulled into (required).
///
@@ -60,7 +81,14 @@ namespace Octokit
{
get
{
- return string.Format(CultureInfo.InvariantCulture, "Title: {0}", Title);
+ if (Title == null)
+ {
+ return string.Format(CultureInfo.InvariantCulture, "Title: {0}", Title);
+ }
+ else
+ {
+ return string.Format(CultureInfo.InvariantCulture, "From Issue: {0}", IssueId);
+ }
}
}
}