Repository: google/go-github
Pull request #737 (2017-09-30 22:19:47)

github: add IsPullRequest helper (resubmit)
Re-submit of #679.

Changes in a761d22 is in reference to https://github.com/google/go-github/pull/679#discussion_r130531558.

googlebot: So there's good news and bad news.

:thumbsup: The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so.  Everything is all good there.

:confused: The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter.  We need to confirm that they're okay with their commits being contributed to this project.  Please have them confirm that here in the pull request.

*Note to project maintainer: This is a terminal state, meaning the `cla/google` commit status will not change from this State. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.*

<!-- need_author_consent -->
e-beach:  I'd consider @kevinburke's submission of this code as consent to it being used.
kevinburke: Go for it, sorry, I may have time next week but go for it

On Sat, Sep 30, 2017 at 18:26 Elliott Beach <notifications@github.com>
wrote:

> I'd consider @kevinburke <https://github.com/kevinburke>'s submission of
> this code as consent to it being used.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/google/go-github/pull/737#issuecomment-333340059>, or mute
> the thread
> <https://github.com/notifications/unsubscribe-auth/AAOSI_YgASur8WchmWhsEpIRqqdDl3YAks5snsAcgaJpZM4PptlG>
> .
>
-- 

--
Kevin Burke
925.271.7005 | kev.inburke.com

shurcooL: (I checked that the CLAs are signed and we have consent of everyone who contributed to this PR.)
shurcooL: Sorry about posting incorrect information about CLAs above; I was relying on @googlebot which did not report accurate information in this case.

Perhaps worth pointing out, since this is a really small change, I expect us to merge this PR via the usual "squash and merge" strategy so that it'll result in a single commit on `master` branch (to keep git history clean and readable). That means all commits within will be squashed into one. There are multiple authors here, but it'll use the author of the first commit (Kevin) as author, and whoever merges the PR as the committer.

I'm not saying we don't need to ensure the CLAs are taken care of in the individual commits (I'm not a lawyer, but I take it it's safer to make sure that's the case)—just pointing out that we won't see all the individual authors in the final `master` branch; they'll be visible in this PR only.
gmlewis: Ah, that is an excellent point, @shurcooL and since @e-beach has been a contributor in the past with a signed CLA, I think we can go ahead and squash and merge this PR and ignore the nit that I pointed out.
If you could go ahead and perform the squash and merge at your convenience, it would be greatly appreciated.
shurcooL: SGTM.

Patch:
diff --git a/github/issues.go b/github/issues.go
index b437d506..cec6f030 100644
--- a/github/issues.go
+++ b/github/issues.go
@@ -23,6 +23,7 @@ type IssuesService service
 // but not every issue is a pull request. Some endpoints, events, and webhooks
 // may also return pull requests via this struct. If PullRequestLinks is nil,
 // this is an issue, and if PullRequestLinks is not nil, this is a pull request.
+// The IsPullRequest helper method can be used to check that.
 type Issue struct {
 	ID               *int              `json:"id,omitempty"`
 	Number           *int              `json:"number,omitempty"`
@@ -55,6 +56,13 @@ func (i Issue) String() string {
 	return Stringify(i)
 }
 
+// IsPullRequest reports whether the issue is also a pull request. It uses the
+// method recommended by GitHub's API documentation, which is to check whether
+// PullRequestLinks is non-nil.
+func (i Issue) IsPullRequest() bool {
+	return i.PullRequestLinks != nil
+}
+
 // IssueRequest represents a request to create/edit an issue.
 // It is separate from Issue above because otherwise Labels
 // and Assignee fail to serialize to the correct JSON.
@@ -97,7 +105,7 @@ type IssueListOptions struct {
 }
 
 // PullRequestLinks object is added to the Issue object when it's an issue included
-// in the IssueCommentEvent webhook payload, if the webhooks is fired by a comment on a PR
+// in the IssueCommentEvent webhook payload, if the webhook is fired by a comment on a PR.
 type PullRequestLinks struct {
 	URL      *string `json:"url,omitempty"`
 	HTMLURL  *string `json:"html_url,omitempty"`


Test patch:
diff --git a/github/issues_test.go b/github/issues_test.go
index dadee755..da60740f 100644
--- a/github/issues_test.go
+++ b/github/issues_test.go
@@ -275,3 +275,14 @@ func TestIssuesService_Unlock(t *testing.T) {
 		t.Errorf("Issues.Unlock returned error: %v", err)
 	}
 }
+
+func TestIsPullRequest(t *testing.T) {
+	i := new(Issue)
+	if i.IsPullRequest() == true {
+		t.Errorf("expected i.IsPullRequest (%v) to return false, got true", i)
+	}
+	i.PullRequestLinks = &PullRequestLinks{URL: String("http://example.com")}
+	if i.IsPullRequest() == false {
+		t.Errorf("expected i.IsPullRequest (%v) to return true, got false", i)
+	}
+}