From 511bc5f4a8cb442d34f9eaecb7cb2372fa706965 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 12 Oct 2016 15:10:38 -0700 Subject: [PATCH] Add support for PullRequestReviewEvent webhook. Fixes #450. Closes #451. Change-Id: Iebdd2bd35a8ddd1346b2268e4e837d6145e990dc --- github/activity_events.go | 2 ++ github/event_types.go | 20 ++++++++++++++++++++ github/messages.go | 1 + github/messages_test.go | 4 ++++ github/pulls_reviews.go | 19 +++++++++++++++++++ 5 files changed, 46 insertions(+) create mode 100644 github/pulls_reviews.go diff --git a/github/activity_events.go b/github/activity_events.go index 0fd850e..1515ca0 100644 --- a/github/activity_events.go +++ b/github/activity_events.go @@ -69,6 +69,8 @@ func (e *Event) Payload() (payload interface{}) { payload = &PublicEvent{} case "PullRequestEvent": payload = &PullRequestEvent{} + case "PullRequestReviewEvent": + payload = &PullRequestReviewEvent{} case "PullRequestReviewCommentEvent": payload = &PullRequestReviewCommentEvent{} case "PushEvent": diff --git a/github/event_types.go b/github/event_types.go index 3abe1ef..6a09208 100644 --- a/github/event_types.go +++ b/github/event_types.go @@ -327,6 +327,26 @@ type PullRequestEvent struct { Sender *User `json:"sender,omitempty"` } +// PullRequestReviewEvent is triggered when a review is submitted on a pull +// request. +// The Webhook event name is "pull_request_review". +// +// GitHub docs: https://developer.github.com/v3/activity/events/types/#pullrequestreviewevent +type PullRequestReviewEvent struct { + // Action is always "submitted". + Action *string `json:"action,omitempty"` + Review *PullRequestReview `json:"review,omitempty"` + PullRequest *PullRequest `json:"pull_request,omitempty"` + + // The following fields are only populated by Webhook events. + Repo *Repository `json:"repository,omitempty"` + Sender *User `json:"sender,omitempty"` + + // The following field is only present when the webhook is triggered on + // a repository belonging to an organization. + Organization *Organization `json:"organization,omitempty"` +} + // PullRequestReviewCommentEvent is triggered when a comment is created on a // portion of the unified diff of a pull request. // The Webhook event name is "pull_request_review_comment". diff --git a/github/messages.go b/github/messages.go index 810e9fd..82c27d2 100644 --- a/github/messages.go +++ b/github/messages.go @@ -55,6 +55,7 @@ var ( "milestone": "MilestoneEvent", "page_build": "PageBuildEvent", "public": "PublicEvent", + "pull_request_review": "PullRequestReviewEvent", "pull_request_review_comment": "PullRequestReviewCommentEvent", "pull_request": "PullRequestEvent", "push": "PushEvent", diff --git a/github/messages_test.go b/github/messages_test.go index 327adf5..a9af4ef 100644 --- a/github/messages_test.go +++ b/github/messages_test.go @@ -152,6 +152,10 @@ func TestParseWebHook(t *testing.T) { payload: &PullRequestEvent{}, messageType: "pull_request", }, + { + payload: &PullRequestReviewEvent{}, + messageType: "pull_request_review", + }, { payload: &PullRequestReviewCommentEvent{}, messageType: "pull_request_review_comment", diff --git a/github/pulls_reviews.go b/github/pulls_reviews.go new file mode 100644 index 0000000..ae3cdd4 --- /dev/null +++ b/github/pulls_reviews.go @@ -0,0 +1,19 @@ +// Copyright 2016 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import "time" + +// PullRequestReview represents a review of a pull request. +type PullRequestReview struct { + ID *int `json:"id,omitempty"` + User *User `json:"user,omitempty"` + Body *string `json:"body,omitempty"` + SubmittedAt *time.Time `json:"submitted_at,omitempty"` + + // State can be "approved", "rejected", or "commented". + State *string `json:"state,omitempty"` +}